umeng_pusher 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +19 -5
- data/README.md +4 -0
- data/lib/umeng_pusher.rb +33 -1
- data/lib/umeng_pusher/client.rb +64 -0
- data/lib/umeng_pusher/configuration.rb +15 -0
- data/lib/umeng_pusher/params.rb +101 -0
- data/lib/umeng_pusher/sign.rb +9 -0
- data/lib/umeng_pusher/version.rb +1 -1
- data/umeng_pusher.gemspec +1 -0
- metadata +19 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d504e87d15e0e9a32f5678876512397073360be05b265b34d0c227ae7d032bf7
|
4
|
+
data.tar.gz: 16c4258738ae9a6a96011162cedfd6c4788da1bfffeeee02331a2f15827824ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 534f123e33720a399d8cb528f7b99ebf30b89e11fc153195b25d8e0effd4679ee84ef54dfff013fefb4318740c1daba4f18f74f54dd4f8ad0d9d83ee77614aea
|
7
|
+
data.tar.gz: ef9ee8046b08b26909fae512b7329ebe5c1523669c6f09c7c6b441a1b8f8c8dcc67f00a213eeadab2c55fa1ce01487d641b4b342d79fc63ce3d8bfd21046151d
|
data/Gemfile.lock
CHANGED
@@ -1,19 +1,30 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
umeng_pusher (0.1.
|
4
|
+
umeng_pusher (0.1.1)
|
5
|
+
activesupport
|
5
6
|
httpx
|
6
7
|
|
7
8
|
GEM
|
8
9
|
remote: https://rubygems.org/
|
9
10
|
specs:
|
11
|
+
activesupport (6.1.3.2)
|
12
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
13
|
+
i18n (>= 1.6, < 2)
|
14
|
+
minitest (>= 5.1)
|
15
|
+
tzinfo (~> 2.0)
|
16
|
+
zeitwerk (~> 2.3)
|
10
17
|
coderay (1.1.3)
|
18
|
+
concurrent-ruby (1.1.9)
|
11
19
|
diff-lcs (1.4.4)
|
12
|
-
http-2-next (0.3
|
13
|
-
httpx (0.
|
14
|
-
http-2-next (>= 0.1
|
20
|
+
http-2-next (0.4.3)
|
21
|
+
httpx (0.15.0)
|
22
|
+
http-2-next (>= 0.4.1)
|
15
23
|
timers
|
24
|
+
i18n (1.8.10)
|
25
|
+
concurrent-ruby (~> 1.0)
|
16
26
|
method_source (1.0.0)
|
27
|
+
minitest (5.14.4)
|
17
28
|
pry (0.14.1)
|
18
29
|
coderay (~> 1.1)
|
19
30
|
method_source (~> 1.0)
|
@@ -31,7 +42,10 @@ GEM
|
|
31
42
|
diff-lcs (>= 1.2.0, < 2.0)
|
32
43
|
rspec-support (~> 3.10.0)
|
33
44
|
rspec-support (3.10.2)
|
34
|
-
timers (4.3.
|
45
|
+
timers (4.3.3)
|
46
|
+
tzinfo (2.0.4)
|
47
|
+
concurrent-ruby (~> 1.0)
|
48
|
+
zeitwerk (2.4.2)
|
35
49
|
|
36
50
|
PLATFORMS
|
37
51
|
ruby
|
data/README.md
CHANGED
data/lib/umeng_pusher.rb
CHANGED
@@ -1,5 +1,37 @@
|
|
1
1
|
require "umeng_pusher/version"
|
2
|
+
require "umeng_pusher/configuration"
|
3
|
+
require "umeng_pusher/sign"
|
4
|
+
require "umeng_pusher/client"
|
5
|
+
require "umeng_pusher/params"
|
2
6
|
|
3
7
|
module UmengPusher
|
4
8
|
class Error < StandardError; end
|
5
|
-
|
9
|
+
|
10
|
+
def self.configuration
|
11
|
+
@configuration ||= Configuration.new
|
12
|
+
end
|
13
|
+
|
14
|
+
class << self
|
15
|
+
attr_writer :configuration
|
16
|
+
|
17
|
+
def configuration
|
18
|
+
@configuration ||= Configuration.new
|
19
|
+
end
|
20
|
+
|
21
|
+
def configure
|
22
|
+
yield(configuration)
|
23
|
+
end
|
24
|
+
|
25
|
+
def appkey(platform)
|
26
|
+
platform.downcase == 'ios' ? configuration.ios_appkey : configuration.android_appkey
|
27
|
+
end
|
28
|
+
|
29
|
+
def app_master_secret(platform)
|
30
|
+
platform.downcase == 'ios' ? configuration.ios_app_master_secret : configuration.android_app_master_secret
|
31
|
+
end
|
32
|
+
|
33
|
+
def production_mode
|
34
|
+
configuration.production_mode
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require "httpx"
|
2
|
+
require "json"
|
3
|
+
require "active_support"
|
4
|
+
|
5
|
+
module UmengPusher
|
6
|
+
class Client
|
7
|
+
attr_reader :payload, :ret, :task_id, :error_code, :file_id, :platform, :content
|
8
|
+
CAST_TYPE = %w|unicast listcast filecast broadcast groupcast customizedcast|
|
9
|
+
SEND_URL = "http://msg.umeng.com/api/send"
|
10
|
+
STATUS_URL = "http://msg.umeng.com/api/status"
|
11
|
+
CANCEL_URL = "http://msg.umeng.com/api/cancel"
|
12
|
+
UPLOAD_URL = "http://msg.umeng.com/upload"
|
13
|
+
|
14
|
+
def initialize(platform, options, debug_mode = true)
|
15
|
+
@platform = platform
|
16
|
+
@options = options
|
17
|
+
@debug_mode = debug_mode
|
18
|
+
end
|
19
|
+
|
20
|
+
# unicast-单播
|
21
|
+
# listcast-列播,要求不超过500个device_token
|
22
|
+
# broadcast-广播
|
23
|
+
# filecast-文件播,多个device_token可通过文件形式批量发送
|
24
|
+
# groupcast-组播,按照filter筛选用户群,请参照filter参数
|
25
|
+
# customizedcast,通过alias进行推送,包括以下两种case:
|
26
|
+
# -alias:对单个或者多个alias进行推送
|
27
|
+
# -file_id:将alias存放到文件后,根据file_id来推送
|
28
|
+
def send
|
29
|
+
post(SEND_URL, Params.send_params(@platform, @options))
|
30
|
+
end
|
31
|
+
|
32
|
+
def status
|
33
|
+
post(STATUS_URL, Params.status_params(@platform, @options[:task_id]))
|
34
|
+
end
|
35
|
+
|
36
|
+
def cancel
|
37
|
+
post(CANCEL_URL, Params.cancel_params(@platform, @options[:task_id]))
|
38
|
+
end
|
39
|
+
|
40
|
+
def upload
|
41
|
+
post(UPLOAD_URL, Params.upload_params(@platform, @options))
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def post(url, payload)
|
47
|
+
sign = Sign.generate @platform, url, payload
|
48
|
+
|
49
|
+
puts payload.to_json if @debug_mode
|
50
|
+
|
51
|
+
resp = HTTPX.post("#{url}?sign=#{sign}", json: payload)
|
52
|
+
|
53
|
+
if resp.status == 200
|
54
|
+
r = JSON.parse(resp.body)
|
55
|
+
{ message: r["ret"], error_code: r["data"]["error_code"] || 0, data: r["data"] }
|
56
|
+
elsif resp.status == 400
|
57
|
+
r = JSON.parse(resp.body)
|
58
|
+
{ message: r["data"]["error_msg"], error_code: r["data"]["error_code"], data: r["data"] }
|
59
|
+
else
|
60
|
+
{ message: "系统错误", error_code: "999", data: {} }
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module UmengPusher
|
2
|
+
class Configuration
|
3
|
+
attr_accessor :ios_appkey, :ios_app_master_secret,
|
4
|
+
:android_appkey, :android_app_master_secret,
|
5
|
+
:production_mode
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@ios_appkey = ""
|
9
|
+
@ios_app_master_secret = ""
|
10
|
+
@android_appkey = ""
|
11
|
+
@android_app_master_secret = ""
|
12
|
+
@production_mode = "false"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
require "securerandom"
|
2
|
+
|
3
|
+
module UmengPusher
|
4
|
+
module Params
|
5
|
+
extend self
|
6
|
+
|
7
|
+
def send_params(platform, options)
|
8
|
+
|
9
|
+
params = {
|
10
|
+
"appkey" => UmengPusher.appkey(platform),
|
11
|
+
"timestamp" => Time.now.to_i.to_s,
|
12
|
+
"type" => options[:type],
|
13
|
+
"device_tokens" => options[:device_tokens],
|
14
|
+
"alias_type" => options[:alias_type], # 当type=customizedcast时,必填
|
15
|
+
"alias" => options[:alias], #当type=customizedcast时,选填(此参数和file_id二选一)
|
16
|
+
"file_id" => options[:file_id], # 当type=filecast时,必填
|
17
|
+
"policy" => { # 可选,定时任务策略
|
18
|
+
"start_time" => options[:start_time],
|
19
|
+
"expire_time" => options[:expire_time],
|
20
|
+
"max_send_num" => options[:max_send_num],
|
21
|
+
"out_biz_no" => options[:out_biz_no], # 强烈建议开发者在发送任务类消息时填写这个字段,友盟服务端会根据这个字段对消息做去重避免重复发送、根据业务推送内容填写,out_biz_no只对任务类消息有效
|
22
|
+
},
|
23
|
+
"production_mode" => UmengPusher.production_mode,
|
24
|
+
"description" => options[:description], # 可选,发送消息描述,建议填写
|
25
|
+
}
|
26
|
+
|
27
|
+
ios_payload = {
|
28
|
+
"payload" => {
|
29
|
+
"aps" => {
|
30
|
+
"alert" => options[:alert],
|
31
|
+
"badge" => options[:badge] || 1,
|
32
|
+
"sound" => options[:sound] || "default",
|
33
|
+
"content-available" => options["content-available".to_sym],
|
34
|
+
"category" => options[:category],
|
35
|
+
},
|
36
|
+
},
|
37
|
+
}
|
38
|
+
|
39
|
+
# body为业务自定义字段
|
40
|
+
ios_payload["payload"]["body"] = options[:extra] if options.has_key?(:extra)
|
41
|
+
|
42
|
+
android_payload = {
|
43
|
+
"payload" => {
|
44
|
+
"display_type" => options[:display_type],
|
45
|
+
"body" => {
|
46
|
+
"ticker" => options[:ticker],
|
47
|
+
"title" => options[:title],
|
48
|
+
"text" => options[:text],
|
49
|
+
"icon" => options[:icon],
|
50
|
+
"largeIcon" => options[:largeIcon],
|
51
|
+
"img" => options[:img],
|
52
|
+
"sound" => options[:sound],
|
53
|
+
"builder_id" => (options[:builder_id] || 0),
|
54
|
+
"play_vibrate" => (options[:play_vibrate] || "true"),
|
55
|
+
"play_lights" => (options[:play_lights] || "true"),
|
56
|
+
"play_sound" => (options[:play_sound] || "true"),
|
57
|
+
"after_open" => (options[:after_open] || "go_app"),
|
58
|
+
"url" => options[:url],
|
59
|
+
"activity" => options[:activity],
|
60
|
+
"custom" => options[:custom],
|
61
|
+
},
|
62
|
+
"extra" => options[:extra] || {},
|
63
|
+
},
|
64
|
+
}
|
65
|
+
|
66
|
+
platform.downcase == "ios" ? params.merge!(ios_payload) : params.merge!(android_payload)
|
67
|
+
compact_params(params)
|
68
|
+
end
|
69
|
+
|
70
|
+
def status_params(platform, task_id)
|
71
|
+
{
|
72
|
+
"appkey" => UmengPusher.appkey(platform),
|
73
|
+
"timestamp" => Time.now.to_i.to_s,
|
74
|
+
"task_id" => task_id,
|
75
|
+
}
|
76
|
+
end
|
77
|
+
|
78
|
+
def cancel_params(platform, task_id)
|
79
|
+
{
|
80
|
+
"appkey" => UmengPusher.appkey(platform),
|
81
|
+
"timestamp" => Time.now.to_i.to_s,
|
82
|
+
"task_id" => task_id,
|
83
|
+
}
|
84
|
+
end
|
85
|
+
|
86
|
+
def upload_params(platform, content)
|
87
|
+
{
|
88
|
+
"appkey" => UmengPusher.appkey(platform),
|
89
|
+
"timestamp" => Time.now.to_i.to_s,
|
90
|
+
"content" => content,
|
91
|
+
}
|
92
|
+
end
|
93
|
+
|
94
|
+
private
|
95
|
+
|
96
|
+
def compact_params(params)
|
97
|
+
custom_compact = Proc.new { |k, v| v.delete_if(&custom_compact) if v.kind_of?(Hash); v.blank? }
|
98
|
+
params.delete_if &custom_compact
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
data/lib/umeng_pusher/version.rb
CHANGED
data/umeng_pusher.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: umeng_pusher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- 42up
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: bundler
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -98,6 +112,10 @@ files:
|
|
98
112
|
- bin/console
|
99
113
|
- bin/setup
|
100
114
|
- lib/umeng_pusher.rb
|
115
|
+
- lib/umeng_pusher/client.rb
|
116
|
+
- lib/umeng_pusher/configuration.rb
|
117
|
+
- lib/umeng_pusher/params.rb
|
118
|
+
- lib/umeng_pusher/sign.rb
|
101
119
|
- lib/umeng_pusher/version.rb
|
102
120
|
- umeng_pusher.gemspec
|
103
121
|
homepage: https://github.com/42up/umeng_pusher
|