igetui-ruby-nolock 1.2.2
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 +46 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/LICENSE.txt +22 -0
- data/README.md +136 -0
- data/Rakefile +6 -0
- data/igetui-ruby.gemspec +23 -0
- data/lib/igetui/client.rb +9 -0
- data/lib/igetui/message.rb +26 -0
- data/lib/igetui/pusher.rb +163 -0
- data/lib/igetui/template/base_template.rb +70 -0
- data/lib/igetui/template/link_template.rb +60 -0
- data/lib/igetui/template/notification_template.rb +66 -0
- data/lib/igetui/template/noty_pop_load_template.rb +90 -0
- data/lib/igetui/template/transmission_template.rb +40 -0
- data/lib/igetui/template.rb +5 -0
- data/lib/igetui/validate.rb +126 -0
- data/lib/igetui/version.rb +3 -0
- data/lib/igetui.rb +36 -0
- data/lib/igetui_ruby.rb +1 -0
- data/lib/protobuf/GtReq.pb.rb +399 -0
- data/test/pusher_test.rb +128 -0
- metadata +68 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 438de2034bbfccc1e7df723a33ba0b9e14c522f8
|
4
|
+
data.tar.gz: 20b624128b9effb9546e1434883b73223ac216f3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b39d77f5891a796412386209d559441b12d168a230b943c4e886426f7aaf4d679fbcdde207f2cb2296945609954adcf72d1d04453aa663bddaa24c533452d355
|
7
|
+
data.tar.gz: 9821d6b37970f1507e5b9ab7684c0249c5fd68fd8d1d68dbe3e941265a107b182631e12608f2264a523315c31ad2f0ba625b5461cdf51df11016ccdc89be5769
|
data/.gitignore
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
.DS_Store
|
2
|
+
.rvmrc
|
3
|
+
*.gem
|
4
|
+
*.rbc
|
5
|
+
.bundle
|
6
|
+
.config
|
7
|
+
.yardoc
|
8
|
+
Gemfile.lock
|
9
|
+
InstalledFiles
|
10
|
+
_yardoc
|
11
|
+
coverage
|
12
|
+
doc/
|
13
|
+
lib/bundler/man
|
14
|
+
pkg
|
15
|
+
rdoc
|
16
|
+
spec/reports
|
17
|
+
test/tmp
|
18
|
+
test/version_tmp
|
19
|
+
tmp
|
20
|
+
spec/public
|
21
|
+
spec/test.log
|
22
|
+
spec/tmp
|
23
|
+
|
24
|
+
## Specific to RubyMotion:
|
25
|
+
.dat*
|
26
|
+
.repl_history
|
27
|
+
build/
|
28
|
+
|
29
|
+
## Documentation cache and generated files:
|
30
|
+
/.yardoc/
|
31
|
+
/_yardoc/
|
32
|
+
/doc/
|
33
|
+
/rdoc/
|
34
|
+
|
35
|
+
## Environment normalisation:
|
36
|
+
/.bundle/
|
37
|
+
/lib/bundler/man/
|
38
|
+
|
39
|
+
# for a library or gem, you might want to ignore these files since the code is
|
40
|
+
# intended to run in multiple environments; otherwise, check them in:
|
41
|
+
# Gemfile.lock
|
42
|
+
.ruby-version
|
43
|
+
.ruby-gemset
|
44
|
+
|
45
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
46
|
+
.rvmrc
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Victor Wang
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Victor Wang
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
# IGeTui::Ruby
|
2
|
+
|
3
|
+
[个推](http://www.igetui.com/)服务端 ruby-sdk
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'igetui-ruby', require: 'igetui'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
```bash
|
16
|
+
$ bundle
|
17
|
+
```
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
```bash
|
22
|
+
$ gem install igetui-ruby
|
23
|
+
```
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
### Push Message To Single
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
pusher = IGeTui.pusher(your_app_id, your_app_key, your_master_secret)
|
31
|
+
|
32
|
+
# 创建通知模板
|
33
|
+
template = IGeTui::NotificationTemplate.new
|
34
|
+
template.logo = 'push.png'
|
35
|
+
template.logo_url = 'http://www.igetui.com/wp-content/uploads/2013/08/logo_getui1.png'
|
36
|
+
template.title = '测试标题'
|
37
|
+
template.text = '测试文本'
|
38
|
+
|
39
|
+
# 创建单体消息
|
40
|
+
single_message = IGeTui::SingleMessage.new
|
41
|
+
single_message.data = template
|
42
|
+
|
43
|
+
# 创建客户端对象
|
44
|
+
client = IGeTui::Client.new(your_client_id)
|
45
|
+
|
46
|
+
# 发送一条通知到指定的客户端
|
47
|
+
ret = pusher.push_message_to_single(single_message, client)
|
48
|
+
p ret
|
49
|
+
```
|
50
|
+
|
51
|
+
### Push Message To List
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
pusher = IGeTui.pusher(your_app_id, your_app_key, your_master_secret)
|
55
|
+
|
56
|
+
# 创建一条透传消息
|
57
|
+
template = IGeTui::TransmissionTemplate.new
|
58
|
+
# Notice: content should be string.
|
59
|
+
content = {
|
60
|
+
action: "notification",
|
61
|
+
title: "标题aaa",
|
62
|
+
content: "内容",
|
63
|
+
type: "article",
|
64
|
+
id: "4274"
|
65
|
+
}
|
66
|
+
content = content.to_s.gsub(":", "").gsub("=>", ":")
|
67
|
+
template.transmission_content = content
|
68
|
+
# 设置iOS的推送参数,如果只有安卓 App,可以忽略下面一行
|
69
|
+
# template.set_push_info("", 1, "这里是iOS推送的显示信息", "")
|
70
|
+
|
71
|
+
# 创建群发消息
|
72
|
+
list_message = IGeTui::ListMessage.new
|
73
|
+
list_message.data = template
|
74
|
+
|
75
|
+
# 创建客户端对象
|
76
|
+
client_1 = IGeTui::Client.new(your_client_id_1)
|
77
|
+
client_2 = IGeTui::Client.new(your_client_id_2)
|
78
|
+
client_list = [client_1, client_2]
|
79
|
+
|
80
|
+
content_id = pusher.get_content_id(list_message)
|
81
|
+
ret = pusher.push_message_to_list(content_id, client_list)
|
82
|
+
```
|
83
|
+
|
84
|
+
### Push Message To App
|
85
|
+
|
86
|
+
```ruby
|
87
|
+
pusher = IGeTui.pusher(your_app_id, your_app_key, your_master_secret)
|
88
|
+
|
89
|
+
# 创建通知模板
|
90
|
+
template = IGeTui::NotificationTemplate.new
|
91
|
+
template.logo = 'push.png'
|
92
|
+
template.logo_url = 'http://www.igetui.com/wp-content/uploads/2013/08/logo_getui1.png'
|
93
|
+
template.title = '测试标题'
|
94
|
+
template.text = '测试文本'
|
95
|
+
|
96
|
+
# 创建APP群发消息
|
97
|
+
app_message = IGeTui::AppMessage.new
|
98
|
+
app_message.data = template
|
99
|
+
app_message.app_id_list = [your_app_id]
|
100
|
+
|
101
|
+
# 发送一条通知到程序
|
102
|
+
ret = pusher.push_message_to_app(app_message)
|
103
|
+
p ret
|
104
|
+
```
|
105
|
+
|
106
|
+
### Custom Test
|
107
|
+
|
108
|
+
```ruby
|
109
|
+
require 'rubygems'
|
110
|
+
require 'igetui'
|
111
|
+
|
112
|
+
@pusher = IGeTui.pusher(your_app_id, your_app_key, your_master_secret)
|
113
|
+
ret = @pusher.get_client_id_status(your_client_id)
|
114
|
+
p ret
|
115
|
+
```
|
116
|
+
|
117
|
+
### Auto Test
|
118
|
+
|
119
|
+
运行测试之前,请先修改 test/pusher_test.rb 中的相关配置。
|
120
|
+
|
121
|
+
```ruby
|
122
|
+
rake test
|
123
|
+
```
|
124
|
+
|
125
|
+
## Documents
|
126
|
+
|
127
|
+
* [参数说明](https://github.com/wjp2013/igetui-ruby/wiki/%E5%8F%82%E6%95%B0%E8%AF%B4%E6%98%8E)
|
128
|
+
* [模板类型说明](https://github.com/wjp2013/igetui-ruby/wiki/%E6%A8%A1%E6%9D%BF%E7%B1%BB%E5%9E%8B%E8%AF%B4%E6%98%8E)
|
129
|
+
|
130
|
+
## Contributing
|
131
|
+
|
132
|
+
1. Fork it ( http://github.com/wjp2013/igetui-ruby/fork )
|
133
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
134
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
135
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
136
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/igetui-ruby.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
require 'igetui/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = "igetui-ruby-nolock"
|
9
|
+
spec.version = IGeTui::VERSION
|
10
|
+
spec.authors = ["yone hsiung"]
|
11
|
+
spec.email = ["QQ: 171842474"]
|
12
|
+
spec.summary = "igetui.com ruby sdk"
|
13
|
+
spec.description = "ruby-sdk of igetui.com push notification service"
|
14
|
+
spec.homepage = "https://github.com/YoneHsiung/igetui-ruby.git"
|
15
|
+
spec.license = "MIT"
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
spec.extra_rdoc_files = ["README.md"]
|
21
|
+
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module IGeTui
|
2
|
+
class Message
|
3
|
+
attr_accessor :is_offline, :offline_expire_time, :data
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@is_offline = true
|
7
|
+
@offline_expire_time = 1000 * 3600 * 12
|
8
|
+
@data = BaseTemplate.new
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
SingleMessage = Class.new(Message)
|
13
|
+
ListMessage = Class.new(Message)
|
14
|
+
|
15
|
+
class AppMessage < Message
|
16
|
+
attr_accessor :app_id_list, :phone_type_list, :province_list, :tag_list
|
17
|
+
|
18
|
+
def initialize
|
19
|
+
super
|
20
|
+
@app_id_list = []
|
21
|
+
@phone_type_list = []
|
22
|
+
@province_list = []
|
23
|
+
@tag_list = []
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,163 @@
|
|
1
|
+
module IGeTui
|
2
|
+
class Pusher
|
3
|
+
attr_reader :host, :app_id, :app_key, :master_secret
|
4
|
+
|
5
|
+
def initialize(host, app_id, app_key, master_secret)
|
6
|
+
@host = host
|
7
|
+
@app_id = app_id
|
8
|
+
@app_key = app_key
|
9
|
+
@master_secret = master_secret
|
10
|
+
end
|
11
|
+
|
12
|
+
def push_message_to_single(message, client)
|
13
|
+
template = message.data
|
14
|
+
data = {
|
15
|
+
'action' => 'pushMessageToSingleAction',
|
16
|
+
'appkey' => app_key,
|
17
|
+
'clientData' => template.get_client_data(self),
|
18
|
+
'transmissionContent' => template.transmission_content,
|
19
|
+
'isOffline' => message.is_offline,
|
20
|
+
'offlineExpireTime' => message.offline_expire_time,
|
21
|
+
'appId' => app_id,
|
22
|
+
'clientId' => client.client_id,
|
23
|
+
'type' => 2, #default is message
|
24
|
+
'pushType' => template.get_push_type
|
25
|
+
}
|
26
|
+
|
27
|
+
http_post_json(data)
|
28
|
+
end
|
29
|
+
|
30
|
+
def push_message_to_list(content_id, clients)
|
31
|
+
target_list = clients.inject([]) do |list, cilent|
|
32
|
+
list << { 'appId' => app_id, 'clientId' => cilent.client_id }
|
33
|
+
end
|
34
|
+
|
35
|
+
# seems that we miss 'pushType'
|
36
|
+
data = {
|
37
|
+
'action' => 'pushMessageToListAction',
|
38
|
+
'appkey' => app_key,
|
39
|
+
'contentId' => content_id,
|
40
|
+
'needDetails' => true,
|
41
|
+
'targetList' => target_list,
|
42
|
+
'type' => 2
|
43
|
+
}
|
44
|
+
|
45
|
+
http_post_json(data)
|
46
|
+
end
|
47
|
+
|
48
|
+
def push_message_to_app(message)
|
49
|
+
template = message.data
|
50
|
+
data = {
|
51
|
+
'action' => 'pushMessageToAppAction',
|
52
|
+
'appkey' => app_key,
|
53
|
+
'clientData' => template.get_client_data(self),
|
54
|
+
'transmissionContent' => template.transmission_content,
|
55
|
+
'isOffline' => message.is_offline,
|
56
|
+
'offlineExpireTime' => message.offline_expire_time,
|
57
|
+
'appIdList' => message.app_id_list,
|
58
|
+
'phoneTypeList' => message.phone_type_list,
|
59
|
+
'provinceList' => message.province_list,
|
60
|
+
'tagList' => message.tag_list,
|
61
|
+
'type' => 2,
|
62
|
+
'pushType' => template.get_push_type
|
63
|
+
}
|
64
|
+
http_post_json(data)
|
65
|
+
end
|
66
|
+
|
67
|
+
def stop(content_id)
|
68
|
+
data = {
|
69
|
+
'action' => 'stopTaskAction',
|
70
|
+
'appkey' => @appKey,
|
71
|
+
'contentId' => content_id
|
72
|
+
}
|
73
|
+
|
74
|
+
ret = http_post_json(data)
|
75
|
+
ret['result'] == 'ok'
|
76
|
+
end
|
77
|
+
|
78
|
+
def get_client_id_status(client_id)
|
79
|
+
data = {
|
80
|
+
'action' => 'getClientIdStatusAction',
|
81
|
+
'appkey' => app_key,
|
82
|
+
'appId' => app_id,
|
83
|
+
'clientId' => client_id
|
84
|
+
}
|
85
|
+
http_post_json(data)
|
86
|
+
end
|
87
|
+
|
88
|
+
|
89
|
+
def get_content_id(message)
|
90
|
+
template = message.data
|
91
|
+
data = {
|
92
|
+
'action' => 'getContentIdAction',
|
93
|
+
'appkey' => app_key,
|
94
|
+
'clientData' => template.get_client_data(self),
|
95
|
+
'transmissionContent' => template.transmission_content,
|
96
|
+
'isOffline' => message.is_offline,
|
97
|
+
'offlineExpireTime' => message.offline_expire_time,
|
98
|
+
'pushType' => template.get_push_type
|
99
|
+
}
|
100
|
+
ret = http_post_json(data)
|
101
|
+
ret['result'] == 'ok' ? ret['contentId'] : ''
|
102
|
+
end
|
103
|
+
|
104
|
+
def cancel_content_id(content_id)
|
105
|
+
data = {
|
106
|
+
'action' => 'cancleContentIdAction',
|
107
|
+
'contentId' => content_id,
|
108
|
+
}
|
109
|
+
ret = http_post_json(data)
|
110
|
+
ret['result'] == 'ok'
|
111
|
+
end
|
112
|
+
|
113
|
+
|
114
|
+
private
|
115
|
+
|
116
|
+
def connect
|
117
|
+
time_stamp = Time.now.to_i
|
118
|
+
sign = Digest::MD5.hexdigest(app_key + time_stamp.to_s + master_secret)
|
119
|
+
data = {
|
120
|
+
action: 'connect',
|
121
|
+
appkey: app_key,
|
122
|
+
timeStamp: time_stamp,
|
123
|
+
sign: sign
|
124
|
+
}
|
125
|
+
ret = http_post(data)
|
126
|
+
ret['result'] == 'success'
|
127
|
+
end
|
128
|
+
|
129
|
+
def http_post_json(params)
|
130
|
+
params['version'] = '3.0.0.0'
|
131
|
+
ret = http_post(params)
|
132
|
+
|
133
|
+
if ret && ret['result'] == 'sign_error'
|
134
|
+
connect
|
135
|
+
ret = http_post(params)
|
136
|
+
end
|
137
|
+
ret
|
138
|
+
end
|
139
|
+
|
140
|
+
def http_post(params)
|
141
|
+
params['version'] = '3.0.0.0'
|
142
|
+
data = params.to_json
|
143
|
+
|
144
|
+
url = URI.parse(host)
|
145
|
+
req = Net::HTTP::Post.new(url.path, initheader = { 'Content-Type' => 'application/json' })
|
146
|
+
req.body = data
|
147
|
+
|
148
|
+
try_time = 0
|
149
|
+
begin
|
150
|
+
res = Net::HTTP.new(url.host, url.port).start { |http| http.request(req) }
|
151
|
+
rescue => e
|
152
|
+
try_time += 1
|
153
|
+
if try_time >= 3
|
154
|
+
raise e
|
155
|
+
else
|
156
|
+
retry
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
JSON.parse res.body
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
module IGeTui
|
2
|
+
class BaseTemplate
|
3
|
+
attr_accessor :transmission_type, :transmission_content, :push_info
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@transmission_type = 0
|
7
|
+
@transmission_content = ''
|
8
|
+
end
|
9
|
+
|
10
|
+
def get_transparent(pusher)
|
11
|
+
transparent = GtReq::Transparent.new
|
12
|
+
transparent.id = ''
|
13
|
+
transparent.messageId = ''
|
14
|
+
transparent.taskId = ''
|
15
|
+
transparent.action = 'pushmessage'
|
16
|
+
transparent.actionChain = get_action_chain
|
17
|
+
transparent.pushInfo = get_push_info
|
18
|
+
transparent.appId = pusher.app_id
|
19
|
+
transparent.appKey = pusher.app_key
|
20
|
+
transparent
|
21
|
+
end
|
22
|
+
|
23
|
+
def get_action_chain
|
24
|
+
raise NotImplementedError, 'Must be implemented by subtypes.'
|
25
|
+
end
|
26
|
+
|
27
|
+
def get_push_type
|
28
|
+
raise NotImplementedError, 'Must be implemented by subtypes.'
|
29
|
+
end
|
30
|
+
|
31
|
+
def get_client_data(pusher)
|
32
|
+
string = self.get_transparent(pusher).serialize_to_string
|
33
|
+
Base64.strict_encode64 string
|
34
|
+
end
|
35
|
+
|
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
|
46
|
+
@push_info.actionLocKey = action_loc_key
|
47
|
+
@push_info.badge = badge.to_s
|
48
|
+
@push_info.message = message
|
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
|
57
|
+
|
58
|
+
private
|
59
|
+
|
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 = '-1'
|
66
|
+
@push_info
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module IGeTui
|
2
|
+
class LinkTemplate < BaseTemplate
|
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
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
super
|
10
|
+
|
11
|
+
STRING_ATTRIBUTES.each { |attr| instance_variable_set("@#{attr}", '') }
|
12
|
+
BOOLEAN_ATTRIBUTES.each { |attr| instance_variable_set("@#{attr}", true) }
|
13
|
+
end
|
14
|
+
|
15
|
+
def get_action_chain
|
16
|
+
# set actionchain
|
17
|
+
action_chain_1 = GtReq::ActionChain.new
|
18
|
+
action_chain_1.actionId = 1
|
19
|
+
action_chain_1.type = GtReq::ActionChain::Type::Goto
|
20
|
+
action_chain_1.next = 10000
|
21
|
+
|
22
|
+
# notification
|
23
|
+
action_chain_2 = GtReq::ActionChain.new
|
24
|
+
action_chain_2.actionId = 10000
|
25
|
+
action_chain_2.type = GtReq::ActionChain::Type::Notification
|
26
|
+
action_chain_2.title = title
|
27
|
+
action_chain_2.text = text
|
28
|
+
action_chain_2.logo = logo
|
29
|
+
action_chain_2.logoURL = logo_url
|
30
|
+
action_chain_2.ring = is_ring
|
31
|
+
action_chain_2.clearable = is_clearable
|
32
|
+
action_chain_2.buzz = is_vibrate
|
33
|
+
action_chain_2.next = 10010
|
34
|
+
|
35
|
+
# goto
|
36
|
+
action_chain_3 = GtReq::ActionChain.new
|
37
|
+
action_chain_3.actionId = 10010
|
38
|
+
action_chain_3.type = GtReq::ActionChain::Type::Goto
|
39
|
+
action_chain_3.next = 10030
|
40
|
+
|
41
|
+
# start web
|
42
|
+
action_chain_4 = GtReq::ActionChain.new
|
43
|
+
action_chain_4.actionId = 10030
|
44
|
+
action_chain_4.type = GtReq::ActionChain::Type::Startweb
|
45
|
+
action_chain_4.url = url
|
46
|
+
action_chain_4.next = 100
|
47
|
+
|
48
|
+
# end
|
49
|
+
action_chain_5 = GtReq::ActionChain.new
|
50
|
+
action_chain_5.actionId = 100
|
51
|
+
action_chain_5.type = GtReq::ActionChain::Type::Eoa
|
52
|
+
|
53
|
+
[action_chain_1, action_chain_2, action_chain_3, action_chain_4, action_chain_5]
|
54
|
+
end
|
55
|
+
|
56
|
+
def get_push_type
|
57
|
+
"NotifyMsg"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module IGeTui
|
2
|
+
class NotificationTemplate < BaseTemplate
|
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
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
super
|
10
|
+
|
11
|
+
STRING_ATTRIBUTES.each { |attr| instance_variable_set("@#{attr}", '') }
|
12
|
+
BOOLEAN_ATTRIBUTES.each { |attr| instance_variable_set("@#{attr}", true) }
|
13
|
+
end
|
14
|
+
|
15
|
+
def get_action_chain
|
16
|
+
# set actionchain
|
17
|
+
action_chain_1 = GtReq::ActionChain.new
|
18
|
+
action_chain_1.actionId = 1
|
19
|
+
action_chain_1.type = GtReq::ActionChain::Type::Goto
|
20
|
+
action_chain_1.next = 10000
|
21
|
+
|
22
|
+
# notification
|
23
|
+
action_chain_2 = GtReq::ActionChain.new
|
24
|
+
action_chain_2.actionId = 10000
|
25
|
+
action_chain_2.type = GtReq::ActionChain::Type::Notification
|
26
|
+
action_chain_2.title = title
|
27
|
+
action_chain_2.text = text
|
28
|
+
action_chain_2.logo = logo
|
29
|
+
action_chain_2.logoURL = logo_url
|
30
|
+
action_chain_2.ring = is_ring
|
31
|
+
action_chain_2.clearable = is_clearable
|
32
|
+
action_chain_2.buzz = is_vibrate
|
33
|
+
action_chain_2.next = 10010
|
34
|
+
|
35
|
+
# goto
|
36
|
+
action_chain_3 = GtReq::ActionChain.new
|
37
|
+
action_chain_3.actionId = 10010
|
38
|
+
action_chain_3.type = GtReq::ActionChain::Type::Goto
|
39
|
+
action_chain_3.next = 10030
|
40
|
+
|
41
|
+
# appStartUp
|
42
|
+
app_start_up = GtReq::AppStartUp.new(android: '', symbia: '', ios: '')
|
43
|
+
|
44
|
+
# start web
|
45
|
+
action_chain_4 = GtReq::ActionChain.new
|
46
|
+
action_chain_4.actionId = 10030
|
47
|
+
action_chain_4.type = GtReq::ActionChain::Type::Startapp
|
48
|
+
action_chain_4.appid = ''
|
49
|
+
action_chain_4.autostart = @transmission_type == 1
|
50
|
+
action_chain_4.appstartupid = app_start_up
|
51
|
+
action_chain_4.failedAction = 100
|
52
|
+
action_chain_4.next = 100
|
53
|
+
|
54
|
+
# end
|
55
|
+
action_chain_5 = GtReq::ActionChain.new
|
56
|
+
action_chain_5.actionId = 100
|
57
|
+
action_chain_5.type = GtReq::ActionChain::Type::Eoa
|
58
|
+
|
59
|
+
[action_chain_1, action_chain_2, action_chain_3, action_chain_4, action_chain_5]
|
60
|
+
end
|
61
|
+
|
62
|
+
def get_push_type
|
63
|
+
"NotifyMsg"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|