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 +4 -4
- data/README.md +1 -1
- data/lib/igetui.rb +1 -0
- data/lib/igetui/message.rb +1 -1
- data/lib/igetui/pusher.rb +3 -8
- data/lib/igetui/template/base_template.rb +38 -35
- data/lib/igetui/template/link_template.rb +7 -11
- data/lib/igetui/template/notification_template.rb +7 -11
- data/lib/igetui/template/noty_pop_load_template.rb +15 -29
- data/lib/igetui/template/transmission_template.rb +0 -2
- data/lib/igetui/validate.rb +78 -9
- data/lib/igetui/version.rb +1 -1
- data/test/pusher_test.rb +10 -5
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3035d4d4c94322549376457acbe615abc7b67c98
|
|
4
|
+
data.tar.gz: 51e6782e963c61b1956fea8b1c46d5316c5872c9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7df6aa78d90fa7a906a1e60ea0fa1914cbe8111059d275623cde13ca404a09687e387b4ccee3e9ca0a7f6e5583afc6d785fbab9314f7cf3d450cf24ba6d6b824
|
|
7
|
+
data.tar.gz: f82c3a064264ce66e33d52ba9d2720d0a1f28d3012d82bc5c478dc872aeaf21ae5efd9a57839d2ecdae631d91fdd385ad089ae47d098cbb9de9612331463b3ca
|
data/README.md
CHANGED
data/lib/igetui.rb
CHANGED
data/lib/igetui/message.rb
CHANGED
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' =>
|
|
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' =>
|
|
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' =>
|
|
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
|
-
@
|
|
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
|
|
23
|
-
|
|
23
|
+
def get_action_chain
|
|
24
|
+
raise NotImplementedError, 'Must be implemented by subtypes.'
|
|
25
|
+
end
|
|
24
26
|
|
|
25
|
-
def
|
|
26
|
-
|
|
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
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
-
|
|
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
|
|
46
|
-
@push_info.payload = payload
|
|
47
|
-
@push_info.locKey = loc_key
|
|
48
|
-
@push_info.locArgs = loc_args
|
|
49
|
-
@push_info.launchImage = 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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
4
|
-
|
|
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
|
-
|
|
4
|
-
|
|
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
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
data/lib/igetui/validate.rb
CHANGED
|
@@ -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
|
-
|
|
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
|
data/lib/igetui/version.rb
CHANGED
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
|
|
98
|
-
title
|
|
99
|
-
content
|
|
100
|
-
type
|
|
101
|
-
id
|
|
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.
|
|
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-
|
|
11
|
+
date: 2014-09-03 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: json
|