jpush 3.1.1 → 3.2.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.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/lib/jpush.rb +10 -0
  3. data/lib/jpush/api_connection_exception.rb +11 -0
  4. data/lib/jpush/device_client.rb +84 -0
  5. data/lib/jpush/http_client.rb +32 -18
  6. data/lib/jpush/jpush_client.rb +81 -7
  7. data/lib/jpush/model/alias_uids_result.rb +32 -0
  8. data/lib/jpush/model/exist_result.rb +33 -0
  9. data/lib/jpush/model/get_messages_result.rb +30 -0
  10. data/lib/jpush/model/notification/ios_notification.rb +6 -2
  11. data/lib/jpush/model/options.rb +15 -4
  12. data/lib/jpush/model/push_payload.rb +6 -0
  13. data/lib/jpush/model/push_result.rb +4 -4
  14. data/lib/jpush/model/receiveds_result.rb +3 -3
  15. data/lib/jpush/model/tag_alias.rb +62 -0
  16. data/lib/jpush/model/tag_alias_result.rb +32 -0
  17. data/lib/jpush/model/tag_list_result.rb +32 -0
  18. data/lib/jpush/model/tag_manager.rb +44 -0
  19. data/lib/jpush/model/user_result.rb +40 -0
  20. data/lib/jpush/push_client.rb +18 -4
  21. data/lib/jpush/report_client.rb +11 -6
  22. data/lib/jpush/response_wrapper.rb +2 -1
  23. data/lib/jpush/util/service_helper.rb +3 -2
  24. metadata +13 -26
  25. data/.gitignore +0 -18
  26. data/.project +0 -18
  27. data/Gemfile +0 -4
  28. data/LICENSE.txt +0 -339
  29. data/README.md +0 -75
  30. data/Rakefile +0 -1
  31. data/example/push_example.rb +0 -101
  32. data/example/report_example.rb +0 -18
  33. data/jpush.gemspec +0 -24
  34. data/test/alert_override_tests.rb +0 -62
  35. data/test/audience_tests.rb +0 -169
  36. data/test/base_remote_tests.rb +0 -27
  37. data/test/message_tests.rb +0 -49
  38. data/test/notification_tests.rb +0 -52
  39. data/test/push_payload_test.rb +0 -58
  40. data/test/report_function_tests.rb +0 -40
@@ -1,6 +1,6 @@
1
1
  module JPush
2
2
  class IOSNotification
3
- attr_accessor :alert, :sound, :badge, :extras, :content_available
3
+ attr_accessor :alert, :sound, :badge, :extras, :content_available, :category
4
4
  def initialize(opts = {})
5
5
  if opts[:badge] != nil
6
6
  @badge = opts[:badge]
@@ -15,6 +15,7 @@ module JPush
15
15
  @alert = opts[:alert]
16
16
  @extras = opts[:extras]
17
17
  @content_available = opts[:content_available]
18
+ @category = opts[:category]
18
19
  end
19
20
 
20
21
  def toJSON
@@ -32,7 +33,10 @@ module JPush
32
33
  array['extras'] = @extras
33
34
  end
34
35
  if @content_available != nil then
35
- array['content-available'] = content_available
36
+ array['content-available'] = @content_available
37
+ end
38
+ if @category != nil then
39
+ array['category'] = @category
36
40
  end
37
41
  return array
38
42
  end
@@ -1,6 +1,6 @@
1
1
  module JPush
2
2
  class Options
3
- attr_accessor :sendno, :time_to_live, :override_msg_id, :apns_production
3
+ attr_accessor :sendno, :time_to_live, :override_msg_id, :apns_production, :big_push_duration
4
4
  def initialize(opts = {})
5
5
  if opts[:apns_production] != nil
6
6
  @apns_production = opts[:apns_production]
@@ -16,6 +16,7 @@ module JPush
16
16
  @time_to_live = 86400
17
17
  end
18
18
  @overrride_msg_id = opts[:override_msg_id]
19
+ @big_push_duration = opts[:big_push_duration]
19
20
  end
