jpush 4.0.1 → 4.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0bae15213acb2d3c9dfd3d3babf1c99ace6034c8
4
- data.tar.gz: bfdab4624e1cee4ae30433fd1c0f5da239fbf88c
3
+ metadata.gz: 79b65314d47e814e62cfea7b886b27462c7c1c13
4
+ data.tar.gz: 1ee47cccb05ec9292d3a6a7227138ba79f1830bc
5
5
  SHA512:
6
- metadata.gz: 7cc2de05de5a4e864039a3761be554396a91673948994ebd353fed6177e2096213d827e944f0ba93eaa0be96fd46f4defd610054a24301dee81e9f387cd20ea6
7
- data.tar.gz: b5d30caaab0b375caa58ed2b26f1b23b63607158cbdb05340570f6656dce921b69f09ededbaff762884fcebe54e0c8730cbe50e97a48db8f72166d8fa7dff3f6
6
+ metadata.gz: b60e7c2e12ff8b4279a24525f100d0834c8bd432498def27ba62be29f8bee086301cbbb2703c4a8aa41697e23e0b6256cc26b7a5846c5d4e230b439227f0cea2
7
+ data.tar.gz: e6a7007ad096d5f0db66a166ceec379496c5c13d67d0b126893221d4ab667411c58692ac77ddc400b856605111f209f9c4578a98e4a6c3ff95b688a90e110e7b
data/README.md CHANGED
@@ -3,26 +3,31 @@
3
3
  # JPush API Ruby Client
4
4
 
