jpush 4.0.10 → 4.0.11

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,35 +1,35 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'jpush/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = "jpush"
8
- spec.version = JPush::VERSION
9
- spec.authors = ["JPush Offical"]
10
- spec.email = ["support@jpush.cn"]
11
-
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. 相应的 API 文档:http://docs.jpush.io/server/server_overview/ }
14
- spec.homepage = "https://github.com/jpush/jpush-api-ruby-client"
15
- spec.license = "MIT"
16
-
17
- # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
- # delete this section to allow pushing this gem to any host.
19
- if spec.respond_to?(:metadata)
20
- spec.metadata['allowed_push_host'] = "https://rubygems.org"
21
- else
22
- raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
- end
24
-
25
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
- spec.bindir = "exe"
27
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
- spec.require_paths = ["lib"]
29
-
30
- spec.add_development_dependency "bundler", "~> 1.11"
31
- spec.add_development_dependency "rake", "~> 10.0"
32
- spec.add_development_dependency "minitest", "~> 5.0"
33
-
34
- spec.required_ruby_version = '>= 2.2'
35
- end
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'jpush/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "jpush"
8
+ spec.version = JPush::VERSION
9
+ spec.authors = ["JPush Offical"]
10
+ spec.email = ["support@jpush.cn"]
11
+
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. 相应的 API 文档:http://docs.jpush.io/server/server_overview/ }
14
+ spec.homepage = "https://github.com/jpush/jpush-api-ruby-client"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency "bundler", "~> 1.11"
31
+ spec.add_development_dependency "rake", "~> 10.0"
32
+ spec.add_development_dependency "minitest", "~> 5.0"
33
+
34
+ spec.required_ruby_version = '>= 2.2'
35
+ end
@@ -1,8 +1,8 @@
1
- require "jpush/version"
2
-
3
- module JPush
4
- # Your code goes here...
5
-
6
- end
7
-
8
- require 'jpush/client'
1
+ require "jpush/version"
2
+
3
+ module JPush
4
+ # Your code goes here...
5
+
6
+ end
7
+
8
+ require 'jpush/client'
@@ -1,43 +1,43 @@
1
- require 'jpush/device'
2
- require 'jpush/pusher'
3
- require 'jpush/report'
4
- require 'jpush/schedules'
5
-
6
- module JPush
7
- class Client
8
-
9
- attr_reader :app_key
10
- attr_reader :master_secret
11
-
12
- def initialize(app_key, master_secret)
13
- @app_key = app_key
14
- @master_secret = master_secret
15
- end
16
-
17
- def devices
18
- @devices ||= Device.new(self)
19
- end
20
-
21
- def tags
22
- @tag ||= Tag.new(self)
23
- end
24
-
25
- def aliases
26
- @alias ||= Alias.new(self)
27
- end
28
-
29
- def pusher
30
- @push ||= Pusher.new(self)
31
- end
32
-
33
- def reporter
34
- @report ||= Report.new(self)
35
- end
36
-
37
- def schedules
38
- @schedule ||= Schedules.new(self)
39
- end
40
-
41
- end
42
-
43
- end
1
+ require 'jpush/device'
2
+ require 'jpush/pusher'
3
+ require 'jpush/report'
4
+ require 'jpush/schedules'
5
+
6
+ module JPush
7
+ class Client
8
+
9
+ attr_reader :app_key
10
+ attr_reader :master_secret
11
+
12
+ def initialize(app_key, master_secret)
13
+ @app_key = app_key
14
+ @master_secret = master_secret
15
+ end
16
+
17
+ def devices
18
+ @devices ||= Device.new(self)
19
+ end
20
+
21
+ def tags
22
+ @tag ||= Tag.new(self)
23
+ end
24
+
25
+ def aliases
26
+ @alias ||= Alias.new(self)
27
+ end
28
+
29
+ def pusher
30
+ @push ||= Pusher.new(self)
31
+ end
32
+
33
+ def reporter
34
+ @report ||= Report.new(self)
35
+ end
36
+
37
+ def schedules
38
+ @schedule ||= Schedules.new(self)
39
+ end
40
+
41
+ end
42
+
43
+ end
@@ -1,163 +1,163 @@
1
- require 'jpush/http/client'
2
- require 'jpush/handler'
3
-
4
- module JPush
5
- class Device < Handler
6
-
7
- # GET /v3/devices/{registration_id}
8
- # 获取当前设备的所有属性
9
- def show(registration_id)
10
- url = base_url + registration_id
11
- Http::Client.get(@jpush, url)
12
- end
13
-
14
- # POST /v3/devices/{registration_id}
15
- # 更新当前设备的指定属性,当前支持tags, alias,手机号码mobile
16
- def update(registration_id, tags_add: nil, tags_remove: nil, clear_tags: false, alis: nil, mobile: nil)
17
- tags =
18
- if clear_tags
19
- ''
20
- else
21
- hash = {}
22
- hash[:add] = [tags_add].flatten unless tags_add.nil?
23
- hash[:remove] = [tags_remove].flatten unless tags_remove.nil?
24
- hash.empty? ? nil : hash
25
- end
26
- body = {
27
- tags: tags,
28
- alias: alis,
29
- mobile: mobile
30
- }.select { |_, value| !value.nil? }
31
-
32
- url = base_url + registration_id
33
- Http::Client.post(@jpush, url, body: body)
34
- end
35
-
36
- # 下面两个方法接受一个参数,其类型为数组或字符串
37
- def add_tags(registration_id, tags)
38
- update(registration_id, tags_add: tags)
39
- end
40
-
41
- def remove_tags(registration_id, tags)
42
- update(registration_id, tags_remove: tags)
43
- end
44
-
45
- def clear_tags(registration_id)
46
- update(registration_id, clear_tags: true)
47
- end
48
-
49
- def update_alias(registration_id, alis)
50
- update(registration_id, alis: alis)
51
- end
52
-
53
- def delete_alias(registration_id)
54
- update(registration_id, alis: '')
55
- end
56
-
57
- def update_mobile(registration_id, mobile)
58
- update(registration_id, mobile: mobile)
59
- end
60
-
61
- # 获取用户在线状态
62
- # POST /v3/devices/status/
63
- def status(registration_ids)
64
- registration_ids = [registration_ids].flatten
65
- url = base_url + 'status'
66
- body = { registration_ids: registration_ids }
67
- Http::Client.post(@jpush, url, body: body)
68
- end
69
-
70
- private
71
-
72
- def base_url
73
- 'https://device.jpush.cn/v3/devices/'
74
- end
75
-
76
- end
77
-
78
-
79
- class Tag < Handler
80
-
81
- # GET /v3/tags/
82
- # 获取当前应用的所有标签列表。
83
- def list
84
- url = base_url
85
- Http::Client.get(@jpush, url)
86
- end
87
-
88
- # GET /v3/tags/{tag_value}/registration_ids/{registration_id}
89
- # 查询某个设备是否在 tag 下
90
- def has_device?(tag_value, registration_id)
91
- url = base_url + "#{tag_value}/registration_ids/#{registration_id}"
92
- Http::Client.get(@jpush, url)
93
- end
94
-
95
- # POST /v3/tags/{tag_value}
96
- # 为一个标签添加或者删除设备。
97
- def update(tag_value, devices_add: nil, devices_remove: nil)
98
- rids = {}
99
- rids[:add] = [devices_add].flatten unless devices_add.nil?
100
- rids[:remove] = [devices_remove].flatten unless devices_remove.nil?
101
-
102
- body = { registration_ids: rids }
103
- url = base_url + tag_value
104
- Http::Client.post(@jpush, url, body: body)
105
- end
106
-
107
- # 下面两个方法接受一个参数,其类型为数组或字符串
108
- def add_devices(tag_value, registration_ids)
109
- update(tag_value, devices_add: registration_ids)
110
- end
111
-
112
- def remove_devices(tag_value, registration_ids)
113
- update(tag_value, devices_remove: registration_ids)
114
- end
115
-
116
- # DELETE /v3/tags/{tag_value}
117
- # 删除一个标签,以及标签与设备之间的关联关系
118
- def delete(tag_value, platform = nil)
119
- params = platform.nil? ? nil : { platform: [platform].flatten.join(',') }
120
- url = base_url + tag_value
121
- Http::Client.delete(@jpush, url, params: params)
122
- end
123
-
124
- private
125
-
126
- def base_url
127
- 'https://device.jpush.cn/v3/tags/'
128
- end
129
-
130
- end
131
-
132
-
133
- class Alias < Handler
134
-
135
- # GET /v3/aliases/{alias_value}
136
- # 获取指定alias下的设备,最多输出10个
137
- def show(alias_value, platform = nil)
138
- params = platform.nil? ? nil : { platform: build_platform(platform) }
139
- url = base_url + alias_value
140
- Http::Client.get(@jpush, url, params: params)
141
- end
142
-
143
- # DELETE /v3/aliases/{alias_value}
144
- # 删除一个别名,以及该别名与设备的绑定关系
145
- def delete(alias_value, platform = nil)
146
- params = platform.nil? ? nil : { platform: build_platform(platform) }
147
- url = base_url + alias_value
148
- Http::Client.delete(@jpush, url, params: params)
149
- end
150
-
151
- private
152
-
153
- def base_url
154
- 'https://device.jpush.cn/v3/aliases/'
155
- end
156
-
157
- def build_platform(p)
158
- [p].flatten.join(',')
159
- end
160
-
161
- end
162
-
163
- end
1
+ require 'jpush/http/client'
2
+ require 'jpush/handler'
3
+
4
+ module JPush
5
+ class Device < Handler
6
+
7
+ # GET /v3/devices/{registration_id}
8
+ # 获取当前设备的所有属性
9
+ def show(registration_id)
10
+ url = base_url + registration_id
11
+ Http::Client.get(@jpush, url)
12
+ end
13
+
14
+ # POST /v3/devices/{registration_id}
15
+ # 更新当前设备的指定属性,当前支持tags, alias,手机号码mobile
16
+ def update(registration_id, tags_add: nil, tags_remove: nil, clear_tags: false, alis: nil, mobile: nil)
17
+ tags =
18
+ if clear_tags
19
+ ''
20
+ else
21
+ hash = {}
22
+ hash[:add] = [tags_add].flatten unless tags_add.nil?
23
+ hash[:remove] = [tags_remove].flatten unless tags_remove.nil?
24
+ hash.empty? ? nil : hash
25
+ end
26
+ body = {
27
+ tags: tags,
28
+ alias: alis,
29
+ mobile: mobile
30
+ }.select { |_, value| !value.nil? }
31
+
32
+ url = base_url + registration_id
33
+ Http::Client.post(@jpush, url, body: body)
34
+ end
35
+
36
+ # 下面两个方法接受一个参数,其类型为数组或字符串
37
+ def add_tags(registration_id, tags)
38
+ update(registration_id, tags_add: tags)
39
+ end
40
+
41
+ def remove_tags(registration_id, tags)
42
+ update(registration_id, tags_remove: tags)
43
+ end
44
+
45
+ def clear_tags(registration_id)
46
+ update(registration_id, clear_tags: true)
47
+ end
48
+
49
+ def update_alias(registration_id, alis)
50
+ update(registration_id, alis: alis)
51
+ end
52
+
53
+ def delete_alias(registration_id)
54
+ update(registration_id, alis: '')
55
+ end
56
+
57
+ def update_mobile(registration_id, mobile)
58
+ update(registration_id, mobile: mobile)
59
+ end
60
+
61
+ # 获取用户在线状态
62
+ # POST /v3/devices/status/
63
+ def status(registration_ids)
64
+ registration_ids = [registration_ids].flatten
65
+ url = base_url + 'status'
66
+ body = { registration_ids: registration_ids }
67
+ Http::Client.post(@jpush, url, body: body)
68
+ end
69
+
70
+ private
71
+
72
+ def base_url
73
+ 'https://device.jpush.cn/v3/devices/'
74
+ end
75
+
76
+ end
77
+
78
+
79
+ class Tag < Handler
80
+
81
+ # GET /v3/tags/
82
+ # 获取当前应用的所有标签列表。
83
+ def list
84
+ url = base_url
85
+ Http::Client.get(@jpush, url)
86
+ end
87
+
88
+ # GET /v3/tags/{tag_value}/registration_ids/{registration_id}
89
+ # 查询某个设备是否在 tag 下
90
+ def has_device?(tag_value, registration_id)
91
+ url = base_url + "#{tag_value}/registration_ids/#{registration_id}"
92
+ Http::Client.get(@jpush, url)
93
+ end
94
+
95
+ # POST /v3/tags/{tag_value}
96
+ # 为一个标签添加或者删除设备。
97
+ def update(tag_value, devices_add: nil, devices_remove: nil)
98
+ rids = {}
99
+ rids[:add] = [devices_add].flatten unless devices_add.nil?
100
+ rids[:remove] = [devices_remove].flatten unless devices_remove.nil?
101
+
102
+ body = { registration_ids: rids }
103
+ url = base_url + tag_value
104
+ Http::Client.post(@jpush, url, body: body)
105
+ end
106
+
107
+ # 下面两个方法接受一个参数,其类型为数组或字符串
108
+ def add_devices(tag_value, registration_ids)
109
+ update(tag_value, devices_add: registration_ids)
110
+ end
111
+
112
+ def remove_devices(tag_value, registration_ids)
113
+ update(tag_value, devices_remove: registration_ids)
114
+ end
115
+
116
+ # DELETE /v3/tags/{tag_value}
117
+ # 删除一个标签,以及标签与设备之间的关联关系
118
+ def delete(tag_value, platform = nil)
119
+ params = platform.nil? ? nil : { platform: [platform].flatten.join(',') }
120
+ url = base_url + tag_value
121
+ Http::Client.delete(@jpush, url, params: params)
122
+ end
123
+
124
+ private
125
+
126
+ def base_url
127
+ 'https://device.jpush.cn/v3/tags/'
128
+ end
129
+
130
+ end
131
+
132
+
133
+ class Alias < Handler
134
+
135
+ # GET /v3/aliases/{alias_value}
136
+ # 获取指定alias下的设备,最多输出10个
137
+ def show(alias_value, platform = nil)
138
+ params = platform.nil? ? nil : { platform: build_platform(platform) }
139
+ url = base_url + alias_value
140
+ Http::Client.get(@jpush, url, params: params)
141
+ end
142
+
143
+ # DELETE /v3/aliases/{alias_value}
144
+ # 删除一个别名,以及该别名与设备的绑定关系
145
+ def delete(alias_value, platform = nil)
146
+ params = platform.nil? ? nil : { platform: build_platform(platform) }
147
+ url = base_url + alias_value
148
+ Http::Client.delete(@jpush, url, params: params)
149
+ end
150
+
151
+ private
152
+
153
+ def base_url
154
+ 'https://device.jpush.cn/v3/aliases/'
155
+ end
156
+
157
+ def build_platform(p)
158
+ [p].flatten.join(',')
159
+ end
160
+
161
+ end
162
+
163
+ end