20
21
 
21
22
  def toJSON
@@ -32,20 +33,30 @@ module JPush
32
33
  if @apns_production != nil then
33
34
  array['apns_production'] = @apns_production
34
35
  end
36
+ if @big_push_duration != nil then
37
+ array['big_push_duration'] = @big_push_duration
38
+ end
35
39
  return array
36
40
  end
37
41
 
38
42
  def self.build(opts = {})
39
43
  options = JPush::Options.new(opts)
40
- if options.sendno != nil&&options.sendno < 0
44
+ if options.sendno != nil && options.sendno < 0
41
45
  raise ArgumentError.new('sendno should be greater than 0.')
42
46
  end
43
- if options.override_msg_id != nil&&options.override_msg_id < 0
47
+ if options.override_msg_id != nil && options.override_msg_id < 0
44
48
  raise ArgumentError.new(' override_msg_id should be greater than 0.')
45
49
  end
46
- if options.time_to_live != nil&&options.time_to_live < 0
50
+ if options.time_to_live != nil && options.time_to_live < 0
47
51
  raise ArgumentError.new('time_to_live should be greater than 0.')
48
52
  end
53
+ if options.big_push_duration != nil && options.big_push_duration > 1440
54
+ raise ArgumentError.new('big_push_duration should be less than 1440.')
55
+ end
56
+
57
+ if options.big_push_duration != nil && options.big_push_duration <= 0
58
+ raise ArgumentError.new('big_push_duration should be greater than 0.')
59
+ end
49
60
  return options
50
61
  end
51
62
 
@@ -45,6 +45,12 @@ The object you should build for sending a push.
45
45
  if payload.notification.to_s.bytesize + payload.message.to_s.bytesize > 1200
46
46
  raise ArgumentError.new('notfication and message size is longer than 1200 ')
47
47
  end
48
+ if payload.options == nil
49
+ options = JPush::Options.build(
50
+ :time_to_live=> 86400,
51
+ :apns_production=> false)
52
+ payload.options = options
53
+ end
48
54
  return payload
49
55
  end
50
56
 
@@ -10,9 +10,9 @@ module JPush
10
10
  if wrapper.code != 200
11
11
  logger = Logger.new(STDOUT)
12
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')
13
+ logger.info("HTTP Status: #{wrapper.code.to_s}")
14
+ logger.info("Error Message: #{wrapper.error.to_s}")
15
+ raise JPush::ApiConnectionException.new(wrapper)
16
16
  end
17
17
  content = wrapper.getResponseContent
18
18
  hash = JSON.parse(content)
@@ -29,4 +29,4 @@ module JPush
29
29
  return array.to_json
30
30
  end
31
31
  end
32
- end
32
+ end
@@ -11,9 +11,9 @@ module JPush
11
11
  if wrapper.code != 200
12
12
  logger = Logger.new(STDOUT)
13
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')
14
+ logger.info('HTTP Status:' + wrapper.code.to_s)
15
+ logger.info('Error Message' + wrapper.error.to_s)
16
+ raise JPush::ApiConnectionException.new(wrapper)
17
17
  end
18
18
  content = wrapper.getResponseContent
19
19
  hash = JSON.parse(content)
