igetui-ruby 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c99084dc071b82bced2d791b76b564f28786be7c
4
+ data.tar.gz: 8061bca4c3e0fad40e4a364f4f8aae582831e214
5
+ SHA512:
6
+ metadata.gz: f6bb4a7b695936bc590c8cebad51fd3c82260c2e0de29149d9cf60ca6c10cca377f5a2aa8264ef7078d2d0a797f4cbdbd5570da86a98e6460fdb97e2e2fb8864
7
+ data.tar.gz: dd9c7d27fa24d99e3f3348bc3db8ecde67976e0e808d4fcb13e9dda8afe8863a926b60e72115f24511a6eebb24bb307be6d607ab6ce760e65dc131856a6f4e1c
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
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in igetui-ruby.gemspec
4
+ gemspec
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,29 @@
1
+ # Igetui::Ruby
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'igetui-ruby'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install igetui-ruby
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( http://github.com/<my-github-username>/igetui-ruby/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.pattern = "test/*_test.rb"
6
+ end
@@ -0,0 +1,28 @@
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"
9
+ spec.version = IGeTui::VERSION
10
+ spec.authors = ["Victor Wang"]
11
+ spec.email = ["QQ: 22674812"]
12
+ spec.summary = "igetui.com ruby sdk"
13
+ spec.description = "ruby-sdk of igetui.com push notification service"
14
+ spec.homepage = "https://github.com/wjp2013/igetui-ruby"
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
+ spec.add_dependency "json", '~> 1.8', ">= 1.8.1"
23
+ spec.add_dependency "ruby-protocol-buffers", '~> 1.5', '>= 1.5.1'
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.5"
26
+ spec.add_development_dependency "rake", '~> 10.3', '>= 10.3.1'
27
+ spec.add_development_dependency "minitest", '~> 5.4', '>= 5.4.0'
28
+ end
@@ -0,0 +1,9 @@
1
+ module IGeTui
2
+ class Client
3
+ attr_accessor :client_id
4
+
5
+ def initialize(client_id)
6
+ @client_id = client_id
7
+ end
8
+ end
9
+ 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
+ @app_id_list = []
20
+ @phone_type_list = []
21
+ @province_list = []
22
+ @tag_list = []
23
+ super
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,172 @@
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' => base64Str(template),
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' => base64Str(template),
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' => base64Str(template),
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 base64Str(template)
117
+ string = template.get_transparent(self).serialize_to_string
118
+ Base64.strict_encode64 string
119
+ end
120
+
121
+ def connect
122
+ time_stamp = Time.now.to_i
123
+ sign = Digest::MD5.hexdigest(app_key + time_stamp.to_s + master_secret)
124
+ data = {
125
+ action: 'connect',
126
+ appkey: app_key,
127
+ timeStamp: time_stamp,
128
+ sign: sign
129
+ }
130
+ ret = http_post(data)
131
+ ret['result'] == 'success'
132
+ end
133
+
134
+ def http_post_json(params)
135
+ params['version'] = '3.0.0.0'
136
+ ret = http_post(params)
137
+
138
+ if ret && ret['result'] == 'sign_error'
139
+ connect
140
+ ret = http_post(params)
141
+ end
142
+ ret
143
+ end
144
+
145
+ def http_post(params)
146
+ params['version'] = '3.0.0.0'
147
+ data = params.to_json
148
+
149
+ url = URI.parse(host)
150
+ req = Net::HTTP::Post.new(url.path, initheader = { 'Content-Type' => 'application/json' })
151
+ req.body = data
152
+
153
+ is_fail = true
154
+ retry_time_limit = 3
155
+ try_time = 0
156
+
157
+ while is_fail && try_time < retry_time_limit
158
+ begin
159
+ res = Net::HTTP.new(url.host, url.port).start { |http| http.request(req) }
160
+ is_fail = false
161
+ rescue
162
+ is_fail = true
163
+ try_time += 1
164
+ puts ('try ' + try_time.to_s + ' time failed, time out.')
165
+ end
166
+ end
167
+
168
+ JSON.parse res.body
169
+ end
170
+
171
+ end
172
+ end
@@ -0,0 +1,67 @@
1
+ module IGeTui
2
+ class BaseTemplate
3
+ attr_accessor :transmission_type, :transmission_content
4
+
5
+ def initialize
6
+ @push_info = nil
7
+ end
8
+
9
+ def get_transparent(pusher)
10
+ transparent = GtReq::Transparent.new
11
+ transparent.id = ''
12
+ transparent.messageId = ''
13
+ transparent.taskId = ''
14
+ transparent.action = 'pushmessage'
15
+ transparent.actionChain = get_action_chain
16
+ transparent.pushInfo = get_push_info
17
+ transparent.appId = pusher.app_id
18
+ transparent.appKey = pusher.app_key
19
+ transparent
20
+ end
21
+
22
+ def get_action_chain; end
23
+ def get_push_type; end
24
+
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
34
+ end
35
+
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)
40
+
41
+ @push_info = GtReq::PushInfo.new
42
+ @push_info.actionLocKey = action_loc_key
43
+ @push_info.badge = badge
44
+ @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
50
+
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
+ }
61
+
62
+ Validate.new.validate(args)
63
+ @push_info
64
+ end
65
+
66
+ end
67
+ end
@@ -0,0 +1,70 @@
1
+ module IGeTui
2
+ class NotificationTemplate < BaseTemplate
3
+ attr_accessor :title, :text, :logo, :logo_url
4
+ attr_accessor :is_ring, :is_vibrate, :is_clearable
5
+
6
+ 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 = false
16
+ super
17
+ end
18
+
19
+ def get_action_chain
20
+ # set actionchain
21
+ actionChain1 = GtReq::ActionChain.new
22
+ actionChain1.actionId = 1
23
+ actionChain1.type = GtReq::ActionChain::Type::Goto
24
+ actionChain1.next = 10000
25
+
26
+ # notification
27
+ actionChain2 = GtReq::ActionChain.new
28
+ actionChain2.actionId = 10000
29
+ actionChain2.type = GtReq::ActionChain::Type::Notification
30
+ actionChain2.title = title
31
+ actionChain2.text = text
32
+ actionChain2.logo = logo
33
+ actionChain2.logoURL = logo_url
34
+ actionChain2.ring = is_ring
35
+ actionChain2.clearable = is_clearable
36
+ actionChain2.buzz = is_vibrate
37
+ actionChain2.next = 10010
38
+
39
+ # goto
40
+ actionChain3 = GtReq::ActionChain.new
41
+ actionChain3.actionId = 10010
42
+ actionChain3.type = GtReq::ActionChain::Type::Goto
43
+ actionChain3.next = 10030
44
+
45
+ # appStartUp
46
+ appStartUp = GtReq::AppStartUp.new(android: '', symbia: '', ios: '')
47
+
48
+ # start web
49
+ actionChain4 = GtReq::ActionChain.new
50
+ actionChain4.actionId = 10030
51
+ actionChain4.type = GtReq::ActionChain::Type::Startapp
52
+ actionChain4.appid = ''
53
+ actionChain4.autostart = @transmission_type == 1
54
+ actionChain4.appstartupid = appStartUp
55
+ actionChain4.failedAction = 100
56
+ actionChain4.next = 100
57
+
58
+ # end
59
+ actionChain5 = GtReq::ActionChain.new
60
+ actionChain5.actionId = 100
61
+ actionChain5.type = GtReq::ActionChain::Type::Eoa
62
+
63
+ [actionChain1, actionChain2, actionChain3, actionChain4, actionChain5]
64
+ end
65
+
66
+ def get_push_type
67
+ "NotifyMsg"
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,42 @@
1
+ module IGeTui
2
+ class TransmissionTemplate < BaseTemplate
3
+ def initialize
4
+ @transmission_type = 0
5
+ @transmission_content = ''
6
+ super
7
+ end
8
+
9
+ def get_action_chain
10
+ # set actionChain
11
+ actionChain1 = GtReq::ActionChain.new
12
+ actionChain1.actionId = 1
13
+ actionChain1.type = GtReq::ActionChain::Type::Goto
14
+ actionChain1.next = 10030
15
+
16
+ # appStartUp
17
+ appStartUp = GtReq::AppStartUp.new(android: '', symbia: '', ios: '')
18
+
19
+ # start up app
20
+ actionChain2 = GtReq::ActionChain.new
21
+ actionChain2.actionId = 10030
22
+ actionChain2.type = GtReq::ActionChain::Type::Startapp
23
+ actionChain2.appid = ''
24
+ actionChain2.autostart = transmission_type == 1
25
+ actionChain2.appstartupid = appStartUp
26
+ actionChain2.failedAction = 100
27
+ actionChain2.next = 100
28
+
29
+ # end
30
+ actionChain3 = GtReq::ActionChain.new
31
+ actionChain3.actionId = 100
32
+ actionChain3.type = GtReq::ActionChain::Type::Eoa
33
+
34
+ [actionChain1, actionChain2, actionChain3]
35
+ end
36
+
37
+ def get_push_type
38
+ "TransmissionMsg"
39
+ end
40
+
41
+ end
42
+ end
@@ -0,0 +1,3 @@
1
+ require 'igetui/template/base_template'
2
+ require 'igetui/template/transmission_template'
3
+ require 'igetui/template/notification_template'
@@ -0,0 +1,57 @@
1
+ require 'json'
2
+ module IGeTui
3
+ class Validate
4
+ def validate(args = {})
5
+ payload_map = get_payload(args)
6
+
7
+ json = JSON.generate payload_map
8
+ if (json.length > 256)
9
+ raise ArgumentError.new("PushInfo length over limit: #{json.length}. Allowed: 256.")
10
+ end
11
+ end
12
+
13
+ def get_payload(args = {})
14
+ apnsMap = Hash.new
15
+
16
+ sound = "default" unless validate_length(args, :sound)
17
+ apnsMap["sound"] = args[:sound]
18
+
19
+ alertMap = Hash.new
20
+ if validate_length(args, :launch_image)
21
+ alertMap["launch-image"] = args[:launch_image]
22
+ end
23
+
24
+ if validate_length(args, :loc_key)
25
+ alertMap["loc-key"] = args[:loc_key]
26
+ if validate_length(args, :loc_args)
27
+ alertMap["loc-args"] = args[:loc_args].split(", ")
28
+ end
29
+ elsif validate_length(nil, message)
30
+ alertMap["body"] = message
31
+ end
32
+
33
+ apnsMap["alert"] = alertMap
34
+ if validate_length(args, :action_loc_key)
35
+ apnsMap["action-loc-key"] = args[:action_loc_key]
36
+ end
37
+
38
+ apnsMap["badge"] = badge
39
+
40
+ h = Hash.new
41
+ h["aps"] = apnsMap
42
+ h["payload"] = payload if validate_length(nil, payload)
43
+
44
+ return h
45
+ end
46
+
47
+ private
48
+
49
+ def validate_length(args = {}, key)
50
+ if key.class == Symbol
51
+ args[key] && args[key].length > 0
52
+ else
53
+ key && key.length > 0
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,3 @@
1
+ module IGeTui
2
+ VERSION = "0.0.1"
3
+ end
data/lib/igetui.rb ADDED
@@ -0,0 +1,35 @@
1
+ require 'forwardable'
2
+ require 'net/http'
3
+ require 'uri'
4
+ require 'json'
5
+ require 'digest/md5'
6
+ require 'base64'
7
+
8
+ module IGeTui
9
+ class << self
10
+ extend Forwardable
11
+
12
+ API_URL = "http://sdk.open.api.igexin.com/apiex.htm"
13
+
14
+ attr_reader :pusher
15
+
16
+ def_delegators :pusher, :push_message_to_single
17
+ def_delegators :pusher, :push_message_to_list
18
+ def_delegators :pusher, :push_message_to_app
19
+ def_delegators :pusher, :stop
20
+ def_delegators :pusher, :get_client_id_status
21
+ def_delegators :pusher, :get_content_id, :cancel_content_id
22
+
23
+ def pusher(app_id, api_key, master_secret)
24
+ @pusher ||= IGeTui::Pusher.new(API_URL, app_id, api_key, master_secret)
25
+ end
26
+
27
+ end
28
+ end
29
+
30
+ require "igetui/version"
31
+ require 'protobuf/GtReq.pb'
32
+ require "igetui/template"
33
+ require "igetui/message"
34
+ require "igetui/pusher"
35
+ require "igetui/client"
@@ -0,0 +1,399 @@
1
+ #!/usr/bin/env ruby
2
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
3
+ # make sure 'gem install ruby-protocol-buffers' at first.
4
+ # https://rubygems.org/gems/ruby-protocol-buffers
5
+ require 'protocol_buffers'
6
+
7
+ module GtReq
8
+ # forward declarations
9
+ class GtAuth < ::ProtocolBuffers::Message; end
10
+ class GtAuthResult < ::ProtocolBuffers::Message; end
11
+ class ReqServList < ::ProtocolBuffers::Message; end
12
+ class ReqServListResult < ::ProtocolBuffers::Message; end
13
+ class PushListResult < ::ProtocolBuffers::Message; end
14
+ class PushResult < ::ProtocolBuffers::Message; end
15
+ class PushOSSingleMessage < ::ProtocolBuffers::Message; end
16
+ class PushMMPSingleMessage < ::ProtocolBuffers::Message; end
17
+ class StartMMPBatchTask < ::ProtocolBuffers::Message; end
18
+ class StartOSBatchTask < ::ProtocolBuffers::Message; end
19
+ class PushListMessage < ::ProtocolBuffers::Message; end
20
+ class EndBatchTask < ::ProtocolBuffers::Message; end
21
+ class PushMMPAppMessage < ::ProtocolBuffers::Message; end
22
+ class ServerNotify < ::ProtocolBuffers::Message; end
23
+ class ServerNotifyResult < ::ProtocolBuffers::Message; end
24
+ class OSMessage < ::ProtocolBuffers::Message; end
25
+ class MMPMessage < ::ProtocolBuffers::Message; end
26
+ class Transparent < ::ProtocolBuffers::Message; end
27
+ class PushInfo < ::ProtocolBuffers::Message; end
28
+ class ActionChain < ::ProtocolBuffers::Message; end
29
+ class AppStartUp < ::ProtocolBuffers::Message; end
30
+ class Button < ::ProtocolBuffers::Message; end
31
+ class Target < ::ProtocolBuffers::Message; end
32
+
33
+ # enums
34
+ module CmdID
35
+ include ::ProtocolBuffers::Enum
36
+
37
+ set_fully_qualified_name "GtReq.CmdID"
38
+
39
+ GTHEARDBT = 0
40
+ GTAUTH = 1
41
+ GTAUTH_RESULT = 2
42
+ REQSERVHOST = 3
43
+ REQSERVHOSTRESULT = 4
44
+ PUSHRESULT = 5
45
+ PUSHOSSINGLEMESSAGE = 6
46
+ PUSHMMPSINGLEMESSAGE = 7
47
+ STARTMMPBATCHTASK = 8
48
+ STARTOSBATCHTASK = 9
49
+ PUSHLISTMESSAGE = 10
50
+ ENDBATCHTASK = 11
51
+ PUSHMMPAPPMESSAGE = 12
52
+ SERVERNOTIFY = 13
53
+ PUSHLISTRESULT = 14
54
+ SERVERNOTIFYRESULT = 15
55
+ end
56
+
57
+ module SMSStatus
58
+ include ::ProtocolBuffers::Enum
59
+
60
+ set_fully_qualified_name "GtReq.SMSStatus"
61
+
62
+ Unread = 0
63
+ Read = 1
64
+ end
65
+
66
+ class GtAuth < ::ProtocolBuffers::Message
67
+ set_fully_qualified_name "GtReq.GtAuth"
68
+
69
+ required :string, :sign, 1
70
+ required :string, :appkey, 2
71
+ required :int64, :timestamp, 3
72
+ optional :string, :seqId, 4
73
+ end
74
+
75
+ class GtAuthResult < ::ProtocolBuffers::Message
76
+ # forward declarations
77
+
78
+ # enums
79
+ module GtAuthResultCode
80
+ include ::ProtocolBuffers::Enum
81
+
82
+ set_fully_qualified_name "GtReq.GtAuthResult.GtAuthResultCode"
83
+
84
+ Successed = 0
85
+ Failed_noSign = 1
86
+ Failed_noAppkey = 2
87
+ Failed_noTimestamp = 3
88
+ Failed_AuthIllegal = 4
89
+ Redirect = 5
90
+ end
91
+
92
+ set_fully_qualified_name "GtReq.GtAuthResult"
93
+
94
+ required :int32, :code, 1
95
+ optional :string, :redirectAddress, 2
96
+ optional :string, :seqId, 3
97
+ optional :string, :info, 4
98
+ end
99
+
100
+ class ReqServList < ::ProtocolBuffers::Message
101
+ set_fully_qualified_name "GtReq.ReqServList"
102
+
103
+ optional :string, :seqId, 1
104
+ required :int64, :timestamp, 3
105
+ end
106
+
107
+ class ReqServListResult < ::ProtocolBuffers::Message
108
+ # forward declarations
109
+
110
+ # enums
111
+ module ReqServHostResultCode
112
+ include ::ProtocolBuffers::Enum
113
+
114
+ set_fully_qualified_name "GtReq.ReqServListResult.ReqServHostResultCode"
115
+
116
+ Successed = 0
117
+ Failed = 1
118
+ Busy = 2
119
+ end
120
+
121
+ set_fully_qualified_name "GtReq.ReqServListResult"
122
+
123
+ required :int32, :code, 1
124
+ repeated :string, :host, 2
125
+ optional :string, :seqId, 3
126
+ end
127
+
128
+ class PushListResult < ::ProtocolBuffers::Message
129
+ set_fully_qualified_name "GtReq.PushListResult"
130
+
131
+ repeated ::GtReq::PushResult, :results, 1
132
+ end
133
+
134
+ class PushResult < ::ProtocolBuffers::Message
135
+ # forward declarations
136
+
137
+ # enums
138
+ module EPushResult
139
+ include ::ProtocolBuffers::Enum
140
+
141
+ set_fully_qualified_name "GtReq.PushResult.EPushResult"
142
+
143
+ Successed_online = 0
144
+ Successed_offline = 1
145
+ Successed_ignore = 2
146
+ Failed = 3
147
+ Busy = 4
148
+ Success_startBatch = 5
149
+ Success_endBatch = 6
150
+ end
151
+
152
+ set_fully_qualified_name "GtReq.PushResult"
153
+
154
+ required ::GtReq::PushResult::EPushResult, :result, 1
155
+ required :string, :taskId, 2
156
+ required :string, :messageId, 3
157
+ required :string, :seqId, 4
158
+ required :string, :target, 5
159
+ optional :string, :info, 6
160
+ optional :string, :traceId, 7
161
+ end
162
+
163
+ class PushOSSingleMessage < ::ProtocolBuffers::Message
164
+ set_fully_qualified_name "GtReq.PushOSSingleMessage"
165
+
166
+ required :string, :seqId, 1
167
+ required ::GtReq::OSMessage, :message, 2
168
+ required ::GtReq::Target, :target, 3
169
+ end
170
+
171
+ class PushMMPSingleMessage < ::ProtocolBuffers::Message
172
+ set_fully_qualified_name "GtReq.PushMMPSingleMessage"
173
+
174
+ required :string, :seqId, 1
175
+ required ::GtReq::MMPMessage, :message, 2
176
+ required ::GtReq::Target, :target, 3
177
+ end
178
+
179
+ class StartMMPBatchTask < ::ProtocolBuffers::Message
180
+ set_fully_qualified_name "GtReq.StartMMPBatchTask"
181
+
182
+ required ::GtReq::MMPMessage, :message, 1
183
+ required :int64, :expire, 2, :default => 72
184
+ optional :string, :seqId, 3
185
+ end
186
+
187
+ class StartOSBatchTask < ::ProtocolBuffers::Message
188
+ set_fully_qualified_name "GtReq.StartOSBatchTask"
189
+
190
+ required ::GtReq::OSMessage, :message, 1
191
+ required :int64, :expire, 2, :default => 72
192
+ end
193
+
194
+ class PushListMessage < ::ProtocolBuffers::Message
195
+ set_fully_qualified_name "GtReq.PushListMessage"
196
+
197
+ required :string, :seqId, 1
198
+ required :string, :taskId, 2
199
+ repeated ::GtReq::Target, :targets, 3
200
+ end
201
+
202
+ class EndBatchTask < ::ProtocolBuffers::Message
203
+ set_fully_qualified_name "GtReq.EndBatchTask"
204
+
205
+ required :string, :taskId, 1
206
+ optional :string, :seqId, 2
207
+ end
208
+
209
+ class PushMMPAppMessage < ::ProtocolBuffers::Message
210
+ set_fully_qualified_name "GtReq.PushMMPAppMessage"
211
+
212
+ required ::GtReq::MMPMessage, :message, 1
213
+ repeated :string, :appIdList, 2
214
+ repeated :string, :phoneTypeList, 3
215
+ repeated :string, :provinceList, 4
216
+ optional :string, :seqId, 5
217
+ end
218
+
219
+ class ServerNotify < ::ProtocolBuffers::Message
220
+ # forward declarations
221
+
222
+ # enums
223
+ module NotifyType
224
+ include ::ProtocolBuffers::Enum
225
+
226
+ set_fully_qualified_name "GtReq.ServerNotify.NotifyType"
227
+
228
+ Normal = 0
229
+ ServerListChanged = 1
230
+ Exception = 2
231
+ end
232
+
233
+ set_fully_qualified_name "GtReq.ServerNotify"
234
+
235
+ required ::GtReq::ServerNotify::NotifyType, :type, 1
236
+ optional :string, :info, 2
237
+ optional :bytes, :extradata, 3
238
+ optional :string, :seqId, 4
239
+ end
240
+
241
+ class ServerNotifyResult < ::ProtocolBuffers::Message
242
+ set_fully_qualified_name "GtReq.ServerNotifyResult"
243
+
244
+ required :string, :seqId, 1
245
+ optional :string, :info, 2
246
+ end
247
+
248
+ class OSMessage < ::ProtocolBuffers::Message
249
+ set_fully_qualified_name "GtReq.OSMessage"
250
+
251
+ required :bool, :isOffline, 2
252
+ required :int64, :offlineExpireTime, 3, :default => 1
253
+ optional ::GtReq::Transparent, :transparent, 4
254
+ optional :string, :extraData, 5
255
+ optional :int32, :msgType, 6
256
+ optional :int32, :msgTraceFlag, 7
257
+ optional :int32, :priority, 8
258
+ end
259
+
260
+ class MMPMessage < ::ProtocolBuffers::Message
261
+ set_fully_qualified_name "GtReq.MMPMessage"
262
+
263
+ optional ::GtReq::Transparent, :transparent, 2
264
+ optional :string, :extraData, 3
265
+ optional :int32, :msgType, 4
266
+ optional :int32, :msgTraceFlag, 5
267
+ optional :int64, :msgOfflineExpire, 6
268
+ optional :bool, :isOffline, 7, :default => true
269
+ optional :int32, :priority, 8
270
+ end
271
+
272
+ class Transparent < ::ProtocolBuffers::Message
273
+ set_fully_qualified_name "GtReq.Transparent"
274
+
275
+ required :string, :id, 1
276
+ required :string, :action, 2
277
+ required :string, :taskId, 3
278
+ required :string, :appKey, 4
279
+ required :string, :appId, 5
280
+ required :string, :messageId, 6
281
+ optional ::GtReq::PushInfo, :pushInfo, 7
282
+ repeated ::GtReq::ActionChain, :actionChain, 8
283
+ end
284
+
285
+ class PushInfo < ::ProtocolBuffers::Message
286
+ set_fully_qualified_name "GtReq.PushInfo"
287
+
288
+ optional :string, :message, 1
289
+ optional :string, :actionKey, 2
290
+ optional :string, :sound, 3
291
+ optional :string, :badge, 4
292
+ optional :string, :payload, 5
293
+ optional :string, :locKey, 6
294
+ optional :string, :locArgs, 7
295
+ optional :string, :actionLocKey, 8
296
+ optional :string, :launchImage, 9
297
+ end
298
+
299
+ class ActionChain < ::ProtocolBuffers::Message
300
+ # forward declarations
301
+
302
+ # enums
303
+ module Type
304
+ include ::ProtocolBuffers::Enum
305
+
306
+ set_fully_qualified_name "GtReq.ActionChain.Type"
307
+
308
+ Goto = 0
309
+ Notification = 1
310
+ Popup = 2
311
+ Startapp = 3
312
+ Startweb = 4
313
+ Smsinbox = 5
314
+ Checkapp = 6
315
+ Eoa = 7
316
+ Appdownload = 8
317
+ Startsms = 9
318
+ Httpproxy = 10
319
+ Smsinbox2 = 11
320
+ Mmsinbox2 = 12
321
+ Popupweb = 13
322
+ Dial = 14
323
+ Reportbindapp = 15
324
+ Reportaddphoneinfo = 16
325
+ Reportapplist = 17
326
+ Terminatetask = 18
327
+ Reportapp = 19
328
+ Enablelog = 20
329
+ Disablelog = 21
330
+ Uploadlog = 22
331
+ end
332
+
333
+ set_fully_qualified_name "GtReq.ActionChain"
334
+
335
+ required :int32, :actionId, 1
336
+ required ::GtReq::ActionChain::Type, :type, 2
337
+ optional :int32, :next, 3
338
+ optional :string, :logo, 100
339
+ optional :string, :logoURL, 101
340
+ optional :string, :title, 102
341
+ optional :string, :text, 103
342
+ optional :bool, :clearable, 104
343
+ optional :bool, :ring, 105
344
+ optional :bool, :buzz, 106
345
+ optional :string, :bannerURL, 107
346
+ optional :string, :img, 120
347
+ repeated ::GtReq::Button, :buttons, 121
348
+ optional :string, :appid, 140
349
+ optional ::GtReq::AppStartUp, :appstartupid, 141
350
+ optional :bool, :autostart, 142
351
+ optional :int32, :failedAction, 143
352
+ optional :string, :url, 160
353
+ optional :string, :withcid, 161
354
+ optional :bool, :is_withnettype, 162, :default => false
355
+ optional :string, :address, 180
356
+ optional :string, :content, 181
357
+ optional :int64, :ct, 182
358
+ optional ::GtReq::SMSStatus, :flag, 183
359
+ optional :int32, :successedAction, 200
360
+ optional :int32, :uninstalledAction, 201
361
+ optional :string, :name, 220
362
+ optional :bool, :autoInstall, 223
363
+ optional :bool, :wifiAutodownload, 225
364
+ optional :bool, :forceDownload, 226
365
+ optional :bool, :showProgress, 227
366
+ optional :string, :post, 241
367
+ optional :string, :headers, 242
368
+ optional :bool, :groupable, 260
369
+ optional :string, :mmsTitle, 280
370
+ optional :string, :mmsURL, 281
371
+ optional :bool, :preload, 300
372
+ optional :string, :taskid, 320
373
+ optional :int64, :duration, 340
374
+ optional :string, :date, 360
375
+ end
376
+
377
+ class AppStartUp < ::ProtocolBuffers::Message
378
+ set_fully_qualified_name "GtReq.AppStartUp"
379
+
380
+ optional :string, :android, 1
381
+ optional :string, :symbia, 2
382
+ optional :string, :ios, 3
383
+ end
384
+
385
+ class Button < ::ProtocolBuffers::Message
386
+ set_fully_qualified_name "GtReq.Button"
387
+
388
+ optional :string, :text, 1
389
+ optional :int32, :next, 2
390
+ end
391
+
392
+ class Target < ::ProtocolBuffers::Message
393
+ set_fully_qualified_name "GtReq.Target"
394
+
395
+ required :string, :appId, 1
396
+ required :string, :clientId, 2
397
+ end
398
+
399
+ end
@@ -0,0 +1,83 @@
1
+ require 'minitest/autorun'
2
+ require './lib/igetui'
3
+
4
+ class PusherTest < MiniTest::Unit::TestCase
5
+
6
+ # before run test, you need to change the variables in setup method.
7
+ def setup
8
+ @app_id = 'YOUR APP ID'
9
+ @app_key = 'YOUR APP KEY'
10
+ @master_secret = 'YOUR MASTER SECRET'
11
+ @cid_1 = 'CLIENT ID ONE'
12
+ @cid_2 = 'CLIENT ID TWO'
13
+
14
+ @pusher = IGeTui.pusher(@app_id, @app_key, @master_secret)
15
+ @client_1 = IGeTui::Client.new(@cid_1)
16
+ @client_2 = IGeTui::Client.new(@cid_2)
17
+ end
18
+
19
+ def test_status
20
+ ret = @pusher.get_client_id_status(@cid_1)
21
+ assert_equal ret["result"], "Online"
22
+ end
23
+
24
+ def test_to_single_notification
25
+ single_message = IGeTui::SingleMessage.new
26
+ single_message.data = notification_template
27
+ ret = @pusher.push_message_to_single(single_message, @client_1)
28
+ assert_equal ret["result"], "ok"
29
+ end
30
+
31
+ def test_to_single_transmission
32
+ single_message = IGeTui::SingleMessage.new
33
+ single_message.data = transmission_template
34
+ ret = @pusher.push_message_to_single(single_message, @client_1)
35
+ assert_equal ret["result"], "ok"
36
+ end
37
+
38
+ def test_to_list_transmission
39
+ list_message = IGeTui::ListMessage.new
40
+ list_message.data = transmission_template
41
+ client_list = [@client_1, @client_2]
42
+ content_id = @pusher.get_content_id(list_message)
43
+ ret = @pusher.push_message_to_list(content_id, client_list)
44
+ assert_equal ret["result"], "ok"
45
+ end
46
+
47
+ def test_to_app_notification
48
+ app_message = IGeTui::AppMessage.new
49
+ app_message.data = notification_template
50
+ app_message.app_id_list = [@app_id]
51
+ # app_message.province_list = ['浙江', '上海']
52
+ # app_message.tag_list = ['开心']
53
+ ret = @pusher.push_message_to_app(app_message)
54
+ assert_equal ret["result"], "ok"
55
+ end
56
+
57
+ private
58
+
59
+ def notification_template
60
+ template = IGeTui::NotificationTemplate.new
61
+ template.logo = 'push.png'
62
+ template.logo_url = 'http://www.igetui.com/wp-content/uploads/2013/08/logo_getui1.png'
63
+ template.title = '测试标题'
64
+ template.text = '测试文本'
65
+ template
66
+ end
67
+
68
+ def transmission_template
69
+ template = IGeTui::TransmissionTemplate.new
70
+ # Notice: content should be string.
71
+ content = {
72
+ action: "notification",
73
+ title: "标题aaa",
74
+ content: "内容",
75
+ type: "article",
76
+ id: "4274"
77
+ }
78
+ content = content.to_s.gsub(":", "").gsub("=>", ":")
79
+ template.transmission_content = content
80
+ template
81
+ end
82
+
83
+ end
metadata ADDED
@@ -0,0 +1,158 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: igetui-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Victor Wang
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: json
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.8'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.8.1
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '1.8'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 1.8.1
33
+ - !ruby/object:Gem::Dependency
34
+ name: ruby-protocol-buffers
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.5'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 1.5.1
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '1.5'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 1.5.1
53
+ - !ruby/object:Gem::Dependency
54
+ name: bundler
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '1.5'
60
+ type: :development
61
+ prerelease: false
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - "~>"
65
+ - !ruby/object:Gem::Version
66
+ version: '1.5'
67
+ - !ruby/object:Gem::Dependency
68
+ name: rake
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - "~>"
72
+ - !ruby/object:Gem::Version
73
+ version: '10.3'
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: 10.3.1
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: '10.3'
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: 10.3.1
87
+ - !ruby/object:Gem::Dependency
88
+ name: minitest
89
+ requirement: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - "~>"
92
+ - !ruby/object:Gem::Version
93
+ version: '5.4'
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: 5.4.0
97
+ type: :development
98
+ prerelease: false
99
+ version_requirements: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '5.4'
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: 5.4.0
107
+ description: ruby-sdk of igetui.com push notification service
108
+ email:
109
+ - 'QQ: 22674812'
110
+ executables: []
111
+ extensions: []
112
+ extra_rdoc_files:
113
+ - README.md
114
+ files:
115
+ - ".gitignore"
116
+ - Gemfile
117
+ - LICENSE.txt
118
+ - README.md
119
+ - Rakefile
120
+ - igetui-ruby.gemspec
121
+ - lib/igetui.rb
122
+ - lib/igetui/client.rb
123
+ - lib/igetui/message.rb
124
+ - lib/igetui/pusher.rb
125
+ - lib/igetui/template.rb
126
+ - lib/igetui/template/base_template.rb
127
+ - lib/igetui/template/notification_template.rb
128
+ - lib/igetui/template/transmission_template.rb
129
+ - lib/igetui/validate.rb
130
+ - lib/igetui/version.rb
131
+ - lib/protobuf/GtReq.pb.rb
132
+ - test/pusher_test.rb
133
+ homepage: https://github.com/wjp2013/igetui-ruby
134
+ licenses:
135
+ - MIT
136
+ metadata: {}
137
+ post_install_message:
138
+ rdoc_options: []
139
+ require_paths:
140
+ - lib
141
+ required_ruby_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ required_rubygems_version: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ requirements: []
152
+ rubyforge_project:
153
+ rubygems_version: 2.2.2
154
+ signing_key:
155
+ specification_version: 4
156
+ summary: igetui.com ruby sdk
157
+ test_files:
158
+ - test/pusher_test.rb