jpush 3.1.1
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 +7 -0
- data/.gitignore +18 -0
- data/.project +18 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +339 -0
- data/README.md +75 -0
- data/Rakefile +1 -0
- data/example/push_example.rb +101 -0
- data/example/report_example.rb +18 -0
- data/jpush.gemspec +24 -0
- data/lib/jpush.rb +20 -0
- data/lib/jpush/http_client.rb +124 -0
- data/lib/jpush/jpush_client.rb +75 -0
- data/lib/jpush/model/audience.rb +67 -0
- data/lib/jpush/model/message.rb +37 -0
- data/lib/jpush/model/messages_result.rb +7 -0
- data/lib/jpush/model/notification/android_notification.rb +38 -0
- data/lib/jpush/model/notification/ios_notification.rb +60 -0
- data/lib/jpush/model/notification/notification.rb +35 -0
- data/lib/jpush/model/notification/winphone_notification.rb +37 -0
- data/lib/jpush/model/options.rb +53 -0
- data/lib/jpush/model/platform.rb +57 -0
- data/lib/jpush/model/push_payload.rb +70 -0
- data/lib/jpush/model/push_result.rb +32 -0
- data/lib/jpush/model/receiveds_result.rb +62 -0
- data/lib/jpush/push_client.rb +31 -0
- data/lib/jpush/report_client.rb +45 -0
- data/lib/jpush/response_wrapper.rb +36 -0
- data/lib/jpush/util/service_helper.rb +10 -0
- data/test/alert_override_tests.rb +62 -0
- data/test/audience_tests.rb +169 -0
- data/test/base_remote_tests.rb +27 -0
- data/test/message_tests.rb +49 -0
- data/test/notification_tests.rb +52 -0
- data/test/push_payload_test.rb +58 -0
- data/test/report_function_tests.rb +40 -0
- metadata +101 -0
@@ -0,0 +1,38 @@
|
|
1
|
+
module JPush
|
2
|
+
class AndroidNotification
|
3
|
+
attr_accessor :alert, :title, :builder_id, :extras
|
4
|
+
def initialize(opts = {})
|
5
|
+
@alert = opts[:alert]
|
6
|
+
@title = opts[:title]
|
7
|
+
@builder_id = opts[:builder_id]
|
8
|
+
@extras = opts[:extras]
|
9
|
+
end
|
10
|
+
|
11
|
+
def toJSON
|
12
|
+
array = {}
|
13
|
+
if @alert != nil then
|
14
|
+
array['alert'] = @alert
|
15
|
+
end
|
16
|
+
if @title != nil then
|
17
|
+
array['title'] = @title
|
18
|
+
end
|
19
|
+
if @builder_id != nil then
|
20
|
+
array['builder_id'] = @builder_id
|
21
|
+
end
|
22
|
+
if @extras != nil then
|
23
|
+
array['extras'] = @extras
|
24
|
+
end
|
25
|
+
|
26
|
+
return array
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.build(opts = {})
|
30
|
+
android = JPush::AndroidNotification.new(opts)
|
31
|
+
if android.alert == nil
|
32
|
+
raise ArgumentError.new('android the alert should be setted')
|
33
|
+
end
|
34
|
+
return android
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module JPush
|
2
|
+
class IOSNotification
|
3
|
+
attr_accessor :alert, :sound, :badge, :extras, :content_available
|
4
|
+
def initialize(opts = {})
|
5
|
+
if opts[:badge] != nil
|
6
|
+
@badge = opts[:badge]
|
7
|
+
else
|
8
|
+
@badge = 1
|
9
|
+
end
|
10
|
+
if opts[:sound] != nil
|
11
|
+
@sound = opts[:sound]
|
12
|
+
else
|
13
|
+
@sound = ''
|
14
|
+
end
|
15
|
+
@alert = opts[:alert]
|
16
|
+
@extras = opts[:extras]
|
17
|
+
@content_available = opts[:content_available]
|
18
|
+
end
|
19
|
+
|
20
|
+
def toJSON
|
21
|
+
array = {}
|
22
|
+
if @alert != nil then
|
23
|
+
array['alert'] = @alert
|
24
|
+
end
|
25
|
+
if @sound != nil && @sound != false then
|
26
|
+
array['sound'] = @sound
|
27
|
+
end
|
28
|
+
if @badge != nil && @badge != false then
|
29
|
+
array['badge'] = @badge
|
30
|
+
end
|
31
|
+
if @extras != nil then
|
32
|
+
array['extras'] = @extras
|
33
|
+
end
|
34
|
+
if @content_available != nil then
|
35
|
+
array['content-available'] = content_available
|
36
|
+
end
|
37
|
+
return array
|
38
|
+
end
|
39
|
+
|
40
|
+
def disableSound
|
41
|
+
@sound = false
|
42
|
+
end
|
43
|
+
|
44
|
+
def disableBadge
|
45
|
+
@badge = false
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.build(opts = {})
|
49
|
+
ios = JPush::IOSNotification.new(opts)
|
50
|
+
if ios.alert == nil
|
51
|
+
raise ArgumentError.new('the alert should be setted')
|
52
|
+
end
|
53
|
+
if ios.to_s.bytesize > 220
|
54
|
+
raise ArgumentError.new('ios notfication size is longer than 220 ')
|
55
|
+
end
|
56
|
+
return ios
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module JPush
|
2
|
+
class Notification
|
3
|
+
attr_accessor :alert, :android, :ios, :winphone
|
4
|
+
def initialize(opts = {})
|
5
|
+
@alert = opts[:alert]
|
6
|
+
@android = opts[:android]
|
7
|
+
@ios = opts[:ios]
|
8
|
+
@winphone = opts[:winphone]
|
9
|
+
end
|
10
|
+
|
11
|
+
def toJSON
|
12
|
+
array = {}
|
13
|
+
if @alert != nil && alert.lstrip.length > 0
|
14
|
+
array['alert'] = @alert
|
15
|
+
end
|
16
|
+
if @android != nil
|
17
|
+
array['android'] = @android.toJSON
|
18
|
+
end
|
19
|
+
if @ios != nil
|
20
|
+
array['ios'] = @ios.toJSON
|
21
|
+
end
|
22
|
+
if @winphone != nil
|
23
|
+
array['winphone'] = @winphone.toJSON
|
24
|
+
end
|
25
|
+
|
26
|
+
return array
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.build(opts = {})
|
30
|
+
notification=JPush::Notification.new(opts)
|
31
|
+
return notification
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module JPush
|
2
|
+
class WinphoneNotification
|
3
|
+
attr_accessor :alert, :title, :_open_page, :extras
|
4
|
+
def initialize(opts = {})
|
5
|
+
@alert = opts[:alert]
|
6
|
+
@title = opts[:title]
|
7
|
+
@_open_page = opts[:_open_page]
|
8
|
+
@extras = opts[:extras]
|
9
|
+
end
|
10
|
+
|
11
|
+
def toJSON
|
12
|
+
array = {}
|
13
|
+
if @alert != nil then
|
14
|
+
array['alert'] = @alert
|
15
|
+
end
|
16
|
+
if @title != nil then
|
17
|
+
array['title'] = @title
|
18
|
+
end
|
19
|
+
if @_open_page != nil then
|
20
|
+
array['_open_page'] = @_open_page
|
21
|
+
end
|
22
|
+
if @extras != nil then
|
23
|
+
array['extras'] = @extras
|
24
|
+
end
|
25
|
+
return array
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.build(opts = {})
|
29
|
+
winphone = JPush::WinphoneNotification.new(opts)
|
30
|
+
if winphone.alert == nil
|
31
|
+
raise ArgumentError.new('winphone the alert should be setted')
|
32
|
+
end
|
33
|
+
return winphone
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module JPush
|
2
|
+
class Options
|
3
|
+
attr_accessor :sendno, :time_to_live, :override_msg_id, :apns_production
|
4
|
+
def initialize(opts = {})
|
5
|
+
if opts[:apns_production] != nil
|
6
|
+
@apns_production = opts[:apns_production]
|
7
|
+
else
|
8
|
+
@apns_production = false
|
9
|
+
end
|
10
|
+
|
11
|
+
@sendno = opts[:sendno]
|
12
|
+
|
13
|
+
if opts[:time_to_live] != nil
|
14
|
+
@time_to_live = opts[:time_to_live]
|
15
|
+
else
|
16
|
+
@time_to_live = 86400
|
17
|
+
end
|
18
|
+
@overrride_msg_id = opts[:override_msg_id]
|
19
|
+
end
|
20
|
+
|
21
|
+
def toJSON
|
22
|
+
array = {}
|
23
|
+
if @sendno != nil then
|
24
|
+
array['sendno'] = @sendno
|
25
|
+
end
|
26
|
+
if @time_to_live != nil then
|
27
|
+
array['time_to_live'] = @time_to_live
|
28
|
+
end
|
29
|
+
if @override_msg_id != nil then
|
30
|
+
array['override_msg_id'] = @override_msg_id
|
31
|
+
end
|
32
|
+
if @apns_production != nil then
|
33
|
+
array['apns_production'] = @apns_production
|
34
|
+
end
|
35
|
+
return array
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.build(opts = {})
|
39
|
+
options = JPush::Options.new(opts)
|
40
|
+
if options.sendno != nil&&options.sendno < 0
|
41
|
+
raise ArgumentError.new('sendno should be greater than 0.')
|
42
|
+
end
|
43
|
+
if options.override_msg_id != nil&&options.override_msg_id < 0
|
44
|
+
raise ArgumentError.new(' override_msg_id should be greater than 0.')
|
45
|
+
end
|
46
|
+
if options.time_to_live != nil&&options.time_to_live < 0
|
47
|
+
raise ArgumentError.new('time_to_live should be greater than 0.')
|
48
|
+
end
|
49
|
+
return options
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module JPush
|
2
|
+
class Platform
|
3
|
+
attr_accessor :android, :ios, :winphone
|
4
|
+
def initialize(opts = {})
|
5
|
+
if opts[:android] != nil
|
6
|
+
@android = opts[:android]
|
7
|
+
else
|
8
|
+
@android = false
|
9
|
+
end
|
10
|
+
if opts[:ios] != nil
|
11
|
+
@ios = opts[:ios]
|
12
|
+
else
|
13
|
+
@ios = false
|
14
|
+
end
|
15
|
+
if opts[:winphone] != nil
|
16
|
+
@winphone = opts[:winphone]
|
17
|
+
else
|
18
|
+
@winphone = false
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def toJSON
|
23
|
+
if @android == true && @ios ==true && @winphone == true
|
24
|
+
return 'all'
|
25
|
+
else
|
26
|
+
array = Array.new
|
27
|
+
if @android == true then
|
28
|
+
array.push('android')
|
29
|
+
end
|
30
|
+
if @ios == true then
|
31
|
+
array.push('ios')
|
32
|
+
end
|
33
|
+
if @winphone == true then
|
34
|
+
array.push('winphone')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
return array
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.all
|
41
|
+
pl = JPush::Platform.new
|
42
|
+
pl.ios = true
|
43
|
+
pl.android = true
|
44
|
+
pl.winphone = true
|
45
|
+
return pl
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.build(opts = {})
|
49
|
+
platform = JPush::Platform.new(opts)
|
50
|
+
if platform.android != true&&platform.ios != true&&platform.winphone != true
|
51
|
+
raise ArgumentError.new('No any deviceType is set.')
|
52
|
+
end
|
53
|
+
return platform
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
module JPush
|
2
|
+
=begin
|
3
|
+
The object you should build for sending a push.
|
4
|
+
@param platform audience must be set
|
5
|
+
=end
|
6
|
+
class PushPayload
|
7
|
+
attr_accessor :platform, :audience, :message, :options, :notification
|
8
|
+
def initialize(opts = {})
|
9
|
+
@platform = opts[:platform]
|
10
|
+
@audience = opts[:audience]
|
11
|
+
@message = opts[:message]
|
12
|
+
@options = opts[:options]
|
13
|
+
@notification = opts[:notification]
|
14
|
+
end
|
15
|
+
|
16
|
+
def toJSON
|
17
|
+
array = {}
|
18
|
+
if @platform != nil then
|
19
|
+
array['platform'] = @platform.toJSON
|
20
|
+
end
|
21
|
+
if @audience != nil then
|
22
|
+
array['audience'] = @audience.toJSON
|
23
|
+
end
|
24
|
+
if @message != nil then
|
25
|
+
array['message'] = @message.toJSON
|
26
|
+
end
|
27
|
+
if @options != nil then
|
28
|
+
array['options'] = @options.toJSON
|
29
|
+
end
|
30
|
+
if @notification != nil then
|
31
|
+
array['notification'] = @notification.toJSON
|
32
|
+
end
|
33
|
+
return array
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.build(opts = {})
|
37
|
+
payload = JPush::PushPayload.new(opts)
|
38
|
+
if payload.audience == nil || payload.platform == nil
|
39
|
+
raise ArgumentError.new(' audience and platform both should be set.')
|
40
|
+
end
|
41
|
+
if payload.notification == nil && payload.message == nil
|
42
|
+
raise ArgumentError.new('notification or message should be set at least one')
|
43
|
+
end
|
44
|
+
|
45
|
+
if payload.notification.to_s.bytesize + payload.message.to_s.bytesize > 1200
|
46
|
+
raise ArgumentError.new('notfication and message size is longer than 1200 ')
|
47
|
+
end
|
48
|
+
return payload
|
49
|
+
end
|
50
|
+
|
51
|
+
#used only the ios nitification is not nil
|
52
|
+
def isIOSExceedLength
|
53
|
+
if @notification.ios.to_s.bytesize > 220
|
54
|
+
return false
|
55
|
+
else
|
56
|
+
return true
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
#Check if the length is too long
|
61
|
+
def isGlobalExceed
|
62
|
+
if @notification.to_s.bytesize + @message.to_s.bytesize > 1200
|
63
|
+
return false
|
64
|
+
else
|
65
|
+
return true
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module JPush
|
4
|
+
class PushResult
|
5
|
+
attr_accessor :sendno, :msg_id, :isok
|
6
|
+
def initialize
|
7
|
+
@isok=false
|
8
|
+
end
|
9
|
+
def fromResponse(wrapper)
|
10
|
+
if wrapper.code != 200
|
11
|
+
logger = Logger.new(STDOUT)
|
12
|
+
logger.error('Error response from JPush server. Should review and fix it. ')
|
13
|
+
logger.info('HTTP Status:',wrapper.code)
|
14
|
+
logger.info('Error Message',wrapper.error)
|
15
|
+
raise RuntimeError.new('response error')
|
16
|
+
end
|
17
|
+
content = wrapper.getResponseContent
|
18
|
+
hash = JSON.parse(content)
|
19
|
+
@sendno = hash['sendno']
|
20
|
+
@msg_id = hash['msg_id']
|
21
|
+
@isok=true
|
22
|
+
return self
|
23
|
+
end
|
24
|
+
|
25
|
+
def toJSON
|
26
|
+
array={}
|
27
|
+
array['sendno'] = @sendno
|
28
|
+
array['msg_id'] = @msg_id
|
29
|
+
return array.to_json
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module JPush
|
4
|
+
class ReceivedsResult
|
5
|
+
attr_accessor :isok, :list
|
6
|
+
def initialize
|
7
|
+
@isok = false
|
8
|
+
end
|
9
|
+
|
10
|
+
def fromResponse(wrapper)
|
11
|
+
if wrapper.code != 200
|
12
|
+
logger = Logger.new(STDOUT)
|
13
|
+
logger.error('Error response from JPush server. Should review and fix it. ')
|
14
|
+
logger.info('HTTP Status:',wrapper.code.to_s)
|
15
|
+
logger.info('Error Message',wrapper.error)
|
16
|
+
raise RuntimeError.new('response error')
|
17
|
+
end
|
18
|
+
content = wrapper.getResponseContent
|
19
|
+
hash = JSON.parse(content)
|
20
|
+
i = 0
|
21
|
+
@list = []
|
22
|
+
while i < hash.length
|
23
|
+
re = JPush::Receiveds.new
|
24
|
+
re.msg_id = hash[i]['msg_id']
|
25
|
+
re.ios_apns_sent = hash[i]['ios_apns_sent']
|
26
|
+
re.android_received = hash[i]['android_received']
|
27
|
+
list.push re
|
28
|
+
i = i+1
|
29
|
+
end
|
30
|
+
@isok = true
|
31
|
+
return self
|
32
|
+
end
|
33
|
+
|
34
|
+
def toJSON
|
35
|
+
array = []
|
36
|
+
i = 0
|
37
|
+
while i < @list.length
|
38
|
+
array.push @list[i].toJSON
|
39
|
+
i = i + 1
|
40
|
+
end
|
41
|
+
return array.to_json
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
class Receiveds
|
47
|
+
attr_accessor :msg_id, :android_received, :ios_apns_sent
|
48
|
+
def initialize
|
49
|
+
@msg_id = nil
|
50
|
+
@android_received = nil
|
51
|
+
@ios_apns_sent = nil
|
52
|
+
end
|
53
|
+
|
54
|
+
def toJSON
|
55
|
+
array = {}
|
56
|
+
array['msg_id'] = @msg_id
|
57
|
+
array['android_received'] = @android_received
|
58
|
+
array['ios_apns_sent'] = @ios_apns_sent
|
59
|
+
return array
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|