jpush 4.0.10 → 4.0.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +12 -12
- data/.travis.yml +7 -7
- data/Gemfile +4 -4
- data/LICENSE.txt +21 -21
- data/README.md +60 -60
- data/Rakefile +10 -10
- data/bin/console +14 -14
- data/bin/setup +8 -8
- data/docs/Guides.md +619 -619
- data/jpush.gemspec +35 -35
- data/lib/jpush.rb +8 -8
- data/lib/jpush/client.rb +43 -43
- data/lib/jpush/device.rb +163 -163
- data/lib/jpush/handler.rb +7 -7
- data/lib/jpush/http/client.rb +100 -100
- data/lib/jpush/http/response.rb +33 -33
- data/lib/jpush/push/audience.rb +55 -55
- data/lib/jpush/push/notification.rb +66 -66
- data/lib/jpush/push/push_payload.rb +77 -77
- data/lib/jpush/push/single_push_payload.rb +52 -52
- data/lib/jpush/pusher.rb +84 -84
- data/lib/jpush/report.rb +98 -98
- data/lib/jpush/schedule/schedule_payload.rb +48 -48
- data/lib/jpush/schedule/trigger.rb +53 -53
- data/lib/jpush/schedules.rb +53 -53
- data/lib/jpush/utils/exceptions.rb +34 -34
- data/lib/jpush/version.rb +3 -3
- metadata +2 -2
@@ -1,77 +1,77 @@
|
|
1
|
-
require 'jpush/push/audience'
|
2
|
-
require 'jpush/push/notification'
|
3
|
-
|
4
|
-
module JPush
|
5
|
-
module Push
|
6
|
-
class PushPayload
|
7
|
-
|
8
|
-
attr_reader :cid
|
9
|
-
|
10
|
-
def initialize(platform: , audience: , notification: nil, message: nil)
|
11
|
-
@platform = 'all' == platform ? 'all' : build_platform(platform)
|
12
|
-
@audience = 'all' == audience ? 'all' : build_audience(audience)
|
13
|
-
@notification = build_notification(notification) unless notification.nil?
|
14
|
-
@message = build_message(message) unless message.nil?
|
15
|
-
end
|
16
|
-
|
17
|
-
def set_message(msg_content, title: nil, content_type: nil, extras: nil)
|
18
|
-
@message = build_message(msg_content, title, content_type, extras)
|
19
|
-
self
|
20
|
-
end
|
21
|
-
|
22
|
-
def set_sms_message(sms_message)
|
23
|
-
@sms_message = sms_message
|
24
|
-
self
|
25
|
-
end
|
26
|
-
|
27
|
-
def set_options(options)
|
28
|
-
@options = options
|
29
|
-
self
|
30
|
-
end
|
31
|
-
|
32
|
-
def set_cid(cid)
|
33
|
-
@cid= cid
|
34
|
-
self
|
35
|
-
end
|
36
|
-
|
37
|
-
def to_hash
|
38
|
-
@push_payload = {
|
39
|
-
platform: @platform,
|
40
|
-
audience: @audience,
|
41
|
-
notification: @notification,
|
42
|
-
message: @message,
|
43
|
-
sms_message: @sms_message,
|
44
|
-
options: { apns_production: false }.merge(@options.nil? ? {} : @options),
|
45
|
-
cid: @cid
|
46
|
-
}.select { |_, value| !value.nil? }
|
47
|
-
end
|
48
|
-
|
49
|
-
private
|
50
|
-
|
51
|
-
def build_platform(platform)
|
52
|
-
return platform if platform.is_a? Array
|
53
|
-
return [platform]
|
54
|
-
end
|
55
|
-
|
56
|
-
def build_audience(audience)
|
57
|
-
audience.is_a?(Audience) ? audience.to_hash : nil
|
58
|
-
end
|
59
|
-
|
60
|
-
def build_notification(notification)
|
61
|
-
return {alert: notification} if notification.is_a?(String)
|
62
|
-
notification.is_a?(Notification) ? notification.to_hash : nil
|
63
|
-
end
|
64
|
-
|
65
|
-
def build_message(msg_content, title = nil, content_type = nil, extras = nil)
|
66
|
-
extras = (extras.nil? || !extras.is_a?(Hash) || extras.empty?) ? nil : extras
|
67
|
-
message = {
|
68
|
-
msg_content: msg_content,
|
69
|
-
title: title,
|
70
|
-
content_type: content_type,
|
71
|
-
extras: extras
|
72
|
-
}.select { |_, value| !value.nil? }
|
73
|
-
end
|
74
|
-
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
1
|
+
require 'jpush/push/audience'
|
2
|
+
require 'jpush/push/notification'
|
3
|
+
|
4
|
+
module JPush
|
5
|
+
module Push
|
6
|
+
class PushPayload
|
7
|
+
|
8
|
+
attr_reader :cid
|
9
|
+
|
10
|
+
def initialize(platform: , audience: , notification: nil, message: nil)
|
11
|
+
@platform = 'all' == platform ? 'all' : build_platform(platform)
|
12
|
+
@audience = 'all' == audience ? 'all' : build_audience(audience)
|
13
|
+
@notification = build_notification(notification) unless notification.nil?
|
14
|
+
@message = build_message(message) unless message.nil?
|
15
|
+
end
|
16
|
+
|
17
|
+
def set_message(msg_content, title: nil, content_type: nil, extras: nil)
|
18
|
+
@message = build_message(msg_content, title, content_type, extras)
|
19
|
+
self
|
20
|
+
end
|
21
|
+
|
22
|
+
def set_sms_message(sms_message)
|
23
|
+
@sms_message = sms_message
|
24
|
+
self
|
25
|
+
end
|
26
|
+
|
27
|
+
def set_options(options)
|
28
|
+
@options = options
|
29
|
+
self
|
30
|
+
end
|
31
|
+
|
32
|
+
def set_cid(cid)
|
33
|
+
@cid= cid
|
34
|
+
self
|
35
|
+
end
|
36
|
+
|
37
|
+
def to_hash
|
38
|
+
@push_payload = {
|
39
|
+
platform: @platform,
|
40
|
+
audience: @audience,
|
41
|
+
notification: @notification,
|
42
|
+
message: @message,
|
43
|
+
sms_message: @sms_message,
|
44
|
+
options: { apns_production: false }.merge(@options.nil? ? {} : @options),
|
45
|
+
cid: @cid
|
46
|
+
}.select { |_, value| !value.nil? }
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def build_platform(platform)
|
52
|
+
return platform if platform.is_a? Array
|
53
|
+
return [platform]
|
54
|
+
end
|
55
|
+
|
56
|
+
def build_audience(audience)
|
57
|
+
audience.is_a?(Audience) ? audience.to_hash : nil
|
58
|
+
end
|
59
|
+
|
60
|
+
def build_notification(notification)
|
61
|
+
return {alert: notification} if notification.is_a?(String)
|
62
|
+
notification.is_a?(Notification) ? notification.to_hash : nil
|
63
|
+
end
|
64
|
+
|
65
|
+
def build_message(msg_content, title = nil, content_type = nil, extras = nil)
|
66
|
+
extras = (extras.nil? || !extras.is_a?(Hash) || extras.empty?) ? nil : extras
|
67
|
+
message = {
|
68
|
+
msg_content: msg_content,
|
69
|
+
title: title,
|
70
|
+
content_type: content_type,
|
71
|
+
extras: extras
|
72
|
+
}.select { |_, value| !value.nil? }
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -1,52 +1,52 @@
|
|
1
|
-
require 'jpush/push/notification'
|
2
|
-
|
3
|
-
module JPush
|
4
|
-
module Push
|
5
|
-
class SinglePushPayload
|
6
|
-
|
7
|
-
def initialize(platform: , target: )
|
8
|
-
@platform = 'all' == platform ? 'all' : build_platform(platform)
|
9
|
-
@target = target
|
10
|
-
end
|
11
|
-
|
12
|
-
def set_notification(notification)
|
13
|
-
@notification = notification
|
14
|
-
self
|
15
|
-
end
|
16
|
-
|
17
|
-
def set_message(message)
|
18
|
-
@message = message
|
19
|
-
self
|
20
|
-
end
|
21
|
-
|
22
|
-
def set_sms_message(sms_message)
|
23
|
-
@sms_message = sms_message
|
24
|
-
self
|
25
|
-
end
|
26
|
-
|
27
|
-
def set_options(options)
|
28
|
-
@options = options
|
29
|
-
self
|
30
|
-
end
|
31
|
-
|
32
|
-
def to_hash
|
33
|
-
single_push_payload = {
|
34
|
-
platform: @platform,
|
35
|
-
target: @target,
|
36
|
-
notification: @notification,
|
37
|
-
message: @message,
|
38
|
-
sms_message: @sms_message,
|
39
|
-
options: @options
|
40
|
-
}.select { |_, value| !value.nil? }
|
41
|
-
end
|
42
|
-
|
43
|
-
private
|
44
|
-
|
45
|
-
def build_platform(platform)
|
46
|
-
return platform if platform.is_a? Array
|
47
|
-
return [platform]
|
48
|
-
end
|
49
|
-
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
1
|
+
require 'jpush/push/notification'
|
2
|
+
|
3
|
+
module JPush
|
4
|
+
module Push
|
5
|
+
class SinglePushPayload
|
6
|
+
|
7
|
+
def initialize(platform: , target: )
|
8
|
+
@platform = 'all' == platform ? 'all' : build_platform(platform)
|
9
|
+
@target = target
|
10
|
+
end
|
11
|
+
|
12
|
+
def set_notification(notification)
|
13
|
+
@notification = notification
|
14
|
+
self
|
15
|
+
end
|
16
|
+
|
17
|
+
def set_message(message)
|
18
|
+
@message = message
|
19
|
+
self
|
20
|
+
end
|
21
|
+
|
22
|
+
def set_sms_message(sms_message)
|
23
|
+
@sms_message = sms_message
|
24
|
+
self
|
25
|
+
end
|
26
|
+
|
27
|
+
def set_options(options)
|
28
|
+
@options = options
|
29
|
+
self
|
30
|
+
end
|
31
|
+
|
32
|
+
def to_hash
|
33
|
+
single_push_payload = {
|
34
|
+
platform: @platform,
|
35
|
+
target: @target,
|
36
|
+
notification: @notification,
|
37
|
+
message: @message,
|
38
|
+
sms_message: @sms_message,
|
39
|
+
options: @options
|
40
|
+
}.select { |_, value| !value.nil? }
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def build_platform(platform)
|
46
|
+
return platform if platform.is_a? Array
|
47
|
+
return [platform]
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/lib/jpush/pusher.rb
CHANGED
@@ -1,84 +1,84 @@
|
|
1
|
-
require 'jpush/http/client'
|
2
|
-
require 'jpush/push/push_payload'
|
3
|
-
require 'jpush/push/single_push_payload'
|
4
|
-
require 'jpush/handler'
|
5
|
-
|
6
|
-
module JPush
|
7
|
-
class Pusher < Handler
|
8
|
-
|
9
|
-
# POST https://api.jpush.cn/v3/push/validate
|
10
|
-
# 验证推送调用是否能够成功,与推送 API 的区别在于:不向用户发送任何消息
|
11
|
-
def validate(push_payload)
|
12
|
-
url = base_url + 'validate'
|
13
|
-
send_push(url, push_payload)
|
14
|
-
end
|
15
|
-
|
16
|
-
# POST https://api.jpush.cn/v3/push
|
17
|
-
# 向某单个设备或者某设备列表推送一条通知、或者消息
|
18
|
-
def push(push_payload)
|
19
|
-
if push_payload.cid.nil?
|
20
|
-
cid_response = get_cid(count=1, type='push')
|
21
|
-
cid = cid_response.body['cidlist'].at(0)
|
22
|
-
push_payload.set_cid(cid)
|
23
|
-
end
|
24
|
-
send_push(base_url, push_payload)
|
25
|
-
end
|
26
|
-
|
27
|
-
# GET https://api.jpush.cn/v3/push/cid[?count=n[&type=xx]]
|
28
|
-
# 获取cid:推送唯一标识符
|
29
|
-
# https://docs.jiguang.cn/jpush/server/push/rest_api_v3_push/#cid
|
30
|
-
def get_cid(count=nil, type=nil)
|
31
|
-
params = {
|
32
|
-
count: count,
|
33
|
-
type: type
|
34
|
-
}.select { |_, value| !value.nil? }
|
35
|
-
url = base_url + 'cid'
|
36
|
-
Http::Client.get(@jpush, url, params: params)
|
37
|
-
end
|
38
|
-
|
39
|
-
# POST https://api.jpush.cn/v3/push/batch/regid/single
|
40
|
-
# 针对RegID方式批量单推(VIP专属接口)
|
41
|
-
# https://docs.jiguang.cn/jpush/server/push/rest_api_v3_push/#vip
|
42
|
-
def push_batch_regid(single_push_payloads)
|
43
|
-
cid_response = get_cid(count=single_push_payloads.size, type='push')
|
44
|
-
cidlist = cid_response.body['cidlist']
|
45
|
-
body = {}
|
46
|
-
body['pushlist'] = {}
|
47
|
-
single_push_payloads.each { |payload|
|
48
|
-
cid = cidlist.pop
|
49
|
-
body['pushlist'][cid] = payload.to_hash
|
50
|
-
}
|
51
|
-
url = base_url + 'batch/regid/single'
|
52
|
-
Http::Client.post(@jpush, url, body: body)
|
53
|
-
end
|
54
|
-
|
55
|
-
# POST https://api.jpush.cn/v3/push/batch/alias/single
|
56
|
-
# 针对Alias方式批量单推(VIP专属接口)
|
57
|
-
# https://docs.jiguang.cn/jpush/server/push/rest_api_v3_push/#vip
|
58
|
-
def push_batch_alias(single_push_payloads)
|
59
|
-
cid_response = get_cid(count=single_push_payloads.size, type='push')
|
60
|
-
cidlist = cid_response.body['cidlist']
|
61
|
-
body = {}
|
62
|
-
body['pushlist'] = {}
|
63
|
-
single_push_payloads.each { |payload|
|
64
|
-
cid = cidlist.pop
|
65
|
-
body['pushlist'][cid] = payload.to_hash
|
66
|
-
}
|
67
|
-
url = base_url + 'batch/alias/single'
|
68
|
-
Http::Client.post(@jpush, url, body: body)
|
69
|
-
end
|
70
|
-
|
71
|
-
private
|
72
|
-
|
73
|
-
def send_push(url, push_payload)
|
74
|
-
push_payload = push_payload.is_a?(JPush::Push::PushPayload) ? push_payload : nil
|
75
|
-
body = push_payload.to_hash
|
76
|
-
Http::Client.post(@jpush, url, body: body)
|
77
|
-
end
|
78
|
-
|
79
|
-
def base_url
|
80
|
-
'https://api.jpush.cn/v3/push/'
|
81
|
-
end
|
82
|
-
|
83
|
-
end
|
84
|
-
end
|
1
|
+
require 'jpush/http/client'
|
2
|
+
require 'jpush/push/push_payload'
|
3
|
+
require 'jpush/push/single_push_payload'
|
4
|
+
require 'jpush/handler'
|
5
|
+
|
6
|
+
module JPush
|
7
|
+
class Pusher < Handler
|
8
|
+
|
9
|
+
# POST https://api.jpush.cn/v3/push/validate
|
10
|
+
# 验证推送调用是否能够成功,与推送 API 的区别在于:不向用户发送任何消息
|
11
|
+
def validate(push_payload)
|
12
|
+
url = base_url + 'validate'
|
13
|
+
send_push(url, push_payload)
|
14
|
+
end
|
15
|
+
|
16
|
+
# POST https://api.jpush.cn/v3/push
|
17
|
+
# 向某单个设备或者某设备列表推送一条通知、或者消息
|
18
|
+
def push(push_payload)
|
19
|
+
if push_payload.cid.nil?
|
20
|
+
cid_response = get_cid(count=1, type='push')
|
21
|
+
cid = cid_response.body['cidlist'].at(0)
|
22
|
+
push_payload.set_cid(cid)
|
23
|
+
end
|
24
|
+
send_push(base_url, push_payload)
|
25
|
+
end
|
26
|
+
|
27
|
+
# GET https://api.jpush.cn/v3/push/cid[?count=n[&type=xx]]
|
28
|
+
# 获取cid:推送唯一标识符
|
29
|
+
# https://docs.jiguang.cn/jpush/server/push/rest_api_v3_push/#cid
|
30
|
+
def get_cid(count=nil, type=nil)
|
31
|
+
params = {
|
32
|
+
count: count,
|
33
|
+
type: type
|
34
|
+
}.select { |_, value| !value.nil? }
|
35
|
+
url = base_url + 'cid'
|
36
|
+
Http::Client.get(@jpush, url, params: params)
|
37
|
+
end
|
38
|
+
|
39
|
+
# POST https://api.jpush.cn/v3/push/batch/regid/single
|
40
|
+
# 针对RegID方式批量单推(VIP专属接口)
|
41
|
+
# https://docs.jiguang.cn/jpush/server/push/rest_api_v3_push/#vip
|
42
|
+
def push_batch_regid(single_push_payloads)
|
43
|
+
cid_response = get_cid(count=single_push_payloads.size, type='push')
|
44
|
+
cidlist = cid_response.body['cidlist']
|
45
|
+
body = {}
|
46
|
+
body['pushlist'] = {}
|
47
|
+
single_push_payloads.each { |payload|
|
48
|
+
cid = cidlist.pop
|
49
|
+
body['pushlist'][cid] = payload.to_hash
|
50
|
+
}
|
51
|
+
url = base_url + 'batch/regid/single'
|
52
|
+
Http::Client.post(@jpush, url, body: body)
|
53
|
+
end
|
54
|
+
|
55
|
+
# POST https://api.jpush.cn/v3/push/batch/alias/single
|
56
|
+
# 针对Alias方式批量单推(VIP专属接口)
|
57
|
+
# https://docs.jiguang.cn/jpush/server/push/rest_api_v3_push/#vip
|
58
|
+
def push_batch_alias(single_push_payloads)
|
59
|
+
cid_response = get_cid(count=single_push_payloads.size, type='push')
|
60
|
+
cidlist = cid_response.body['cidlist']
|
61
|
+
body = {}
|
62
|
+
body['pushlist'] = {}
|
63
|
+
single_push_payloads.each { |payload|
|
64
|
+
cid = cidlist.pop
|
65
|
+
body['pushlist'][cid] = payload.to_hash
|
66
|
+
}
|
67
|
+
url = base_url + 'batch/alias/single'
|
68
|
+
Http::Client.post(@jpush, url, body: body)
|
69
|
+
end
|
70
|
+
|
71
|
+
private
|
72
|
+
|
73
|
+
def send_push(url, push_payload)
|
74
|
+
push_payload = push_payload.is_a?(JPush::Push::PushPayload) ? push_payload : nil
|
75
|
+
body = push_payload.to_hash
|
76
|
+
Http::Client.post(@jpush, url, body: body)
|
77
|
+
end
|
78
|
+
|
79
|
+
def base_url
|
80
|
+
'https://api.jpush.cn/v3/push/'
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
end
|
data/lib/jpush/report.rb
CHANGED
@@ -1,98 +1,98 @@
|
|
1
|
-
require 'jpush/http/client'
|
2
|
-
require 'jpush/handler'
|
3
|
-
|
4
|
-
module JPush
|
5
|
-
class Report < Handler
|
6
|
-
|
7
|
-
TIME_UNIT = ['HOUR', 'DAY', 'MONTH']
|
8
|
-
TIME_FORMAT = { hour: '%F %H', day: '%F', month: '%Y-%m' }
|
9
|
-
MAX_DURATION = { hour: 24, day: 60, month: 2 }
|
10
|
-
|
11
|
-
# GET /v3/received
|
12
|
-
# 送达统计
|
13
|
-
def received(msg_ids)
|
14
|
-
msg_ids = [msg_ids].flatten
|
15
|
-
url = base_url + '/received'
|
16
|
-
params = {
|
17
|
-
msg_ids: msg_ids.join(',')
|
18
|
-
}
|
19
|
-
Http::Client.get(@jpush, url, params: params)
|
20
|
-
end
|
21
|
-
|
22
|
-
# GET /v3/received/detail
|
23
|
-
# 送达统计
|
24
|
-
# https://docs.jiguang.cn/jpush/server/push/rest_api_v3_report/#_7
|
25
|
-
def received_detail(msg_ids)
|
26
|
-
msg_ids = [msg_ids].flatten
|
27
|
-
url = base_url + '/received/detail'
|
28
|
-
params = {
|
29
|
-
msg_ids: msg_ids.join(',')
|
30
|
-
}
|
31
|
-
Http::Client.get(@jpush, url, params: params)
|
32
|
-
end
|
33
|
-
|
34
|
-
# GET /v3/status/message
|
35
|
-
# 送达状态查询
|
36
|
-
# Status API 用于查询已推送的一条消息在一组设备上的送达状态。
|
37
|
-
# https://docs.jiguang.cn/jpush/server/push/rest_api_v3_report/#_11
|
38
|
-
def status_message(msg_id: , registration_ids: , date: nil)
|
39
|
-
registration_ids = [registration_ids].flatten
|
40
|
-
url = base_url + 'status/message'
|
41
|
-
body = {
|
42
|
-
msg_id: msg_id.to_i,
|
43
|
-
registration_ids: registration_ids,
|
44
|
-
date: date
|
45
|
-
}.select { |_, value| !value.nil? }
|
46
|
-
Http::Client.post(@jpush, url, body: body)
|
47
|
-
end
|
48
|
-
|
49
|
-
# GET /v3/messages
|
50
|
-
# 消息统计
|
51
|
-
def messages(msg_ids)
|
52
|
-
msg_ids = [msg_ids].flatten
|
53
|
-
url = base_url + '/messages'
|
54
|
-
params = {
|
55
|
-
msg_ids: msg_ids.join(',')
|
56
|
-
}
|
57
|
-
Http::Client.get(@jpush, url, params: params)
|
58
|
-
end
|
59
|
-
|
60
|
-
# GET /v3/messages/detail
|
61
|
-
# 消息统计详情(VIP 专属接口,新)
|
62
|
-
# https://docs.jiguang.cn/jpush/server/push/rest_api_v3_report/#vip_1
|
63
|
-
def messages_detail(msg_ids)
|
64
|
-
msg_ids = [msg_ids].flatten
|
65
|
-
url = base_url + '/messages/detail'
|
66
|
-
params = {
|
67
|
-
msg_ids: msg_ids.join(',')
|
68
|
-
}
|
69
|
-
Http::Client.get(@jpush, url, params: params)
|
70
|
-
end
|
71
|
-
|
72
|
-
# GET /v3/users
|
73
|
-
# 用户统计
|
74
|
-
def users(time_unit, start, duration)
|
75
|
-
start = start.strftime(TIME_FORMAT[time_unit.downcase.to_sym])
|
76
|
-
duration = build_duration(time_unit.downcase.to_sym, duration)
|
77
|
-
params = {
|
78
|
-
time_unit: time_unit.upcase,
|
79
|
-
start: start,
|
80
|
-
duration: duration
|
81
|
-
}
|
82
|
-
url = base_url + '/users'
|
83
|
-
Http::Client.get(@jpush, url, params: params)
|
84
|
-
end
|
85
|
-
|
86
|
-
private
|
87
|
-
|
88
|
-
def base_url
|
89
|
-
'https://report.jpush.cn/v3/'
|
90
|
-
end
|
91
|
-
|
92
|
-
def build_duration(time_unit, duration)
|
93
|
-
return 1 if duration < 0
|
94
|
-
duration > MAX_DURATION[time_unit] ? MAX_DURATION[time_unit] : duration
|
95
|
-
end
|
96
|
-
|
97
|
-
end
|
98
|
-
end
|
1
|
+
require 'jpush/http/client'
|
2
|
+
require 'jpush/handler'
|
3
|
+
|
4
|
+
module JPush
|
5
|
+
class Report < Handler
|
6
|
+
|
7
|
+
TIME_UNIT = ['HOUR', 'DAY', 'MONTH']
|
8
|
+
TIME_FORMAT = { hour: '%F %H', day: '%F', month: '%Y-%m' }
|
9
|
+
MAX_DURATION = { hour: 24, day: 60, month: 2 }
|
10
|
+
|
11
|
+
# GET /v3/received
|
12
|
+
# 送达统计
|
13
|
+
def received(msg_ids)
|
14
|
+
msg_ids = [msg_ids].flatten
|
15
|
+
url = base_url + '/received'
|
16
|
+
params = {
|
17
|
+
msg_ids: msg_ids.join(',')
|
18
|
+
}
|
19
|
+
Http::Client.get(@jpush, url, params: params)
|
20
|
+
end
|
21
|
+
|
22
|
+
# GET /v3/received/detail
|
23
|
+
# 送达统计
|
24
|
+
# https://docs.jiguang.cn/jpush/server/push/rest_api_v3_report/#_7
|
25
|
+
def received_detail(msg_ids)
|
26
|
+
msg_ids = [msg_ids].flatten
|
27
|
+
url = base_url + '/received/detail'
|
28
|
+
params = {
|
29
|
+
msg_ids: msg_ids.join(',')
|
30
|
+
}
|
31
|
+
Http::Client.get(@jpush, url, params: params)
|
32
|
+
end
|
33
|
+
|
34
|
+
# GET /v3/status/message
|
35
|
+
# 送达状态查询
|
36
|
+
# Status API 用于查询已推送的一条消息在一组设备上的送达状态。
|
37
|
+
# https://docs.jiguang.cn/jpush/server/push/rest_api_v3_report/#_11
|
38
|
+
def status_message(msg_id: , registration_ids: , date: nil)
|
39
|
+
registration_ids = [registration_ids].flatten
|
40
|
+
url = base_url + 'status/message'
|
41
|
+
body = {
|
42
|
+
msg_id: msg_id.to_i,
|
43
|
+
registration_ids: registration_ids,
|
44
|
+
date: date
|
45
|
+
}.select { |_, value| !value.nil? }
|
46
|
+
Http::Client.post(@jpush, url, body: body)
|
47
|
+
end
|
48
|
+
|
49
|
+
# GET /v3/messages
|
50
|
+
# 消息统计
|
51
|
+
def messages(msg_ids)
|
52
|
+
msg_ids = [msg_ids].flatten
|
53
|
+
url = base_url + '/messages'
|
54
|
+
params = {
|
55
|
+
msg_ids: msg_ids.join(',')
|
56
|
+
}
|
57
|
+
Http::Client.get(@jpush, url, params: params)
|
58
|
+
end
|
59
|
+
|
60
|
+
# GET /v3/messages/detail
|
61
|
+
# 消息统计详情(VIP 专属接口,新)
|
62
|
+
# https://docs.jiguang.cn/jpush/server/push/rest_api_v3_report/#vip_1
|
63
|
+
def messages_detail(msg_ids)
|
64
|
+
msg_ids = [msg_ids].flatten
|
65
|
+
url = base_url + '/messages/detail'
|
66
|
+
params = {
|
67
|
+
msg_ids: msg_ids.join(',')
|
68
|
+
}
|
69
|
+
Http::Client.get(@jpush, url, params: params)
|
70
|
+
end
|
71
|
+
|
72
|
+
# GET /v3/users
|
73
|
+
# 用户统计
|
74
|
+
def users(time_unit, start, duration)
|
75
|
+
start = start.strftime(TIME_FORMAT[time_unit.downcase.to_sym])
|
76
|
+
duration = build_duration(time_unit.downcase.to_sym, duration)
|
77
|
+
params = {
|
78
|
+
time_unit: time_unit.upcase,
|
79
|
+
start: start,
|
80
|
+
duration: duration
|
81
|
+
}
|
82
|
+
url = base_url + '/users'
|
83
|
+
Http::Client.get(@jpush, url, params: params)
|
84
|
+
end
|
85
|
+
|
86
|
+
private
|
87
|
+
|
88
|
+
def base_url
|
89
|
+
'https://report.jpush.cn/v3/'
|
90
|
+
end
|
91
|
+
|
92
|
+
def build_duration(time_unit, duration)
|
93
|
+
return 1 if duration < 0
|
94
|
+
duration > MAX_DURATION[time_unit] ? MAX_DURATION[time_unit] : duration
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
end
|