5
5
  [![Build Status](https://travis-ci.org/jpush/jpush-api-ruby-client.svg?branch=master)](https://travis-ci.org/jpush/jpush-api-ruby-client)
6
+ [![Gem Version](https://badge.fury.io/rb/jpush.svg)](https://badge.fury.io/rb/jpush)
6
7
 
7
8
  这是 JPush REST API 的 Ruby 版本封装开发包,是由极光推送官方提供的,一般支持最新的 API 功能。
8
- 对应的 REST API 文档: http://docs.jpush.io/server/server_overview/,
9
- 支持 Ruby 版本 >= 2.2.0
9
+
10
+ 对应的 REST API 文档: http://docs.jpush.io/server/server_overview/
11
+
12
+ > 支持的 Ruby 版本:>= 2.2
10
13
 
11
14
  ## Installation
12
15
 
13
16
  Add this line to your application's Gemfile:
14
17
 
15
18
  ```ruby
19
+ gem 'jpush'
20
+ # OR
16
21
  gem 'jpush', git: 'https://github.com/jpush/jpush-api-ruby-client.git'
17
22
  ```
18
23
 
19
24
  ## Usage
20
25
 
21
- - [Getting Started](docs/README.md#getting-started)
22
- - [Device API](docs/README.md#device-api)
23
- - [Push API](docs/README.md#push-api)
24
- - [Report API](docs/README.md#report-api)
25
- - [Schedule API](docs/README.md#schedule-api)
26
+ - [Getting Started](docs/Guides.md#getting-started)
27
+ - [Push API](docs/Guides.md#push-api)
28
+ - [Report API](docs/Guides.md#report-api)
29
+ - [Schedule API](docs/Guides.md#schedule-api)
30
+ - [Device API](docs/Guides.md#device-api)
26
31
 
27
32
  ## Development
28
33
 
@@ -0,0 +1,508 @@
1
+ # 目录
2
+
3
+ - [Getting Started](#getting-started)
4
+ - [Push API](#push-api)
5
+ - [构建 Audience 对象](#构建-audience-对象)
6
+ - [构建 Notification 对象](#构建-notification-对象)
7
+ - [构建 PushPayload 对象](#构建-pushpayload-对象)
8
+ - [推送消息](#推送消息)
9
+ - [Report API](#report-api)
10
+ - [送达统计](#送达统计)
11
+ - [消息统计(VIP专属接口)](#消息统计vip专属接口)
12
+ - [用户统计(VIP专属接口)](#用户统计vip专属接口)
13
+ - [Schedule API](#schedule-api)
14
+ - [构建 Trigger 对象](#构建-trigger-对象)
15
+ - [构建 SchedulePayload 对象](#构建-schedulepayload-对象)
16
+ - [创建定时任务](#创建定时任务)
17
+ - [获取有效的定时任务列表](#获取有效的定时任务列表)
18
+ - [获取定时任务详情](#获取定时任务详情)
19
+ - [更新定时任务](#更新定时任务)
20
+ - [删除定时任务](#删除定时任务)
21
+ - [Device API](#device-api)
22
+ - [查询设备](#查询设备-设备的别名与标签)
23
+ - [更新设备](#更新设备-设备的别名与标签)
24
+ - [获取用户在线状态(VIP专属接口)](#获取用户在线状态vip专属接口)
25
+ - [查询标签列表](#查询标签列表)
26
+ - [判断设备与标签的绑定](#判断设备与标签的绑定)
27
+ - [更新标签](#更新标签-与设备的绑定的关系)
28
+ - [删除标签](#删除标签-与设备的绑定关系)
29
+ - [查询别名](#查询别名-与设备的绑定关系)
30
+ - [删除别名](#删除别名-与设备的绑定关系)
31
+
32
+ ## Getting Started
33
+
34
+ [Where to get app_key or master_secret?](https://www.jpush.cn/common/apps/new)
35
+
36
+ ```ruby
37
+ app_key = 'xxx'
38
+ master_secret = 'xxx'
39
+ jpush = JPush::Client.new(app_key, master_secret)
40
+ ```
41
+
42
+ ## Push API
43
+
44
+ ```ruby
45
+ pusher = jpush.pusher
46
+
47
+ # simplest push Hello to all
48
+ push_payload = JPush::Push::PushPayload.new(
49
+ platform: 'all',
50
+ audience: 'all',
51
+ notification: 'hello jpush',
52
+ message: 'hello world'
53
+ )
54
+ pusher.push(push_payload)
55
+ ```
56
+
57
+ #### 构建 Audience 对象
58
+
59
+ 推送设备对象,表示一条推送可以被推送到哪些设备列表。
60
+ 如果要发广播(全部设备),不需要构建 Audience 对象,在新建 PushPayload 对象的时候,给 'audience' 参数直接传递字符串 'all' 即可。
61
+ 广播外的设备选择方式,有4种类型: tag, tag_and, alias, registration_id, **4种类型至少需要有其一, 这几种类型并存时多项的隐含关系是 AND,即取交集**
62
+
63
+ ```ruby
64
+ audience = JPush::Push::Audience.new
65
+ audience.set_tag(tag)
66
+ audience.set_tag_and(tag_and)
67
+ audience.set_alias(alis)
68
+ audience.set_registration_id(registration_ids)
69
+
70
+ # 链式调用
71
+ audience = JPush::Push::Audience.new.
72
+ set_tag(tag).
73
+ set_tag_and(tag_and).
74
+ set_alias(alis).
75
+ set_registration_id(registration_ids)
76
+ ```
77
+
78
+ 参数说明
79
+
80
+ | 参数 | 是否必须 | 说明 |
81
+ | --- | :---: | --- |
82
+ | tag | 否 | 有效的标签字符串或者一个最多包含20个有效的标签字符串的数组 |
83
+ | tag_and | 否 | 有效的标签字符串或者一个最多包含20个有效的标签字符串的数组 |
84
+ | alis | 否 | 有效的别名字符串或者一个最多包含1000个有效的别名字符串的数组 |
85
+ | registration_ids | 否 | 有效的 registration id 字符串或者一个最多包含1000个有效的 registration id 字符串的数组 |
86
+
87
+ #### 构建 Notification 对象
88
+
89
+ 若通知的内容在各个平台上,都只有 'alert' 这一个最基本的属性,
90
+ 则不需要构建 Notifacation 对象,在新建 PushPayload 对象的时候,给 'notication' 参数直接传递表示 alert 的字符串即可,
91
+ 也可以在 Notifacation 对象中设置 alert 属性。
92
+ 其下属属性包含3种,2个平台属性,以及一个 'alert' 属性。
93
+
94
+ ```ruby
95
+ notification = JPush::Push::Notification.new
96
+ ```
97
+
98
+ ###### alert
99
+
100
+ ```ruby
101
+ notification.set_alert(alert)
102
+ ```
103
+
104
+ ###### android
105
+
106
+ ```ruby
107
+ notification.set_android(
108
+ alert: alert,
109
+ title: title,
110
+ builder_id: builder_id,
111
+ extras: extras
112
+ )
113
+ ```
114
+
115
+ 参数说明
116
+
117
+ | 参数 | 是否必须 | 说明 |
118
+ | --- | :---: | --- |
119
+ | alert | 是 | 表示通知内容,会覆盖上级统一指定的 alert 信息;内容可以为空字符串,表示不展示到通知栏 |
120
+ | title | 否 | 表示通知标题,会替换通知里原来展示 App 名称的地方 |
121
+ | builder_id | 否 | 表示通知栏样式ID,Android SDK 可设置通知栏样式,这里根据样式 ID 来指定该使用哪套样式 |
122
+ | extras | 否 | 表示扩展字段,接受一个 Hash 对象,以供业务使用 |
123
+
124
+ ###### ios
125
+
126
+ ```ruby
127
+ notification.set_ios(
128
+ alert: alert,
129
+ sound: sound,
130
+ badge: badge,
131
+ available: available,
132
+ category: category,
133
+ extras: extras
134
+ )
135
+ ```
136
+
137
+ 参数说明
138
+
139
+ | 参数 | 是否必须 | 说明 |
140
+ | --- | :---: | --- |
141
+ | alert | 是 | 表示通知内容,会覆盖上级统一指定的 alert 信息;内容可以为空字符串,表示不展示到通知栏 |
142
+ | sound | 否 | 表示通知提示声音 |
143
+ | bandge | 否 | 表示应用角标,把角标数字改为指定的数字;为 0 表示清除 |
144
+ | available | 否 | 表示推送唤醒,仅接受 true 表示为 Background Remote Notification,若不填默认是 nil 表示普通的 Remote Notification |
145
+ | category | 否 | IOS8才支持。设置 APNs payload 中的 'category' 字段值 |
146
+ | extras | 否 | 表示扩展字段,接受一个 Hash 对象,以供业务使用 |
147
+
148
+ ###### 链式调用
149
+
150
+ ```ruby
151
+ notification = JPush::Push::Notification.new.
152
+ set_alert(alert).
153
+ set_android(
154
+ alert: alert,
155
+ title: title,
156
+ builder_id: builder_id,
157
+ extras: extras
158
+ ).set_ios(
159
+ alert: alert,
160
+ sound: sound,
161
+ badge: badge,
162
+ available: available,
163
+ category: category,
164
+ extras: extras
165
+ )
166
+ ```
167
+
168
+ #### 构建 PushPayload 对象
169
+
170
+ 一个推送对象,表示一条推送相关的所有信息,通知内容体。是被推送到客户端的内容。
171
+ **notification 和 message 二者必须有其一,可以二者并存。**
172
+ **如果目标平台有 iOS 平台 需要在 options 中通过 apns_production 字段来制定推送环境。True 表示推送生产环境,False 表示要推送开发环境; 如果不指定则为推送生产环境。**
173
+
174
+ ```ruby
175
+ # audience 和 notification 对象可按照上面的例子实例化
176
+ audience = JPush::Push::Andience.new.set_registration_id(registration_ids)
177
+ notification = JPush::Push::Notification.new.set_alert(alert)
178
+ ```
179
+
180
+ ```ruby
181
+ # 初始化 PushPayload 对象
182
+ push_payload = JPush::Push::PushPayload.new(
183
+ platform: platform,
184
+ audience: audience,
185
+ notification: notification,
186
+ message: message
187
+ )
188
+ ```
189
+
190
+ 参数说明
191
+
192
+ | 参数 | 是否必须 | 说明 |
193
+ | --- | :---: | --- |
194
+ | platform | 是 | 表示推送的平台,其可接受的参数为 'all'(表示推送到所有平台), 'android' 或 'ios' 或 ['android', 'ios'] |
195
+ | audience | 是 | 表示推送的设备,其可接受的参数为 'all' (表示发广播,推送到全部设备) 或者一个 Audience 对象 |
196
+ | notification | 否 | 接受一个字符串快速设置最基本的 'alert' 属性,或者一个 Notifcation 对象 |
197
+ | message | 否 | 表示应用内消息,仅接受一个字符串来快速设置消息内容本身,要构建复杂的 Message 对象,需使用 PushPayload 的实例方法 set_message |
198
+
199
+ ###### 添加应用内消息
200
+
201
+ ```ruby
202
+ push_payload = JPush::Push::PushPayload.new(
203
+ platform: platform,
204
+ audience: audience,
205
+ notification: notification,
206
+ ).set_message(
207
+ msg_content,
208
+ title: title,
209
+ content_type: content_type,
210
+ extras: extras
211
+ )
212
+ ```
213
+
214
+ 参数说明
215
+
216
+ | 参数 | 是否必须 | 说明 |
217
+ | --- | :---: | --- |
218
+ | msg_content | 是 | 消息内容本身 |
219
+ | title | 否 | 消息标题 |
220
+ | content_type | 否 | 消息内容类型 |
221
+ | extras | 否 | 表示扩展字段,接受一个 Hash 对象,以供业务使用 |
222
+
223
+ ###### 添加短信业务
224
+
225
+ ```ruby
226
+ push_payload = JPush::Push::PushPayload.new(
227
+ platform: platform,
228
+ audience: audience,
229
+ notification: notification
230
+ ).set_sms_message(content, delay_time)
231
+ ```
232
+
233
+ 参数说明
234
+
235
+ | 参数 | 是否必须 | 说明 |
236
+ | --- | :---: | --- |
237
+ | content | 是 | 表示短信内容,不能超过480个字符 |
238
+ | delay_time | 否 | 表示短信发送的延迟时间,单位为秒,不能超过24小时。仅对android平台有效。默认为 0,表示立即发送短信 |
239
+
240
+ ###### 推送可选项
241
+
242
+ ```ruby
243
+ options = {
244
+ sendno: no,
245
+ time_to_live: time,
246
+ override_msg_id: msg_id,
247
+ apns_production: true,
248
+ big_push_duration: duration
249
+ }
250
+
251
+ # 参数 options 仅接受一个 Hash 对象,而这个 Hash 对象的键也仅支持上面所示的5种。
252
+ push_payload = JPush::Push::PushPayload.new(
253
+ platform: platform,
254
+ audience: audience,
255
+ notification: notification,
256
+ message: message
257
+ ).set_options(options)
258
+ ```
259
+
260
+ 参数说明
261
+
262
+ | 可选项 | 说明 |
263
+ | --- | --- |
264
+ | sendno | 表示推送序号,纯粹用来作为 API 调用标识,API 返回时被原样返回,以方便 API 调用方匹配请求与返回 |
265
+ | time_to_live | 表示离线消息保留时长(秒),推送当前用户不在线时,为该用户保留多长时间的离线消息,以便其上线时再次推送。默认 86400 (1 天),最长 10 天。设置为 0 表示不保留离线消息,只有推送当前在线的用户可以收到 |
266
+ | override_msg_id | 表示要覆盖的消息ID |
267
+ | apns_production | 表示APNs是否生产环境,True 表示推送生产环境,False 表示要推送开发环境;如果不指定则为推送生产环境 |
268
+ | big_push_duration | 表示定速推送时长(分钟),又名缓慢推送,把原本尽可能快的推送速度,降低下来,给定的n分钟内,均匀地向这次推送的目标用户推送。最大值为1400.未设置则不是定速推送 |
269
+
270
+ ###### 链式调用
271
+
272
+ ```ruby
273
+ push_payload = JPush::Push::PushPayload.new(
274
+ platform: platform,
275
+ audience: audience,
276
+ notification: notification
277
+ ).set_message(
278
+ msg_content,
279
+ title: title,
280
+ content_type: content_type,
281
+ extras: extras
282
+ ).set_sms_message(content, delay_time).
283
+ set_options(options)
284
+ ```
285
+
286
+ #### 推送消息
287
+
288
+ ```ruby
289
+ # 仅接受一个 PushPayload 对象参数
290
+ pusher.push(push_payload)
291
+ ```
292
+
293
+ ## Report API
294
+
295
+ ```ruby
296
+ reporter = jpush.reporter
297
+ ```
298
+
299
+ #### 送达统计
300
+
301
+ ```ruby
302
+ # 参数 msg_ids 为一个表示有效的 msg_id 字符串或者一个最多包含100个有效的 msg_id 字符串的数组
303
+ reporter.received(msg_ids)
304
+ ```
305
+
306
+ #### 消息统计(VIP专属接口)
307
+
308
+ ```ruby
309
+ # 与送达统计 API 不同的是,该 API 提供更多的的统计数据
310
+ # 参数 msg_ids 为一个表示有效的 msg_id 字符串或者一个最多包含100个有效的 msg_id 字符串的数组
311
+ reporter.messages(msg_ids)
312
+ ```
313
+
314
+ #### 用户统计(VIP专属接口)
315
+
316
+ ```ruby
317
+ # 提供近2个月内某时间段的用户相关统计数据:新增用户、在线用户、活跃用户
318
+ reporter.users(time_unit, start, duration)
319
+ ```
320
+
321
+ 参数说明
322
+
323
+ | 参数 | 是否必须 | 说明 |
324
+ | --- | :---: | --- |
325
+ | time_unit | 是 | 表示时间单位,支持:HOUR(小时)、DAY(天)、MONTH(月) (不区分大小写) |
326
+ | start | 是 | 接受一个 Time 类的实例,表示统计的起始时间,会根据参数 time_unit 自动的转换成需要的格式。若 time_unit 为 'MONTH' 其格式为yyyy-mm,若 time_unit 为 'DAY' 其格式为 yyyy-mm-dd,若 time_unit 为 'MONTH',其格式为 yyyy-mm-dd hh,也就是说,会自动根据 time_unit 的不同将 Time 类的实例中用不到的部分去掉 |
327
+ | duration | 是 | 表示统计持续的时长,根据参数 time_unit 的不同有不同的取值范围,若 time_unit 为 'MONTH' 其范围为1至2,若 time_unit 为 'DAY' 其范围为1至60,若 time_unit 为 'HOUR',其范围为1至24,并且只支持输出当天的统计结果,若 duration 超过限定的最大取值,则取最大值。 |
328
+
329
+ ## Schedule API
330
+
331
+ ```ruby
332
+ schedules = jpush.schedules
333
+ ```
334
+
335
+ #### 构建 Trigger 对象
336
+
337
+ 表示 schedule 任务的触发条件,当前只支持定时任务(single)或定期任务(periodical)
338
+
339
+ ###### 定时任务(single)
340
+
341
+ ```ruby
342
+ # 参数 time 接受一个 Time 类的实例
343
+ single = JPush::Schedule::Trigger.new.set_single(time)
344
+ ```
345
+
346
+ ###### 定期任务(periodical)
347
+
348
+ ```ruby
349
+ periodical = JPush::Schedule::Trigger.new.set_periodical(start_time, end_time, time, time_unit, frequency, point)
350
+ ```
351
+
352
+ 参数说明
353
+
354
+ | 参数 | 是否必须 | 说明 |
355
+ | --- | :---: | --- |
356
+ | start_time | 是 | 表示定期任务有效起始时间,接受一个 Time 类的实例 |
357
+ | end_time | 是 | 表示定期任务有效过期时间,接受一个 Time 类的实例 |
358
+ | time | 是 | 表示触发定期任务的定期执行时间, 其接受一个表示24小时制时间(时分秒)的字符串,例如:'12:07' |
359
+ | time_unit | 是 | 表示定期任务的执行的最小时间单位 可选 'day','week' 或 'month' |
360
+ | frequency | 是 | 与 time_unit 的乘积共同表示的定期任务的执行周期 |
361
+ | point | 是 | 接受一个数组,此项与 time_unit 相对应:当 time_unit 为 day 时 point 此项无效;当 time_unit 为 week 时,point 为数组 ['MON','TUE','WED','THU','FRI','SAT','SUN'] 的子数组,表示星期几进行触发;当 time_unit 为 month 时,point 为当前进行月对应的日期, 为数组 ['01', '02' , .., '31'] 的子数组 |
362
+
363
+ #### 构建 SchedulePayload 对象
364
+
365
+ ```ruby
366
+ # 参数 trigger 接受一个 Trigger 对象,或者一个 Time 对象快速设置 single 定时任务
367
+ # 参数 push_payload 仅接受一个有效的 PushPayload 对象
368
+ JPush::Schedule::SchedulePayload.new(name, trigger, push_payload)
369
+ ```
370
+
371
+ #### 创建定时任务
372
+
373
+ ```ruby
374
+ # 参数 schedule_payload 仅接受一个有效的 SchedulePayload 对象
375
+ schedules.create(schedule_payload)
376
+ ```
377
+
378
+ #### 获取有效的定时任务列表
379
+
380
+ ```ruby
381
+ # 返回当前请求页的详细的 schedule-task 列表,如未指定page则page为1
382
+ schedules.tasks(page)
383
+ ```
384
+
385
+ #### 获取定时任务详情
386
+
387
+ ```ruby
388
+ schedules.show(schedule_id)
389
+ ```
390
+
391
+ #### 更新定时任务
392
+
393
+ **更新操作必须为 'name','enabled','trigger' 或 'push' 四项中的一项或多项**
394
+
395
+ **定时任务(single)与定期任务(periodical)之间不能进行相互更新,即,原先为single类任务,则不能更新为periodical任务,反之亦然**
396
+
397
+ **不能更新已过期的schedule任务**
398
+
399
+ ```ruby
400
+ schedules.update(schedule_id, name: name, enabled: enabled, trigger: trigger, push: push_payload)
401
+ # 例如只更新 name
402
+ schedules.update(schedule_id, name: 'jpush')
403
+ ```
404
+
405
+ 参数说明
406
+
407
+ | 参数 | 是否必须 | 说明 |
408
+ | --- | :---: | --- |
409
+ | schedule_id | 是 | 表示要更新的定时任务的 id |
410
+ | name | 否 | 表示定时任务的名字 |
411
+ | enabled | 否 | 表示任务当前状态,布尔值,必须为 true 或 false |
412
+ | trigger | 否 | 接受一个 Trigger 对象,或者一个 Time 对象快速设置 single 定时任务 |
413
+ | push_payload | 否 | 仅接受一个有效的 PushPayload 对象 |
414
+
415
+ #### 删除定时任务
416
+
417
+ ```ruby
418
+ schedules.delete(schedule_id)
419
+ ```
420
+
421
+ ## Device API
422
+
423
+ Device API 用于在服务器端查询、设置、更新、删除设备的 tag,alias 信息,使用时需要注意不要让服务端设置的标签又被客户端给覆盖了
424
+
425
+ ```ruby
426
+ devices = jpush.devices
427
+ tags = jpush.tags
428
+ aliases = jpush.aliases
429
+ ```
430
+
431
+ #### 查询设备 (设备的别名与标签)
432
+
433
+ ```ruby
434
+ # 获取当前设备的所有属性,包含标签 tags, 别名 alias, 手机号码 mobile
435
+ devices.show(registration_id)
436
+ ```
437
+
438
+ #### 更新设备 (设备的别名与标签)
439
+
440
+ ```ruby
441
+ # 为设备添加/移除标签
442
+ # 参数 tags 为一个表示有效的 tag 字符串或者一个最多包含100个有效的 tag 字符串的数组
443
+ devices.add_tags(registration_id, tags)
444
+ devices.remove_tags(registration_id, tags)
445
+
446
+ # 清除设备所有标签
447
+ devices.clear_tags(registration_id)
448
+
449
+ # 更新设备的别名
450
+ devices.update_alias(registration_id, alis)
451
+
452
+ # 删除设备的别名
453
+ devices.delete_alias(registration_id)
454
+
455
+ # 更新设备的手机号码
456
+ devices.update_mobile(registration_id)
457
+ ```
458
+
459
+ #### 获取用户在线状态(VIP专属接口)
460
+
461
+ ```ruby
462
+ # 参数 registration_ids 为一个表示有效的 registration_id 字符串或者一个最多包含1000个有效的 registration_id 字符串的数组
463
+ device.status(registration_ids)
464
+ ```
465
+
466
+ #### 查询标签列表
467
+
468
+ ```ruby
469
+ # 获取应用的所有标签列表
470
+ tags.list
471
+ ```
472
+
473
+ #### 判断设备与标签的绑定
474
+
475
+ ```ruby
476
+ # 查询某个设备是否在标签下
477
+ tags.has_device?(tag_value, registration_id)
478
+ ```
479
+
480
+ #### 更新标签 (与设备的绑定的关系)
481
+
482
+ ```ruby
483
+ # 为一个标签添加/移除设备
484
+ # 参数 registration_ids 为一个表示有效的 registration_id 字符串或者一个最多包含1000个有效的 registration_id 字符串的数组
485
+ tags.add_devices(tag_value, registration_ids)
486
+ tags.remove_devices(tag_value, registration_ids)
487
+ ```
488
+
489
+ #### 删除标签 (与设备的绑定关系)
490
+
491
+ ```ruby
492
+ # 删除一个标签,以及标签与设备之间的关联关系, platform 不填默认为所有平台
493
+ tags.delete(tag_value, platform)
494
+ ```
495
+
496
+ #### 查询别名 (与设备的绑定关系)
497
+
498
+ ```ruby
499
+ # 获取指定别名下的设备,最多输出10个, platform 不填默认为所有平台
500
+ aliases.show(alias_value, platform)
501
+ ```
502
+
503
+ #### 删除别名 (与设备的绑定关系)
504
+
505
+ ```ruby
506
+ # 删除一个别名,以及该别名与设备的绑定关系, platform 不填默认为所有平台
507
+ aliases.delete(alias_value, platform)
508
+ ```
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["support@jpush.cn"]
11
11
 
12
12
  spec.summary = %q{JPush's officially supported Ruby client library for accessing JPush APIs.}
13
- spec.description = %q{JPush's officially supported Ruby client library for accessing JPush APIs. 极光推送官方支持的 Ruby 版本服务器端 SDK. http://docs.jpush.io/server/server_overview/}
13
+ spec.description = %q{JPush's officially supported Ruby client library for accessing JPush APIs. 极光推送官方支持的 Ruby 版本服务器端 SDK. 相应的 API 文档:http://docs.jpush.io/server/server_overview/ }
14
14
  spec.homepage = "https://github.com/jpush/jpush-api-ruby-client"
15
15
  spec.license = "MIT"
16
16
 
@@ -26,7 +26,7 @@ module JPush
26
26
  self
27
27
  end
28
28
 
29
- def build
29
+ def to_hash
30
30
  @audience = {
31
31
  tag: @tag,
32
32
  tag_and: @tag_and,
@@ -34,10 +34,6 @@ module JPush
34
34
  registration_id: @registration_id
35
35
  }.compact
36
36
  raise Utils::Exceptions::JPushError, 'Audience can not be empty.' if @audience.empty?
37
- self
38
- end
39
-
40
- def to_hash
41
37
  @audience
42
38
  end
43
39
 
@@ -48,17 +48,13 @@ module JPush
48
48
  self
49
49
  end
50
50
 
51
- def build
51
+ def to_hash
52
52
  @notification = {
53
53
  alert: @alert,
54
54
  android: @android,
55
55
  ios: @ios
56
56
  }.compact
57
57
  raise Utils::Exceptions::JPushError, 'Notification can not be empty.' if @notification.empty?
58
- self
59
- end
60
-
61
- def to_hash
62
58
  @notification
63
59
  end
64
60
 
@@ -8,8 +8,6 @@ module JPush
8
8
  extend Helper::ArgumentHelper
9
9
  using Utils::Helper::ObjectExtensions
10
10
 
11
- attr_reader :platform, :audience, :notification, :message, :sms_message, :options
12
-
13
11
  VALID_OPTION_KEY = [:sendno, :time_to_live, :override_msg_id, :apns_production, :big_push_duration]
14
12
  MAX_SMS_CONTENT_SIZE = 480
15
13
  MAX_SMS_DELAY_TIME = 86400 # 24 * 60 * 60 (second)
@@ -36,7 +34,7 @@ module JPush
36
34
  self
37
35
  end
38
36
 
39
- def build
37
+ def to_hash
40
38
  raise Utils::Exceptions::MissingArgumentError.new(['audience']) unless @audience
41
39
  err_msg = 'missing notification or message'
42
40
  raise Utils::Exceptions::JPushError, err_msg unless @notification || @message
@@ -48,11 +46,6 @@ module JPush
48
46
  sms_message: @sms_message,
49
47
  options: @options
50
48
  }.compact
51
- self
52
- end
53
-
54
- def to_hash
55
- @push_payload
56
49
  end
57
50
 
58
51
  private
@@ -31,8 +31,8 @@ module JPush
31
31
  # 修改指定的Schedule
32
32
  # PUT https://api.jpush.cn/v3/schedules/{schedule_id}
33
33
  def update(schedule_id, name: nil, enabled: nil, trigger: nil, push: nil)
34
- hash = SchedulePayload.new(name, trigger, push, enabled).build_update.to_hash
35
- Http::Client.put(base_url + schedule_id, body: hash)
34
+ body = SchedulePayload.new(name, trigger, push, enabled).to_update_hash
35
+ Http::Client.put(base_url + schedule_id, body: body)
36
36
  end
37
37
 
38
38
  # 删除指定的Schedule任务
@@ -15,7 +15,7 @@ module JPush
15
15
  @enabled = enabled
16
16
  end
17
17
 
18
- def build_update
18
+ def to_update_hash
19
19
  @schedule_payload = {
20
20
  name: @name,
21
21
  enabled: @enabled,
@@ -23,10 +23,10 @@ module JPush
23
23
  push: @push_payload
24
24
  }.compact
25
25
  raise Utils::Exceptions::JPushError, 'Schedule update body can not be empty' if @schedule_payload.empty?
26
- self
26
+ @schedule_payload
27
27
  end
28
28
 
29
- def build
29
+ def to_hash
30
30
  @schedule_payload = {
31
31
  name: @name,
32
32
  enabled: true,
@@ -35,10 +35,6 @@ module JPush
35
35
  }
36
36
  hash = @schedule_payload.select { |_, value| value.nil? }
37
37
  raise Utils::Exceptions::MissingArgumentError.new(hash.keys) unless hash.empty?
38
- self
39
- end
40
-
41
- def to_hash
42
38
  @schedule_payload
43
39
  end
44
40
 
@@ -32,16 +32,12 @@ module JPush
32
32
  self
33
33
  end
34
34
 
35
- def build
35
+ def to_hash
36
36
  @trigger = {
37
37
  single: @single,
38
38
  periodical: @periodical
39
39
  }.compact
40
40
  raise Utils::Exceptions::JPushError, 'Trigger can not be empty.' if @trigger.empty?
41
- self
42
- end
43
-
44
- def to_hash
45
41
  @trigger
46
42
  end
47
43
 
@@ -1,3 +1,3 @@
1
1
  module JPush
2
- VERSION = "4.0.1"
2
+ VERSION = "4.0.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jpush
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.1
4
+ version: 4.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - JPush Offical
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-04-27 00:00:00.000000000 Z
11
+ date: 2016-04-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,8 +52,8 @@ dependencies:
52
52
  - - ~>
53
53
  - !ruby/object:Gem::Version
54
54
  version: '5.0'
55
- description: JPush's officially supported Ruby client library for accessing JPush
56
- APIs. 极光推送官方支持的 Ruby 版本服务器端 SDK. http://docs.jpush.io/server/server_overview/
55
+ description: 'JPush''s officially supported Ruby client library for accessing JPush
56
+ APIs. 极光推送官方支持的 Ruby 版本服务器端 SDK. 相应的 API 文档:http://docs.jpush.io/server/server_overview/ '
57
57
  email:
58
58
  - support@jpush.cn
59
59
  executables: []
@@ -68,7 +68,7 @@ files:
68
68
  - Rakefile
69
69
  - bin/console
70
70
  - bin/setup
71
- - docs/README.md
71
+ - docs/Guides.md
72
72
  - jpush.gemspec
73
73
  - lib/jpush.rb
74
74
  - lib/jpush/api.rb
@@ -1,347 +0,0 @@
1
- ## 目录
2
-
3
- - [Getting Started](#getting-started)
4
- - [Device API](#device-api)
5
- - [查询设备](#查询设备-设备的别名与标签)
6
- - [更新设备](#更新设备-设备的别名与标签)
7
- - [获取用户在线状态(VIP专属接口)](#获取用户在线状态vip专属接口)
8
- - [查询标签列表](#查询标签列表)
9
- - [判断设备与标签的绑定](#判断设备与标签的绑定)
10
- - [更新标签](#更新标签-与设备的绑定的关系)
11
- - [删除标签](#删除标签-与设备的绑定关系)
12
- - [查询别名](#查询别名-与设备的绑定关系)
13
- - [删除别名](#删除别名-与设备的绑定关系)
14
- - [Push API](#push-api)
15
- - [构建复杂的 Audience 对象](#构建复杂的-audience-对象)
16
- - [构建复杂的 Notification 对象](#构建复杂的-notification-对象)
17
- - [构建复杂 PushPayload 对象](#构建复杂-pushpayload-对象)
18
- - [推送消息](#推送消息)
19
- - [Report API](#report-api)
20
- - [送达统计](#送达统计)
21
- - [消息统计(VIP专属接口)](#消息统计vip专属接口)
22
- - [用户统计(VIP专属接口)](#用户统计vip专属接口)
23
- - [Schedule API](#schedule-api)
24
- - [构建 Trigger 对象](#构建-trigger-对象)
25
- - [构建 SchedulePayload 对象](#构建-schedulepayload-对象)
26
- - [创建定时任务](#创建定时任务)
27
- - [获取有效的定时任务列表](#获取有效的定时任务列表)
28
- - [获取定时任务详情](#获取定时任务详情)
29
- - [更新定时任务](#更新定时任务)
30
- - [删除定时任务](#删除定时任务)
31
-
32
- #### Getting Started
33
-
34
- [Where to get app_key or master_secret?](https://www.jpush.cn/common/apps/new)
35
-
36
- ```ruby
37
- app_key = 'xxx'
38
- master_secret = 'xxx'
39
- jpush = JPush::Client.new(app_key, master_secret)
40
- ```
41
-
42
- #### Device API
43
-
44
- ```ruby
45
- devices = jpush.devices
46
- tags = jpush.tags
47
- aliases = jpush.aliases
48
- ```
49
-
50
- ###### 查询设备 (设备的别名与标签)
51
-
52
- ```ruby
53
- # 获取当前设备的所有属性,包含标签 tags, 别名 alias, 手机号码 mobile
54
- devices.show(registration_id)
55
- ```
56
-
57
- ###### 更新设备 (设备的别名与标签)
58
-
59
- ```ruby
60
- # 为设备添加/移除标签
61
- # 参数 tags 为一个表示有效的 tag 字符串或者一个最多包含100个有效的 tag 字符串的数组
62
- devices.add_tags(registration_id, tags)
63
- devices.remove_tags(registration_id, tags)
64
-
65
- # 清除设备所有标签
66
- devices.clear_tags(registration_id)
67
-
68
- # 更新设备的别名
69
- devices.update_alias(registration_id, alis)
70
-
71
- # 删除设备的别名
72
- devices.delete_alias(registration_id)
73
-
74
- # 更新设备的手机号码
75
- devices.update_mobile(registration_id)
76
- ```
77
-
78
- ###### 获取用户在线状态(VIP专属接口)
79
-
80
- ```ruby
81
- # 参数 registration_ids 为一个表示有效的 registration_id 字符串或者一个最多包含1000个有效的 registration_id 字符串的数组
82
- device.status(registration_ids)
83
- ```
84
-
85
- ###### 查询标签列表
86
-
87
- ```ruby
88
- # 获取应用的所有标签列表
89
- tags.list
90
- ```
91
-
92
- ###### 判断设备与标签的绑定
93
-
94
- ```ruby
95
- # 查询某个设备是否在标签下
96
- tags.has_device?(tag_value, registration_id)
97
- ```
98
-
99
- ###### 更新标签 (与设备的绑定的关系)
100
-
101
- ```ruby
102
- # 为一个标签添加/移除设备
103
- # 参数 registration_ids 为一个表示有效的 registration_id 字符串或者一个最多包含1000个有效的 registration_id 字符串的数组
104
- tags.add_devices(tag_value, registration_ids)
105
- tags.remove_devices(tag_value, registration_ids)
106
- ```
107
-
108
- ###### 删除标签 (与设备的绑定关系)
109
-
110
- ```ruby
111
- # 删除一个标签,以及标签与设备之间的关联关系, platform 默认为所有平台
112
- tags.delete(tag_value, platform = nil)
113
- ```
114
-
115
- ###### 查询别名 (与设备的绑定关系)
116
-
117
- ```ruby
118
- # 获取指定别名下的设备,最多输出10个, platform 默认为所有平台
119
- aliases.show(alias_value, platform = nil)
120
- ```
121
-
122
- ###### 删除别名 (与设备的绑定关系)
123
-
124
- ```ruby
125
- # 删除一个别名,以及该别名与设备的绑定关系, platform 默认为所有平台
126
- aliases.delete(alias_value, platform = nil)
127
- ```
128
-
129
- #### Push API
130
-
131
- ```ruby
132
- pusher = jpush.pusher
133
-
134
- # simplest push Hello to all
135
- push_payload = JPush::Push::PushPayload.new(
136
- platform: 'all',
137
- audience: 'all',
138
- notification: 'hello jpush',
139
- message: 'hello world'
140
- ).build
141
- pusher.push(push_payload)
142
- ```
143
-
144
- ###### 构建复杂的 Audience 对象
145
-
146
- 推送设备对象,表示一条推送可以被推送到哪些设备列表。
147
- 如果要发广播(全部设备),不需要构建 Audience 对象,在新建 PushPayload 对象的时候,给 'audience' 直接传递 'all'即可。
148
- 广播外的设备选择方式,有4种类型: tag, tag_and, alias, registration_id
149
- 4 种类型至少需要有其一, 这几种类型并存时多项的隐含关系是 AND,即取交集。
150
-
151
- ```ruby
152
- # 参数 tag 和 tag_and 为一个有效的 tag 字符串或者一个最多包含20个有效的 tag 字符串的数组
153
- # 参数 alias 为一个表示有效的 alias 字符串或者一个最多包含1000个有效的 alias 字符串的数组
154
- # 参数registration_ids 为一个表示有效的 registration_id 字符串或者一个最多包含1000个有效的 registration_id 字符串的数组
155
- audience = JPush::Push::Audience.new
156
- audience.set_tag(tag)
157
- audience.set_tag_and(tag_and)
158
- audience.set_alias(alis)
159
- audience.set_registration_id(registration_ids)
160
- audience.build
161
-
162
- # OR
163
- audience = JPush::Push::Audience.new.
164
- set_tag(tag).
165
- set_tag_and(tag_and).
166
- set_alias(alis).
167
- set_registration_id(registration_ids).
168
- build
169
- ```
170
-
171
- ###### 构建复杂的 Notification 对象
172
-
173
- 若通知的内容在各个平台上,都只有 'alert' 这一个最基本的属性,
174
- 则不需要构建 Notifacation 对象,在新建 PushPayload 对象的时候,给 'notication' 直接传递 alert 字符串即可。
175
-
176
- ```ruby
177
- notification = JPush::Push::Notification.new
178
-
179
- notification.set_alert(alert)
180
- notification.set_not_alert # 不展示到通知栏
181
-
182
- # 参数 extra 为一个 Hash 对象,表示自定义扩展字段以供业务使用
183
- notification.set_android(alert: , title: nil, builder_id: nil, extras: nil)
184
- # 参数 available 表示推送唤醒,仅能接受 true 或者 nil
185
- notification.set_ios(alert: , sound: nil, badge: nil, available: nil, category: nil, extras: nil)
186
-
187
- notification.build
188
-
189
- # OR
190
- notification = JPush::Push::Notification.new.
191
- set_alert(alert).
192
- set_android(alert: , title: nil, builder_id: nil, extras: nil).
193
- set_ios(alert: , sound: nil, badge: nil, available: nil, category: nil, extras: nil).
194
- build
195
- ```
196
-
197
- ###### 构建复杂 PushPayload 对象
198
-
199
- 一个推送对象,表示一条推送相关的所有信息,通知内容体。是被推送到客户端的内容。
200
- notification 和 message 二者必须有其一,可以二者并存。
201
-
202
- ```ruby
203
- # audience 和 notification 对象可按照上面的例子实例化
204
- audience = JPush::Push::Andience.new
205
- notification = JPush::Push::Notification.new
206
-
207
- # 初始化 PushPayload 对象
208
- # 参数 platform 表示推送的平台,其可接受的参数为 'all'(表示推送到所有平台), 'android' 或 'ios'
209
- # 参数 audience 表示推送的设备,其可接受的参数为 'all' (表示发广播(推送到全部设备)) 或者一个 Audience 对象
210
- # 参数 notification 接受一个字符串(表示为仅设置最基本的属性 'alert') 或者一个 Notifcation 对象
211
- # 参数 message 仅接受一个字符串来快速设置消息内容本身
212
- push_payload = JPush::Push::PushPayload.new(
213
- platform: , audience: , notification: , message:
214
- )
215
-
216
- # 添加应用内消息
217
- # 参数 extra 为一个 Hash 对象,表示自定义扩展字段以供业务使用
218
- push_payload.set_message(msg_content, title: nil,content_type: nil, extras: nil)
219
-
220
- # 添加短信业务
221
- # 参数 content 表示短信内容,不能超过480个字符
222
- # 参数 delay_time 表示短信发送的延迟时间,单位为秒,不能超过24小时。
223
- # 该参数仅对android平台有效。默认为 0,表示立即发送短信
224
- push_payload.set_sms_message(content, delay_time = 0)
225
-
226
- push_payload.build
227
-
228
- # OR
229
- push_payload = JPush::Push::PushPayload.new(
230
- platform: , audience: , notification: ).
231
- set_message(msg_content, title: nil,content_type: nil, extras: nil).
232
- set_sms_message(content, delay_time).
233
- build
234
- ```
235
-
236
- ###### 推送消息
237
-
238
- ```ruby
239
- # 仅接受一个 PushPayload对象参数
240
- pusher.push(push_payload)
241
- ```
242
-
243
- #### Report API
244
-
245
- ```ruby
246
- reporter = jpush.reporter
247
- ```
248
-
249
- ###### 送达统计
250
-
251
- ```ruby
252
- # 参数 msg_ids 为一个表示有效的 msg_id 字符串或者一个最多包含100个有效的 msg_id 字符串的数组
253
- reporter.received(msg_ids)
254
- ```
255
-
256
- ###### 消息统计(VIP专属接口)
257
-
258
- ```ruby
259
- # 与送达统计 API 不同的是,该 API 提供更多的的统计数据
260
- # 参数 msg_ids 为一个表示有效的 msg_id 字符串或者一个最多包含100个有效的 msg_id 字符串的数组
261
- reporter.messages(msg_ids)
262
- ```
263
-
264
- ###### 用户统计(VIP专属接口)
265
-
266
- ```ruby
267
- # 提供近2个月内某时间段的用户相关统计数据:新增用户、在线用户、活跃用户
268
- # 参数 time_unit 表示时间单位,支持:HOUR(小时)、DAY(天)、MONTH(月) (不区分大小写)
269
- # 参数 start 接受一个 Time 类的实例,表示统计的起始时间,会根据参数 time_unit 自动的转换成需要的格式
270
- # 参数 duration 表示统计持续的时长,根据参数 time_unit 的不同有不同的取值范围,
271
- # 若 time_unit 为 'MONTH' 其范围为1至2,若 time_unit 为 'DAY' 其范围为1至60,
272
- # 若 time_unit 为 'HOUR',其范围为1至24,并且只支持输出当天的统计结果,
273
- # 若 duration 超过限定的最大取值,则取最大值。
274
- reporter.users(time_unit, start, duration)
275
- ```
276
-
277
- #### Schedule API
278
-
279
- ```ruby
280
- schedules = jpush.schedules
281
- ```
282
-
283
- ###### 构建 Trigger 对象
284
-
285
- 表示schedule任务的触发条件,当前只支持定时任务(single)或定期任务(periodical)
286
-
287
- ```ruby
288
- # 定时任务(single)
289
- # 参数 time 接受一个 Time 对象
290
- single = JPush::Schedule::Trigger.new.set_single(time)
291
-
292
- # 定期任务(periodical)
293
- # 参数 start_time 和 end_time 表示定期任务有效起始时间与过期时间,都接受一个 Time 对象
294
- # 参数 time 表示触发定期任务的定期执行时间, 其接受一个表示24小时制时间(时分秒)的字符串,例如:'12:07'
295
- # 参数 time_unit 表示定期任务的执行的最小时间单位 可选 'day','week' 或 'month'
296
- # 参数 frequency 与time_unit的乘积共同表示的定期任务的执行周期
297
- # 参数 point 接受一个数组,此项与time_unit相对应:
298
- # 当time_unit为day时point此项无效
299
- # 当time_unit为week时,point为数组 ['MON','TUE','WED','THU','FRI','SAT','SUN'] 的子数组,表示星期几进行触发
300
- # 当time_unit为month时,point为当前进行月对应的日期, 为数组['01', '02' , .., '31'] 的子数组
301
- periodical = JPush::Schedule::Trigger.new.set_periodical(start_time, end_time, time, time_unit, frequency, point)
302
- ```
303
-
304
- ###### 构建 SchedulePayload 对象
305
-
306
- ```ruby
307
- # 参数 triggle 接受一个 Trigger 对象,或者一个 Time 对象快速设置 single 定时任务
308
- # 参数 push 仅接受一个有效的 PushPayload 对象
309
- JPush::Schedule::SchedulePayload.new(name, trigger, push)
310
- ```
311
-
312
- ###### 创建定时任务
313
-
314
- ```ruby
315
- # 参数 schedule_payload 仅接受一个有效的 SchedulePayload 对象
316
- schedules.create(schedule_payload)
317
- ```
318
-
319
- ###### 获取有效的定时任务列表
320
-
321
- ```ruby
322
- # 返回当前请求页的详细的 schedule-task 列表,如未指定page则page为1
323
- schedules.tasks(page)
324
- ```
325
-
326
- ###### 获取定时任务详情
327
-
328
- ```ruby
329
- schedules.show(schedule_id)
330
- ```
331
-
332
- ###### 更新定时任务
333
-
334
- ```ruby
335
- # 更新操作必须为 'name','enabled','trigger' 或 'push' 四项中的一项或多项
336
- # 参数 triggle 接受一个 Trigger 对象,或者一个 Time 对象快速设置 single 定时任务
337
- # 参数 push 仅接受一个有效的 PushPayload 对象
338
- schedules.update(schedule_id, name: nil, enabled: nil, trigger: nil, push: nil)
339
- # 例如只更新 name
340
- schedules.update(schedule_id, name: 'jpush')
341
- ```
342
-
343
- ###### 删除定时任务
344
-
345
- ```ruby
346
- schedules.delete(schedule_id)
347
- ```