@@ -0,0 +1,62 @@
1
+ module JPush
2
+ class TagAlias
3
+ attr_accessor :add, :remove, :alias ,:tags
4
+ def initialize(opts = {})
5
+ if opts[:add] != nil
6
+ if opts[:add].class == Array
7
+ @add = opts[:add]
8
+ else
9
+ raise ArgumentError.new('add should be array.')
10
+ end
11
+ end
12
+
13
+ if opts[:remove] != nil
14
+ if opts[:remove].class == Array
15
+ @remove = opts[:remove]
16
+ else
17
+ raise ArgumentError.new('add should be array.')
18
+ end
19
+ end
20
+
21
+ if opts[:alias] != nil
22
+ @alias = opts[:alias]
23
+ end
24
+ end
25
+
26
+ def toJSON
27
+ hash = {}
28
+ tags = {}
29
+ if @add != nil
30
+ tags['add'] = @add
31
+ end
32
+ if @remove != nil
33
+ tags['remove'] = @remove
34
+ end
35
+ if @alias != nil
36
+ hash['alias'] = @alias
37
+ end
38
+ if @tags == ''
39
+ hash['tags'] = @tags
40
+ else
41
+ hash['tags'] = tags
42
+ end
43
+
44
+ return hash
45
+ end
46
+
47
+
48
+
49
+
50
+ def self.clear
51
+ tags = JPush::TagAlias.new
52
+ tags.tags = ''
53
+ tags.alias = ''
54
+ return tags;
55
+ end
56
+
57
+ def self.build(opts = {})
58
+ tagAlias = JPush::TagAlias.new(opts)
59
+ return tagAlias
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,32 @@
1
+ require 'json'
2
+
3
+ module JPush
4
+ class TagAliasResult
5
+ attr_accessor :tags, :alias, :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.to_s)
14
+ logger.info('Error Message:' + wrapper.error.to_s)
15
+ raise JPush::ApiConnectionException.new(wrapper)
16
+ end
17
+ content = wrapper.getResponseContent
18
+ hash = JSON.parse(content)
19
+ @tags = hash['tags']
20
+ @alias = hash['alias']
21
+ @isok=true
22
+ return self
23
+ end
24
+
25
+ def toJSON
26
+ array={}
27
+ array['tags'] = @tags
28
+ array['alias'] = @alias
29
+ return array
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,32 @@
1
+ require 'json'
2
+
3
+ module JPush
4
+ class TagListResult
5
+ attr_accessor :tags, :isok
6
+
7
+ def initialize
8
+ @isok=false
9
+ end
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.to_s)
16
+ raise JPush::ApiConnectionException.new(wrapper)
17
+ end
18
+ content = wrapper.getResponseContent
19
+ hash = JSON.parse(content)
20
+ @tags = hash['tags']
21
+ @isok=true
22
+ return self
23
+ end
24
+
25
+ def toJSON
26
+ array={}
27
+ array['tags'] = @tags
28
+ return array
29
+ end
30
+
31
+ end
32
+ end
@@ -0,0 +1,44 @@
1
+ module JPush
2
+ class TagManager
3
+ attr_accessor :add, :remove
4
+
5
+ def initialize(opts = {})
6
+ if opts[:add] != nil
7
+ if opts[:add].class == Array && opts[:add].length <= 1000
8
+ @add = opts[:add]
9
+ else
10
+ raise ArgumentError.new('add should be array and size <= 1000.')
11
+ end
12
+ end
13
+
14
+ if opts[:remove] != nil
15
+ if opts[:remove].class == Array && opts[:remove].length <= 1000
16
+ @remove = opts[:remove]
17
+ else
18
+ raise ArgumentError.new('add should be array and size <= 1000.')
19
+ end
20
+ end
21
+
22
+ end
23
+
24
+ def toJSON
25
+ hash = {}
26
+ registration_ids = {}
27
+ if @add != nil
28
+ registration_ids['add'] = @add
29
+ end
30
+ if @remove != nil
31
+ registration_ids['remove'] = @remove
32
+ end
33
+
34
+ hash['registration_ids'] = registration_ids
35
+ return hash
36
+ end
37
+
38
+ def self.build(opts = {})
39
+ tm = JPush::TagManager.new(opts)
40
+ return tm
41
+ end
42
+
43
+ end
44
+ end
@@ -0,0 +1,40 @@
1
+ require 'json'
2
+
3
+ module JPush
4
+ class UserResult
5
+ attr_accessor :isok, :time_unit, :start, :duration, :items
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.to_s)
16
+ raise JPush::ApiConnectionException.new(wrapper)
17
+ end
18
+ content = wrapper.getResponseContent
19
+ hash = JSON.parse(content)
20
+ @time_unit = hash['time_unit']
21
+ @start = hash['start']
22
+ @duration = hash['duration']
23
+ @itmes = hash['items']
24
+ @isok = true
25
+ return self
26
+ end
27
+
28
+ def toJSON
29
+ array = {}
30
+ array['time_unit'] = @time_unit
31
+ array['start'] = @start
32
+ array['duration'] = @duration
33
+ array['items'] = @items
34
+ return array.to_json
35
+ end
36
+
37
+ end
38
+
39
+
40
+ end
@@ -1,4 +1,4 @@
1
- path= File.expand_path('../', __FILE__)
1
+ path = File.expand_path('../', __FILE__)
2
2
  require File.join(path, 'http_client.rb')
