jpush 4.0.8 → 4.0.10
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 +5 -5
- data/.gitignore +12 -11
- data/.travis.yml +7 -7
- data/Gemfile +4 -4
- data/LICENSE.txt +21 -21
- data/README.md +60 -59
- data/Rakefile +10 -10
- data/bin/console +14 -14
- data/bin/setup +8 -8
- data/docs/Guides.md +619 -521
- data/jpush.gemspec +35 -35
- data/lib/jpush.rb +8 -9
- data/lib/jpush/client.rb +43 -0
- data/lib/jpush/device.rb +163 -165
- data/lib/jpush/handler.rb +8 -0
- data/lib/jpush/http/client.rb +100 -39
- data/lib/jpush/http/response.rb +33 -33
- data/lib/jpush/push/audience.rb +55 -43
- data/lib/jpush/push/notification.rb +66 -61
- data/lib/jpush/push/push_payload.rb +77 -77
- data/lib/jpush/push/single_push_payload.rb +52 -0
- data/lib/jpush/pusher.rb +84 -0
- data/lib/jpush/report.rb +98 -59
- data/lib/jpush/schedule/schedule_payload.rb +48 -48
- data/lib/jpush/schedule/trigger.rb +53 -53
- data/lib/jpush/{schedule.rb → schedules.rb} +53 -49
- data/lib/jpush/utils/exceptions.rb +34 -34
- data/lib/jpush/version.rb +3 -3
- metadata +8 -8
- data/lib/jpush/api.rb +0 -42
- data/lib/jpush/config.rb +0 -20
- data/lib/jpush/push.rb +0 -34
- data/lib/jpush/utils/http.rb +0 -78
@@ -1,49 +1,53 @@
|
|
1
|
-
require 'jpush/schedule/schedule_payload'
|
2
|
-
require 'jpush/http/client'
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
1
|
+
require 'jpush/schedule/schedule_payload'
|
2
|
+
require 'jpush/http/client'
|
3
|
+
require 'jpush/handler'
|
4
|
+
|
5
|
+
module JPush
|
6
|
+
|
7
|
+
class Schedules < Handler
|
8
|
+
|
9
|
+
def initialize(jpush)
|
10
|
+
@jpush = jpush;
|
11
|
+
end
|
12
|
+
|
13
|
+
# POST https://api.jpush.cn/v3/schedules
|
14
|
+
# 创建一个新的定时任务
|
15
|
+
def create(schedule_payload)
|
16
|
+
schedule_payload = schedule_payload.is_a?(JPush::Schedule::SchedulePayload) ? schedule_payload : nil
|
17
|
+
body = schedule_payload.to_hash
|
18
|
+
Http::Client.post(@jpush, base_url, body: body)
|
19
|
+
end
|
20
|
+
|
21
|
+
# GET https://api.jpush.cn/v3/schedules?page=
|
22
|
+
# 获取当前有效(endtime未过期)的 schedule 列表
|
23
|
+
def tasks(page = nil)
|
24
|
+
Http::Client.get(@jpush, base_url, params: { page: page })
|
25
|
+
end
|
26
|
+
|
27
|
+
# 获取指定的定时任务
|
28
|
+
# GET https://api.jpush.cn/v3/schedules/{schedule_id}
|
29
|
+
def show(schedule_id)
|
30
|
+
Http::Client.get(@jpush, base_url + schedule_id)
|
31
|
+
end
|
32
|
+
|
33
|
+
# 修改指定的Schedule
|
34
|
+
# PUT https://api.jpush.cn/v3/schedules/{schedule_id}
|
35
|
+
def update(schedule_id, name: nil, enabled: nil, trigger: nil, push: nil)
|
36
|
+
body = JPush::Schedule::SchedulePayload.new(name, trigger, push, enabled).to_update_hash
|
37
|
+
Http::Client.put(@jpush, base_url + schedule_id, body: body)
|
38
|
+
end
|
39
|
+
|
40
|
+
# 删除指定的Schedule任务
|
41
|
+
# DELETE https://api.jpush.cn/v3/schedules/{schedule_id}
|
42
|
+
def delete(schedule_id)
|
43
|
+
Http::Client.delete(@jpush, base_url + schedule_id)
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def base_url
|
49
|
+
'https://api.jpush.cn/v3/schedules/'
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
@@ -1,34 +1,34 @@
|
|
1
|
-
module JPush
|
2
|
-
module Utils
|
3
|
-
module Exceptions
|
4
|
-
|
5
|
-
class JPushError < StandardError
|
6
|
-
attr_reader :message
|
7
|
-
def initialize(message)
|
8
|
-
@message = message
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
class JPushResponseError < JPushError
|
13
|
-
attr_reader :http_code, :error_code, :error_message
|
14
|
-
|
15
|
-
def initialize(http_code, error_code, error_message)
|
16
|
-
@http_code, @error_code, @error_message = http_code, error_code, error_message
|
17
|
-
@error_message = "UnknownError[#{@http_code}]." if @error_message.nil?
|
18
|
-
super("#{@error_message} (error code: #{@error_code}) ")
|
19
|
-
end
|
20
|
-
|
21
|
-
def to_s
|
22
|
-
"#{@message}. http status code: #{@http_code}"
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
class TimeOutError < JPushError
|
27
|
-
def initialize(error)
|
28
|
-
super("#{error.class} was raised, please rescue it")
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
1
|
+
module JPush
|
2
|
+
module Utils
|
3
|
+
module Exceptions
|
4
|
+
|
5
|
+
class JPushError < StandardError
|
6
|
+
attr_reader :message
|
7
|
+
def initialize(message)
|
8
|
+
@message = message
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class JPushResponseError < JPushError
|
13
|
+
attr_reader :http_code, :error_code, :error_message
|
14
|
+
|
15
|
+
def initialize(http_code, error_code, error_message)
|
16
|
+
@http_code, @error_code, @error_message = http_code, error_code, error_message
|
17
|
+
@error_message = "UnknownError[#{@http_code}]." if @error_message.nil?
|
18
|
+
super("#{@error_message} (error code: #{@error_code}) ")
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_s
|
22
|
+
"#{@message}. http status code: #{@http_code}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class TimeOutError < JPushError
|
27
|
+
def initialize(error)
|
28
|
+
super("#{error.class} was raised, please rescue it")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/jpush/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
module JPush
|
2
|
-
VERSION = "4.0.
|
3
|
-
end
|
1
|
+
module JPush
|
2
|
+
VERSION = "4.0.10"
|
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.
|
4
|
+
version: 4.0.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- JPush Offical
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-08-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -71,21 +71,21 @@ files:
|
|
71
71
|
- docs/Guides.md
|
72
72
|
- jpush.gemspec
|
73
73
|
- lib/jpush.rb
|
74
|
-
- lib/jpush/
|
75
|
-
- lib/jpush/config.rb
|
74
|
+
- lib/jpush/client.rb
|
76
75
|
- lib/jpush/device.rb
|
76
|
+
- lib/jpush/handler.rb
|
77
77
|
- lib/jpush/http/client.rb
|
78
78
|
- lib/jpush/http/response.rb
|
79
|
-
- lib/jpush/push.rb
|
80
79
|
- lib/jpush/push/audience.rb
|
81
80
|
- lib/jpush/push/notification.rb
|
82
81
|
- lib/jpush/push/push_payload.rb
|
82
|
+
- lib/jpush/push/single_push_payload.rb
|
83
|
+
- lib/jpush/pusher.rb
|
83
84
|
- lib/jpush/report.rb
|
84
|
-
- lib/jpush/schedule.rb
|
85
85
|
- lib/jpush/schedule/schedule_payload.rb
|
86
86
|
- lib/jpush/schedule/trigger.rb
|
87
|
+
- lib/jpush/schedules.rb
|
87
88
|
- lib/jpush/utils/exceptions.rb
|
88
|
-
- lib/jpush/utils/http.rb
|
89
89
|
- lib/jpush/version.rb
|
90
90
|
homepage: https://github.com/jpush/jpush-api-ruby-client
|
91
91
|
licenses:
|
@@ -108,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
108
108
|
version: '0'
|
109
109
|
requirements: []
|
110
110
|
rubyforge_project:
|
111
|
-
rubygems_version: 2.6.
|
111
|
+
rubygems_version: 2.7.6.2
|
112
112
|
signing_key:
|
113
113
|
specification_version: 4
|
114
114
|
summary: JPush's officially supported Ruby client library for accessing JPush APIs.
|
data/lib/jpush/api.rb
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
require 'jpush/device'
|
2
|
-
require 'jpush/push'
|
3
|
-
require 'jpush/report'
|
4
|
-
require 'jpush/schedule'
|
5
|
-
|
6
|
-
module JPush
|
7
|
-
module API
|
8
|
-
def devices
|
9
|
-
Device
|
10
|
-
end
|
11
|
-
|
12
|
-
def tags
|
13
|
-
Tag
|
14
|
-
end
|
15
|
-
|
16
|
-
def aliases
|
17
|
-
Alias
|
18
|
-
end
|
19
|
-
|
20
|
-
def pusher
|
21
|
-
Push
|
22
|
-
end
|
23
|
-
|
24
|
-
def reporter
|
25
|
-
Report
|
26
|
-
end
|
27
|
-
|
28
|
-
def schedules
|
29
|
-
Schedule
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
class Client
|
34
|
-
include JPush::API
|
35
|
-
|
36
|
-
def initialize(app_key, master_secret)
|
37
|
-
JPush::Config.init(app_key, master_secret)
|
38
|
-
end
|
39
|
-
|
40
|
-
end
|
41
|
-
|
42
|
-
end
|
data/lib/jpush/config.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
module JPush
|
2
|
-
module Config
|
3
|
-
extend self
|
4
|
-
|
5
|
-
DEFAULT_OPTIONS = {
|
6
|
-
api_version: 'v3',
|
7
|
-
push_api_host: 'https://api.jpush.cn/',
|
8
|
-
device_api_host: 'https://device.jpush.cn/',
|
9
|
-
report_api_host: 'https://report.jpush.cn/',
|
10
|
-
valid_platform: ['android', 'ios']
|
11
|
-
}
|
12
|
-
|
13
|
-
attr_reader :settings
|
14
|
-
|
15
|
-
def init(app_key, master_secret)
|
16
|
-
@settings = DEFAULT_OPTIONS.merge!(app_key: app_key, master_secret: master_secret)
|
17
|
-
end
|
18
|
-
|
19
|
-
end
|
20
|
-
end
|
data/lib/jpush/push.rb
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'jpush/push/push_payload'
|
2
|
-
require 'jpush/http/client'
|
3
|
-
|
4
|
-
module JPush
|
5
|
-
module Push
|
6
|
-
extend self
|
7
|
-
|
8
|
-
# POST https://api.jpush.cn/v3/push/validate
|
9
|
-
# 验证推送调用是否能够成功,与推送 API 的区别在于:不向用户发送任何消息
|
10
|
-
def validate(push_payload)
|
11
|
-
url = base_url + 'validate'
|
12
|
-
send_push(url, push_payload)
|
13
|
-
end
|
14
|
-
|
15
|
-
# POST https://api.jpush.cn/v3/push
|
16
|
-
# 向某单个设备或者某设备列表推送一条通知、或者消息
|
17
|
-
def push(push_payload)
|
18
|
-
send_push(base_url, push_payload)
|
19
|
-
end
|
20
|
-
|
21
|
-
private
|
22
|
-
|
23
|
-
def send_push(url, push_payload)
|
24
|
-
push_payload = push_payload.is_a?(PushPayload) ? push_payload : nil
|
25
|
-
body = push_payload.to_hash
|
26
|
-
Http::Client.post(url, body: body)
|
27
|
-
end
|
28
|
-
|
29
|
-
def base_url
|
30
|
-
Config.settings[:push_api_host] + Config.settings[:api_version] + '/push/'
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|
34
|
-
end
|
data/lib/jpush/utils/http.rb
DELETED
@@ -1,78 +0,0 @@
|
|
1
|
-
require 'net/http'
|
2
|
-
require 'json'
|
3
|
-
require 'jpush/utils/exceptions'
|
4
|
-
|
5
|
-
module JPush
|
6
|
-
module Utils
|
7
|
-
class Http
|
8
|
-
|
9
|
-
DEFAULT_USER_AGENT = 'jpush-api-ruby-client/' + JPush::VERSION
|
10
|
-
DEFAULT_OPEN_TIMEOUT = 20
|
11
|
-
DEFAULT_READ_TIMEOUT = 120
|
12
|
-
DEFAULT_RETRY_TIMES = 3
|
13
|
-
RETRY_SLEEP_TIME = 3
|
14
|
-
|
15
|
-
HTTP_VERB_MAP = {
|
16
|
-
get: Net::HTTP::Get,
|
17
|
-
post: Net::HTTP::Post,
|
18
|
-
put: Net::HTTP::Put,
|
19
|
-
delete: Net::HTTP::Delete
|
20
|
-
}
|
21
|
-
|
22
|
-
DEFAULT_HEADERS = {
|
23
|
-
'user-agent' => DEFAULT_USER_AGENT,
|
24
|
-
'accept' => 'application/json',
|
25
|
-
'content-type' => 'application/json',
|
26
|
-
'connection' => 'close'
|
27
|
-
}
|
28
|
-
|
29
|
-
def initialize(method, url, params: nil, body: nil, headers: {}, opts: {})
|
30
|
-
method = method.downcase.to_sym
|
31
|
-
err_msg = "http method #{method} is not supported"
|
32
|
-
raise Utils::Exceptions::JPushError, err_msg unless HTTP_VERB_MAP.keys.include?(method)
|
33
|
-
@uri = URI(url)
|
34
|
-
@uri.query = URI.encode_www_form(params) unless params.nil?
|
35
|
-
@request = prepare_request(method, body, headers)
|
36
|
-
@opts = opts
|
37
|
-
end
|
38
|
-
|
39
|
-
def send_request
|
40
|
-
tries ||= DEFAULT_RETRY_TIMES
|
41
|
-
opts ||= default_opts.merge @opts
|
42
|
-
Net::HTTP.start(@uri.host, @uri.port, opts) do |http|
|
43
|
-
http.request(@request)
|
44
|
-
end
|
45
|
-
# if raise Timeout::Error retry it for 3 times
|
46
|
-
rescue Net::OpenTimeout, Net::ReadTimeout => e
|
47
|
-
(tries -= 1).zero? ? (raise Utils::Exceptions::TimeOutError.new(e)) : retry
|
48
|
-
end
|
49
|
-
|
50
|
-
def basic_auth(user = nil, password = nil)
|
51
|
-
user ||= Config.settings[:app_key]
|
52
|
-
password ||= Config.settings[:master_secret]
|
53
|
-
@request.basic_auth(user, password)
|
54
|
-
self
|
55
|
-
end
|
56
|
-
|
57
|
-
private
|
58
|
-
|
59
|
-
def prepare_request(method, body, headers)
|
60
|
-
headers = DEFAULT_HEADERS.merge(headers)
|
61
|
-
request = HTTP_VERB_MAP[method].new @uri
|
62
|
-
request.initialize_http_header(headers)
|
63
|
-
request.body = body.to_json unless body.nil?
|
64
|
-
request
|
65
|
-
end
|
66
|
-
|
67
|
-
|
68
|
-
def default_opts
|
69
|
-
{
|
70
|
-
use_ssl: 'https' == @uri.scheme,
|
71
|
-
open_timeout: DEFAULT_OPEN_TIMEOUT,
|
72
|
-
read_timeout: DEFAULT_READ_TIMEOUT
|
73
|
-
}
|
74
|
-
end
|
75
|
-
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|