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,48 +1,48 @@
|
|
1
|
-
require 'jpush/push/push_payload'
|
2
|
-
require 'jpush/schedule/trigger'
|
3
|
-
|
4
|
-
module JPush
|
5
|
-
module Schedule
|
6
|
-
class SchedulePayload
|
7
|
-
|
8
|
-
def initialize(name, trigger, push_payload, enabled = nil)
|
9
|
-
@name = name
|
10
|
-
@trigger = build_trigger(trigger)
|
11
|
-
@push_payload = build_push_payload(push_payload)
|
12
|
-
@enabled = enabled
|
13
|
-
end
|
14
|
-
|
15
|
-
def to_update_hash
|
16
|
-
@schedule_payload = {
|
17
|
-
name: @name,
|
18
|
-
enabled: @enabled,
|
19
|
-
trigger: @trigger,
|
20
|
-
push: @push_payload
|
21
|
-
}.select { |_, value| !value.nil? }
|
22
|
-
raise Utils::Exceptions::JPushError, 'Schedule update body can not be empty' if @schedule_payload.empty?
|
23
|
-
@schedule_payload
|
24
|
-
end
|
25
|
-
|
26
|
-
def to_hash
|
27
|
-
@schedule_payload = {
|
28
|
-
name: @name,
|
29
|
-
enabled: true,
|
30
|
-
trigger: @trigger,
|
31
|
-
push: @push_payload
|
32
|
-
}
|
33
|
-
hash = @schedule_payload.select { |_, value| value.nil? }
|
34
|
-
@schedule_payload
|
35
|
-
end
|
36
|
-
|
37
|
-
def build_trigger(trigger)
|
38
|
-
return { single: { time: trigger.strftime('%F %T') } } if trigger.is_a? Time
|
39
|
-
trigger.is_a?(Trigger) ? trigger.to_hash : nil
|
40
|
-
end
|
41
|
-
|
42
|
-
def build_push_payload(push_payload)
|
43
|
-
push_payload.is_a?(Push::PushPayload) ? push_payload.to_hash : nil
|
44
|
-
end
|
45
|
-
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
1
|
+
require 'jpush/push/push_payload'
|
2
|
+
require 'jpush/schedule/trigger'
|
3
|
+
|
4
|
+
module JPush
|
5
|
+
module Schedule
|
6
|
+
class SchedulePayload
|
7
|
+
|
8
|
+
def initialize(name, trigger, push_payload, enabled = nil)
|
9
|
+
@name = name
|
10
|
+
@trigger = build_trigger(trigger)
|
11
|
+
@push_payload = build_push_payload(push_payload)
|
12
|
+
@enabled = enabled
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_update_hash
|
16
|
+
@schedule_payload = {
|
17
|
+
name: @name,
|
18
|
+
enabled: @enabled,
|
19
|
+
trigger: @trigger,
|
20
|
+
push: @push_payload
|
21
|
+
}.select { |_, value| !value.nil? }
|
22
|
+
raise Utils::Exceptions::JPushError, 'Schedule update body can not be empty' if @schedule_payload.empty?
|
23
|
+
@schedule_payload
|
24
|
+
end
|
25
|
+
|
26
|
+
def to_hash
|
27
|
+
@schedule_payload = {
|
28
|
+
name: @name,
|
29
|
+
enabled: true,
|
30
|
+
trigger: @trigger,
|
31
|
+
push: @push_payload
|
32
|
+
}
|
33
|
+
hash = @schedule_payload.select { |_, value| value.nil? }
|
34
|
+
@schedule_payload
|
35
|
+
end
|
36
|
+
|
37
|
+
def build_trigger(trigger)
|
38
|
+
return { single: { time: trigger.strftime('%F %T') } } if trigger.is_a? Time
|
39
|
+
trigger.is_a?(Trigger) ? trigger.to_hash : nil
|
40
|
+
end
|
41
|
+
|
42
|
+
def build_push_payload(push_payload)
|
43
|
+
push_payload.is_a?(Push::PushPayload) ? push_payload.to_hash : nil
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -1,53 +1,53 @@
|
|
1
|
-
module JPush
|
2
|
-
module Schedule
|
3
|
-
class Trigger
|
4
|
-
|
5
|
-
WEEK = ['MON','TUE','WED','THU','FRI','SAT','SUN']
|
6
|
-
MDAY = ('01'..'31').to_a
|
7
|
-
|
8
|
-
def set_single(time)
|
9
|
-
@periodical = nil
|
10
|
-
@single = { time: time.strftime('%F %T') }
|
11
|
-
self
|
12
|
-
end
|
13
|
-
|
14
|
-
def set_periodical(start_time, end_time, time, time_unit, frequency, point)
|
15
|
-
@single = nil
|
16
|
-
require 'time'
|
17
|
-
frequency = 100 if frequency > 100
|
18
|
-
@periodical = {
|
19
|
-
start: start_time.strftime('%F %T'),
|
20
|
-
end: end_time.strftime('%F %T'),
|
21
|
-
time: Time.parse(time).strftime('%T'),
|
22
|
-
time_unit: time_unit,
|
23
|
-
frequency: frequency,
|
24
|
-
point: build_point(time_unit, point)
|
25
|
-
}
|
26
|
-
self
|
27
|
-
end
|
28
|
-
|
29
|
-
def to_hash
|
30
|
-
@trigger = {}
|
31
|
-
@trigger[:single] = @single unless @single.nil?
|
32
|
-
@trigger[:periodical] = @periodical unless @periodical.nil?
|
33
|
-
@trigger
|
34
|
-
end
|
35
|
-
|
36
|
-
private
|
37
|
-
|
38
|
-
def build_point(time_unit, point)
|
39
|
-
array = [point].flatten
|
40
|
-
point =
|
41
|
-
case time_unit.upcase
|
42
|
-
when 'DAY'
|
43
|
-
nil
|
44
|
-
when 'WEEK'
|
45
|
-
WEEK & array.map{ |e| e.upcase }
|
46
|
-
when 'MONTH'
|
47
|
-
MDAY & array
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
1
|
+
module JPush
|
2
|
+
module Schedule
|
3
|
+
class Trigger
|
4
|
+
|
5
|
+
WEEK = ['MON','TUE','WED','THU','FRI','SAT','SUN']
|
6
|
+
MDAY = ('01'..'31').to_a
|
7
|
+
|
8
|
+
def set_single(time)
|
9
|
+
@periodical = nil
|
10
|
+
@single = { time: time.strftime('%F %T') }
|
11
|
+
self
|
12
|
+
end
|
13
|
+
|
14
|
+
def set_periodical(start_time, end_time, time, time_unit, frequency, point)
|
15
|
+
@single = nil
|
16
|
+
require 'time'
|
17
|
+
frequency = 100 if frequency > 100
|
18
|
+
@periodical = {
|
19
|
+
start: start_time.strftime('%F %T'),
|
20
|
+
end: end_time.strftime('%F %T'),
|
21
|
+
time: Time.parse(time).strftime('%T'),
|
22
|
+
time_unit: time_unit,
|
23
|
+
frequency: frequency,
|
24
|
+
point: build_point(time_unit, point)
|
25
|
+
}
|
26
|
+
self
|
27
|
+
end
|
28
|
+
|
29
|
+
def to_hash
|
30
|
+
@trigger = {}
|
31
|
+
@trigger[:single] = @single unless @single.nil?
|
32
|
+
@trigger[:periodical] = @periodical unless @periodical.nil?
|
33
|
+
@trigger
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def build_point(time_unit, point)
|
39
|
+
array = [point].flatten
|
40
|
+
point =
|
41
|
+
case time_unit.upcase
|
42
|
+
when 'DAY'
|
43
|
+
nil
|
44
|
+
when 'WEEK'
|
45
|
+
WEEK & array.map{ |e| e.upcase }
|
46
|
+
when 'MONTH'
|
47
|
+
MDAY & array
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/lib/jpush/schedules.rb
CHANGED
@@ -1,53 +1,53 @@
|
|
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
|
+
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.11"
|
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.11
|
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: 2020-01-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|