3
3
  require File.join(path, 'model/push_result.rb')
4
4
  require 'json'
@@ -10,6 +10,7 @@ timeToLive If not present, the default is 86400(s) (one day).
10
10
  module JPush
11
11
  class PushClient
12
12
  @@PUSH_API_URL = 'https://api.jpush.cn/v3/push'
13
+ @@VALIDATE = '/validate'
13
14
  @@_timeToLive = 60 * 60 * 24
14
15
  def initialize(maxRetryTimes)
15
16
  @httpclient = JPush::NativeHttpClient.new(maxRetryTimes)
@@ -17,15 +18,28 @@ module JPush
17
18
 
18
19
  =begin
19
20
  @param payload is the instance of PushPayload
20
- @autoCode
21
21
  =end
22
- def sendPush(payload,autoCode)
22
+ def sendPush(payload)
23
23
  json_data = JSON.generate(payload.toJSON)
24
24
  result = JPush::PushResult.new
25
- wrapper = @httpclient.sendPost(@@PUSH_API_URL, json_data, autoCode)
25
+ wrapper = @httpclient.sendPost(@@PUSH_API_URL, json_data)
26
26
  result.fromResponse(wrapper)
27
27
  return result
28
28
  end
29
29
 
30
+ =begin
31
+ The API is used only to verify push call whether can succeed,
32
+ lies in the difference with the push of API: not to send any message to user.
33
+ @param payload is the instance of PushPayload
34
+ =end
35
+ def validate(payload)
36
+ json_data = JSON.generate(payload.toJSON)
37
+ result = JPush::PushResult.new
38
+ wrapper = @httpclient.sendPost(@@PUSH_API_URL + @@VALIDATE, json_data)
39
+ result.fromResponse(wrapper)
40
+ return result
41
+ end
42
+
43
+
30
44
  end
31
45
  end
@@ -14,23 +14,28 @@ module JPush
14
14
  end
15
15
 
16
16
 
17
- def getReceiveds(msg_ids, authcode)
17
+ def getReceiveds(msg_ids)
18
18
  msg_ids = checkMsgids(msg_ids)
19
19
  @url = @@REPORT_HOST_NAME + @@REPORT_RECEIVE_PATH + '?msg_ids=' + msg_ids
20
20
  result = JPush::ReceivedsResult.new
21
- wrapper = @httpclient.sendGet(@url, nil, authcode)
21
+ wrapper = @httpclient.sendGet(@url, nil)
22
22
  return result.fromResponse(wrapper)
23
23
  end
24
24
 
25
- def getMessages(msg_ids, authcode)
25
+ def getMessages(msg_ids)
26
26
  msg_ids = checkMsgids(msg_ids)
27
27
  @url = @@REPORT_HOST_NAME + @@REPORT_MESSAGE_PATH + '?msg_ids=' + msg_ids
28
- return @httpclient.sendGet(@url, nil, authcode)
28
+ result = JPush::GetMessagesResult.new
29
+ wrapper = @httpclient.sendGet(@url, nil)
30
+ return result.fromResponse(wrapper)
29
31
  end
30
32
 
31
- def getUsers(timeUnit, start, duration, authcode)
33
+ def getUsers(timeUnit, start, duration)
32
34
  @url = @@REPORT_HOST_NAME + @@REPORT_USER_PATH + '?time_unit=' + timeUnit + '&start=' + start + '&duration=' + duration.to_s
