igetui-ruby 1.1.0 → 1.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bead0733943449a4bbcd17ec0bda3707c5ba2c2d
4
- data.tar.gz: 949f835131885144e35c30a4721c424a4c4b57e5
3
+ metadata.gz: 3035d4d4c94322549376457acbe615abc7b67c98
4
+ data.tar.gz: 51e6782e963c61b1956fea8b1c46d5316c5872c9
5
5
  SHA512:
6
- metadata.gz: 591720b17a8d38540f8831faeeff83b4980873ac7b74c8373979cc2b52e6a64e9cf2929ef0e7de86c9a74df801df5d15a43be1319813cc3f6524cbdbeb951fb6
7
- data.tar.gz: a13b2d75cd7a6e8c34d4693cd89aa642e830101d3888a929c03e3c660d9a26cde50d7e65e2fa036abc0beef3358422adec60ef0b90e0cdbd1e41762af8298e5e
6
+ metadata.gz: 7df6aa78d90fa7a906a1e60ea0fa1914cbe8111059d275623cde13ca404a09687e387b4ccee3e9ca0a7f6e5583afc6d785fbab9314f7cf3d450cf24ba6d6b824
7
+ data.tar.gz: f82c3a064264ce66e33d52ba9d2720d0a1f28d3012d82bc5c478dc872aeaf21ae5efd9a57839d2ecdae631d91fdd385ad089ae47d098cbb9de9612331463b3ca
data/README.md CHANGED
@@ -108,7 +108,7 @@ require 'rubygems'
108
108
  require 'igetui'
109
109
 
110
110
  @pusher = IGeTui.pusher(your_app_id, your_app_key, your_master_secret)
111
- ret = @pusher.get_client_id_status(@cid_1)
111
+ ret = @pusher.get_client_id_status(your_client_id)
112
112
  p ret