33
- return @httpclient.sendGet(@url, nil, authcode)
35
+ result = JPush::UserResult.new
36
+ puts @url
37
+ wrapper = @httpclient.sendGet(@url, nil)
38
+ return result.fromResponse(wrapper)
34
39
  end
35
40
 
36
41
  def checkMsgids(msg_ids)
@@ -31,6 +31,7 @@ module JPush
31
31
 
32
32
  def setErrorObject
33
33
  @error = JSON.parse @responseContent
34
+ @error = @error['error']
34
35
  end
35
36
  end
36
- end
37
+ end
@@ -4,7 +4,8 @@ class ServiceHelper
4
4
 
5
5
  def self.getAuthorizationBase64(appKey, masterSecret)
6
6
  encodeKey = appKey + ":" + masterSecret
7
- return @@BASIC_PREFIX + " " + Base64.strict_encode64(encodeKey)
8
-
7
+ value = @@BASIC_PREFIX + " " + Base64.encode64(encodeKey)
8
+ value.gsub!("\n", '')
9
+ return value
9
10
  end
10
11
  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: 3.1.1
4
+ version: 3.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - JPush Offical
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-11 00:00:00.000000000 Z
11
+ date: 2015-02-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -32,19 +32,15 @@ executables: []
32
32
  extensions: []
33
33
  extra_rdoc_files: []
34
34
  files:
35
- - ".gitignore"
36
- - ".project"
37
- - Gemfile
38
- - LICENSE.txt
39
- - README.md
40
- - Rakefile
41
- - example/push_example.rb
42
- - example/report_example.rb
43
- - jpush.gemspec
44
35
  - lib/jpush.rb
36
+ - lib/jpush/api_connection_exception.rb
37
+ - lib/jpush/device_client.rb
45
38
  - lib/jpush/http_client.rb
46
39
  - lib/jpush/jpush_client.rb
40
+ - lib/jpush/model/alias_uids_result.rb
47
41
  - lib/jpush/model/audience.rb
42
+ - lib/jpush/model/exist_result.rb
43
+ - lib/jpush/model/get_messages_result.rb
48
44
  - lib/jpush/model/message.rb
49
45
  - lib/jpush/model/messages_result.rb
50
46
  - lib/jpush/model/notification/android_notification.rb
@@ -56,17 +52,15 @@ files:
56
52
  - lib/jpush/model/push_payload.rb
57
53
  - lib/jpush/model/push_result.rb
58
54
  - lib/jpush/model/receiveds_result.rb
55
+ - lib/jpush/model/tag_alias.rb
56
+ - lib/jpush/model/tag_alias_result.rb
57
+ - lib/jpush/model/tag_list_result.rb
58
+ - lib/jpush/model/tag_manager.rb
59
+ - lib/jpush/model/user_result.rb
59
60
  - lib/jpush/push_client.rb
60
61
  - lib/jpush/report_client.rb
61
62
  - lib/jpush/response_wrapper.rb
62
63
  - lib/jpush/util/service_helper.rb
63
- - test/alert_override_tests.rb
64
- - test/audience_tests.rb
65
- - test/base_remote_tests.rb
66
- - test/message_tests.rb
67
- - test/notification_tests.rb
68
- - test/push_payload_test.rb
69
- - test/report_function_tests.rb
70
64
  homepage: https://github.com/jpush/jpush-api-ruby-client
71
65
  licenses:
72
66
  - GNU
@@ -91,11 +85,4 @@ rubygems_version: 2.2.2
91
85
  signing_key:
92
86
  specification_version: 4
93
87
  summary: JPush's officially supported Ruby client library for accessing JPush APIs.
94
- test_files:
95
- - test/alert_override_tests.rb
96
- - test/audience_tests.rb
97
- - test/base_remote_tests.rb
98
- - test/message_tests.rb
99
- - test/notification_tests.rb
100
- - test/push_payload_test.rb
101
- - test/report_function_tests.rb
88
+ test_files: []