113
113
  ```
114
114
 
data/lib/igetui.rb CHANGED
@@ -30,6 +30,7 @@ end
30
30
  require "igetui/version"
31
31
  require 'protobuf/GtReq.pb'
32
32
  require "igetui/template"
33
+ require "igetui/validate"
33
34
  require "igetui/message"
34
35
  require "igetui/pusher"
35
36
  require "igetui/client"
@@ -16,11 +16,11 @@ module IGeTui
16
16
  attr_accessor :app_id_list, :phone_type_list, :province_list, :tag_list
17
17
 
18
18
  def initialize
19
+ super
19
20
  @app_id_list = []
20
21
  @phone_type_list = []
21
22
  @province_list = []
22
23
  @tag_list = []
23
- super
24
24
  end
25
25
  end
26
26
  end
data/lib/igetui/pusher.rb CHANGED
@@ -14,7 +14,7 @@ module IGeTui
14
14
  data = {
15
15
  'action' => 'pushMessageToSingleAction',
16
16
  'appkey' => app_key,
17
- 'clientData' => base64Str(template),
17
+ 'clientData' => template.get_client_data(self),
18
18
  'transmissionContent' => template.transmission_content,
19
19
  'isOffline' => message.is_offline,
20
20
  'offlineExpireTime' => message.offline_expire_time,
@@ -50,7 +50,7 @@ module IGeTui
50
50
  data = {
51
51
  'action' => 'pushMessageToAppAction',
52
52
  'appkey' => app_key,
53
- 'clientData' => base64Str(template),
53
+ 'clientData' => template.get_client_data(self),
54
54
  'transmissionContent' => template.transmission_content,
55
55
  'isOffline' => message.is_offline,
56
56
  'offlineExpireTime' => message.offline_expire_time,
@@ -91,7 +91,7 @@ module IGeTui
91
91
  data = {
92
92
  'action' => 'getContentIdAction',
93
93
  'appkey' => app_key,
94
- 'clientData' => base64Str(template),
94
+ 'clientData' => template.get_client_data(self),
95
95
  'transmissionContent' => template.transmission_content,
96
96
  'isOffline' => message.is_offline,
97
97
  'offlineExpireTime' => message.offline_expire_time,
@@ -113,11 +113,6 @@ module IGeTui
113
113
 
114
114
  private
115
115
 
116
- def base64Str(template)
117
- string = template.get_transparent(self).serialize_to_string
118
- Base64.strict_encode64 string
119
- end
120
-
121
116
  def connect
122
117
  time_stamp = Time.now.to_i
123
118
  sign = Digest::MD5.hexdigest(app_key + time_stamp.to_s + master_secret)
@@ -1,9 +1,10 @@
1
1
  module IGeTui
2
2
  class BaseTemplate
3
- attr_accessor :transmission_type, :transmission_content
3
+ attr_accessor :transmission_type, :transmission_content, :push_info
4
4
 
5
5
  def initialize
6
- @push_info = nil
6
+ @transmission_type = 0
7
+ @transmission_content = ''
7
8
  end
8
9
 
9
10
  def get_transparent(pusher)
@@ -19,47 +20,49 @@ module IGeTui
19
20
  transparent
20
21
  end
21
22
 
22
- def get_action_chain; end
23
- def get_push_type; end
23
+ def get_action_chain
24
+ raise NotImplementedError, 'Must be implemented by subtypes.'
25
+ end
24
26
 
25
- def get_push_info
26
- unless @push_info
27
- @push_info = GtReq::PushInfo.new
28
- @push_info.actionKey = ''
29
- @push_info.badge = ''
30
- @push_info.message = ''
31
- @push_info.sound = ''
32
- end
33
- @push_info
27
+ def get_push_type
28
+ raise NotImplementedError, 'Must be implemented by subtypes.'
34
29
  end
35
30
 
36
- # Need TEST:
37
- # iOS Pusher need the top three fields of 'push_info' are required.
38
- # the others can be blank string.
39
- def set_push_info(action_loc_key, badge, message, sound, payload, loc_key, loc_args, launch_image)
31
+ def get_client_data(pusher)
32
+ string = self.get_transparent(pusher).serialize_to_string
33
+ Base64.strict_encode64 string
34
+ end
40
35
 
41
- @push_info = GtReq::PushInfo.new
36
+ def get_push_info
37
+ @push_info || init_push_info
38
+ end
39
+
40
+ # NOTE:
41
+ # iOS Pusher need the top four fields of 'push_info' are required.
42
+ # options can be includes [:payload, :loc_key, :loc_args, :launch_image]
43
+ # http://docs.igetui.com/pages/viewpage.action?pageId=590588
44
+ def set_push_info(action_loc_key, badge, message, sound, options = {})
45
+ init_push_info
42
46
  @push_info.actionLocKey = action_loc_key
43
- @push_info.badge = badge
47
+ @push_info.badge = badge.to_s
44
48
  @push_info.message = message
45
- @push_info.sound = sound if sound
46
- @push_info.payload = payload if payload
47
- @push_info.locKey = loc_key if loc_key
48
- @push_info.locArgs = loc_args if loc_args
49
- @push_info.launchImage = launch_image if launch_image
49
+ @push_info.sound = sound
50
+ @push_info.payload = options[:payload]
51
+ @push_info.locKey = options[:loc_key]
52
+ @push_info.locArgs = options[:loc_args]
53
+ @push_info.launchImage = options[:launch_image]
54
+ # validate method need refactoring.
55
+ # Validate.new.validate(args)
56
+ end
50
57
 
51
- args = {
52
- loc_key: loc_key,
53
- loc_args: locArgs,
54
- message: message,
55
- action_loc_key: action_loc_key,
56
- launch_image: launch_image,
57
- badge: badge,
58
- sound: sound,
59
- payload: payload
60
- }
58
+ private
61
59
 
62
- Validate.new.validate(args)
60
+ def init_push_info
61
+ @push_info = GtReq::PushInfo.new
62
+ @push_info.message = ''
63
+ @push_info.actionKey = ''
64
+ @push_info.sound = ''
65
+ @push_info.badge = ''
63
66
  @push_info
64
67
  end
65
68
 
@@ -1,19 +1,15 @@
1
1
  module IGeTui
2
2
  class LinkTemplate < BaseTemplate
3
- attr_accessor :title, :text, :logo, :logo_url, :url
4
- attr_accessor :is_ring, :is_vibrate, :is_clearable
3
+ STRING_ATTRIBUTES = %i(title text logo logo_url url).freeze
4
+ BOOLEAN_ATTRIBUTES = %i(is_ring is_vibrate is_clearable).freeze
5
+
6
+ attr_accessor *STRING_ATTRIBUTES, *BOOLEAN_ATTRIBUTES
5
7
 
6
8
  def initialize
7
- @title = ''
8
- @text = ''
9
- @logo = ''
10
- @logo_url = ''
11
- @transmission_type = 0
12
- @transmission_content = ''
13
- @is_ring = true
14
- @is_vibrate = true
15
- @is_clearable = true
16
9
  super
10
+
11
+ STRING_ATTRIBUTES.each { |attr| instance_variable_set("@#{attr}", '') }
12
+ BOOLEAN_ATTRIBUTES.each { |attr| instance_variable_set("@#{attr}", true) }
17
13
  end
18
14
 
19
15
  def get_action_chain
@@ -1,19 +1,15 @@
1
1
  module IGeTui
2
2
  class NotificationTemplate < BaseTemplate
3
- attr_accessor :title, :text, :logo, :logo_url
4
- attr_accessor :is_ring, :is_vibrate, :is_clearable
3
+ STRING_ATTRIBUTES = %i(title text logo logo_url).freeze
4
+ BOOLEAN_ATTRIBUTES = %i(is_ring is_vibrate is_clearable).freeze
5
+
6
+ attr_accessor *STRING_ATTRIBUTES, *BOOLEAN_ATTRIBUTES
5
7
 
6
8
  def initialize
7
- @title = ''
8
- @text = ''
9
- @logo = ''
10
- @logo_url = ''
11
- @transmission_type = 0
12
- @transmission_content = ''
13
- @is_ring = true
14
- @is_vibrate = true
15
- @is_clearable = true
16
9
  super
10
+
11
+ STRING_ATTRIBUTES.each { |attr| instance_variable_set("@#{attr}", '') }
12
+ BOOLEAN_ATTRIBUTES.each { |attr| instance_variable_set("@#{attr}", true) }
17
13
  end
18
14
 
19
15
  def get_action_chain
@@ -1,37 +1,23 @@
1
1
  module IGeTui
2
2
  class NotyPopLoadTemplate < BaseTemplate
3
- attr_accessor :title, :text, :logo, :logo_url
4
- attr_accessor :is_ring, :is_vibrate, :is_clearable
5
- attr_accessor :pop_title, :pop_text, :pop_image
6
- attr_accessor :pop_button_1, :pop_button_2
7
- attr_accessor :load_icon, :load_title, :load_url
8
- attr_accessor :android_mask, :symbia_mask, :ios_mask
9
- attr_accessor :is_auto_install, :is_active
3
+ STRING_ATTRIBUTES = %i(
4
+ title text logo logo_url
5
+ pop_title pop_text pop_image
6
+ pop_button_1 pop_button_2
7
+ load_icon load_title load_url
8
+ android_mask symbia_mask ios_mask
9
+ ).freeze
10
+ BOOLEAN_ATTRIBUTES_OF_TRUE = %i(is_ring is_vibrate is_clearable).freeze
11
+ BOOLEAN_ATTRIBUTES_OF_FALSE = %i(is_auto_install is_active).freeze
12
+
13
+ attr_accessor *STRING_ATTRIBUTES, *BOOLEAN_ATTRIBUTES_OF_TRUE, *BOOLEAN_ATTRIBUTES_OF_FALSE
10
14
 
11
15
  def initialize
12
- @title = ''
13
- @text = ''
14
- @logo = ''
15
- @logo_url = ''
16
- @pop_title = ''
17
- @pop_text = ''
18
- @pop_image = ''
19
- @pop_button_1 = ''
20
- @pop_button_2 = ''
21
- @load_icon = ''
22
- @load_title = ''
23
- @load_url = ''
24
- @transmission_type = 0
25
- @transmission_content = ''
26
- @is_ring = true
27
- @is_vibrate = true
28
- @is_clearable = true
29
- @android_mask = ''
30
- @symbia_mask = ''
31
- @ios_mask = ''
32
- @is_auto_install = false
33
- @is_active = false
34
16
  super
17
+
18
+ STRING_ATTRIBUTES.each { |attr| instance_variable_set("@#{attr}", '') }
19
+ BOOLEAN_ATTRIBUTES_OF_TRUE.each { |attr| instance_variable_set("@#{attr}", true) }
20
+ BOOLEAN_ATTRIBUTES_OF_FALSE.each { |attr| instance_variable_set("@#{attr}", false) }
35
21
  end
36
22
 
37
23
  def get_action_chain
@@ -1,8 +1,6 @@
1
1
  module IGeTui
2
2
  class TransmissionTemplate < BaseTemplate
3
3
  def initialize
4
- @transmission_type = 0
5
- @transmission_content = ''
6
4
  super
7
5
  end
8
6
 
@@ -1,13 +1,82 @@
1
- require 'json'
2
1
  module IGeTui
3
2
  class Validate
4
3
  def validate(args = {})
5
- payload_map = get_payload(args)
4
+ # payload_map = get_payload(args)
6
5
 
7
- json = JSON.generate payload_map
8
- if (json.length > 256)
9
- raise ArgumentError.new("PushInfo length over limit: #{json.length}. Allowed: 256.")
6
+ # json = JSON.generate payload_map
7
+ # if (json.length > 256)
8
+ # raise ArgumentError.new("PushInfo length over limit: #{json.length}. Allowed: 256.")
9
+ # end
10
+
11
+ is_validate = validate_payload(args)
12
+ unless is_validate
13
+ payload_len = validate_payload_length(args)
14
+ raise ArgumentError.new("PushInfo length over limit: #{payload_len.length}. Allowed: 256.")
15
+ end
16
+ end
17
+
18
+ def validate_payload(args)
19
+ length = validate_payload_length(args)
20
+ length <= 256
21
+ end
22
+
23
+ def validate_payload_length(args)
24
+ json = process_payload(args)
25
+ json.length
26
+ end
27
+
28
+ def process_payload(args)
29
+ is_valid = false
30
+ pb = Payload.new
31
+ if !args[:loc_key].nil? && args[:loc_key].length > 0
32
+ pb.alert_loc_key = args[:loc_key]
33
+ if !args[:loc_args].nil? && args[:loc_args].length > 0
34
+ pb.alert_loc_args = args[:loc_args].split(",")
35
+ end
36
+ is_valid = true
37
+ end
38
+
39
+ if !args[:message].nil? && args[:message].length > 0
40
+ pb.alert_body = args[:message]
41
+ is_valid = true
42
+ end
43
+
44
+ if !args[:action_loc_key].nil? && args[:action_loc_key].length > 0
45
+ pb.alert_action_loc_key = args[:action_loc_key]
46
+ end
47
+
48
+ if !args[:launch_image].nil? && args[:launch_image].length > 0
49
+ pb.alert_launch_image = args[:launch_image]
10
50
  end
51
+
52
+ badge_num = args[:badge].to_i
53
+
54
+ if badge_num >= 0
55
+ pb.badge = badge_num
56
+ is_valid = true
57
+ end
58
+
59
+ if !args[:sound].nil? && args[:sound].length > 0
60
+ pb.sound = args[:sound]
61
+ end
62
+
63
+ if !args[:payload].nil? && args[:payload].length > 0
64
+ pb.add_param("payload", payload)
65
+ end
66
+
67
+ unless is_valid
68
+ puts "one of the params(locKey,message,badge) must not be null"
69
+ end
70
+
71
+ json = pb.to_s
72
+
73
+ if json.nil?
74
+ puts "payload json is null"
75
+ end
76
+
77
+ json
78
+
79
+ # do something
11
80
  end
12
81
 
13
82
  def get_payload(args = {})
@@ -26,8 +95,8 @@ module IGeTui
26
95
  if validate_length(args, :loc_args)
27
96
  alertMap["loc-args"] = args[:loc_args].split(", ")
28
97
  end
29
- elsif validate_length(nil, message)
30
- alertMap["body"] = message
98
+ elsif validate_length(nil, args[:message])
99
+ alertMap["body"] = args[:message]
31
100
  end
32
101
 
33
102
  apnsMap["alert"] = alertMap
@@ -35,11 +104,11 @@ module IGeTui
35
104
  apnsMap["action-loc-key"] = args[:action_loc_key]
36
105
  end
37
106
 
38
- apnsMap["badge"] = badge
107
+ apnsMap["badge"] = args[:badge]
39
108
 
40
109
  h = Hash.new
41
110
  h["aps"] = apnsMap
42
- h["payload"] = payload if validate_length(nil, payload)
111
+ h["payload"] = args[:payload] if validate_length(nil, args[:payload])
43
112
 
44
113
  return h
45
114
  end
@@ -1,3 +1,3 @@
1
1
  module IGeTui
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.0"
3
3
  end
data/test/pusher_test.rb CHANGED
@@ -81,12 +81,14 @@ class PusherTest < MiniTest::Unit::TestCase
81
81
  template = IGeTui::LinkTemplate.new
82
82
  set_template_base_info(template)
83
83
  template.url = "http://www.baidu.com"
84
+ template.set_push_info("open", 4, "message", "")
84
85
  template
85
86
  end
86
87
 
87
88
  def notification_template
88
89
  template = IGeTui::NotificationTemplate.new
89
90
  set_template_base_info(template)
91
+ template.set_push_info("open", 4, "message", "")
90
92
  template
91
93
  end
92
94
 
@@ -94,14 +96,17 @@ class PusherTest < MiniTest::Unit::TestCase
94
96
  template = IGeTui::TransmissionTemplate.new
95
97
  # Notice: content should be string.
96
98
  content = {
97
- action: "notification",
98
- title: "标题aaa",
99
- content: "内容",
100
- type: "article",
101
- id: "4274"
99
+ "action" => "notification",
100
+ "title" => "标题aaa",
101
+ "content" => "内容",
102
+ "type" => "Article",
103
+ "id" => "1234"
102
104
  }
105
+
103
106
  content = content.to_s.gsub(":", "").gsub("=>", ":")
104
107
  template.transmission_content = content
108
+ puts template.transmission_content
109
+ template.set_push_info("test", 1, "test1", "")
105
110
  template
106
111
  end
107
112
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: igetui-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Victor Wang
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-19 00:00:00.000000000 Z
11
+ date: 2014-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json