├── .gitignore ├── Gemfile ├── LICENSE ├── LICENSE.txt ├── README.md ├── Rakefile ├── igetui-ruby.gemspec ├── lib ├── igetui.rb ├── igetui │ ├── client.rb │ ├── message.rb │ ├── pusher.rb │ ├── template.rb │ ├── template │ │ ├── base_template.rb │ │ ├── link_template.rb │ │ ├── notification_template.rb │ │ ├── noty_pop_load_template.rb │ │ └── transmission_template.rb │ ├── validate.rb │ └── version.rb ├── igetui_ruby.rb └── protobuf │ └── GtReq.pb.rb └── test └── pusher_test.rb /.gitignore: -------------------------------------------------------------------------------- 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 47 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # Specify your gem's dependencies in igetui-ruby.gemspec 4 | gemspec 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 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. 22 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 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. 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 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 137 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require "bundler/gem_tasks" 2 | require 'rake/testtask' 3 | 4 | Rake::TestTask.new do |t| 5 | t.pattern = "test/*_test.rb" 6 | end 7 | -------------------------------------------------------------------------------- /igetui-ruby.gemspec: -------------------------------------------------------------------------------- 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 29 | -------------------------------------------------------------------------------- /lib/igetui.rb: -------------------------------------------------------------------------------- 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/validate" 34 | require "igetui/message" 35 | require "igetui/pusher" 36 | require "igetui/client" 37 | -------------------------------------------------------------------------------- /lib/igetui/client.rb: -------------------------------------------------------------------------------- 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 10 | -------------------------------------------------------------------------------- /lib/igetui/message.rb: -------------------------------------------------------------------------------- 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 27 | -------------------------------------------------------------------------------- /lib/igetui/pusher.rb: -------------------------------------------------------------------------------- 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 164 | -------------------------------------------------------------------------------- /lib/igetui/template.rb: -------------------------------------------------------------------------------- 1 | require 'igetui/template/base_template' 2 | require 'igetui/template/transmission_template' 3 | require 'igetui/template/link_template' 4 | require 'igetui/template/notification_template' 5 | require 'igetui/template/noty_pop_load_template' 6 | -------------------------------------------------------------------------------- /lib/igetui/template/base_template.rb: -------------------------------------------------------------------------------- 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 71 | -------------------------------------------------------------------------------- /lib/igetui/template/link_template.rb: -------------------------------------------------------------------------------- 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 61 | -------------------------------------------------------------------------------- /lib/igetui/template/notification_template.rb: -------------------------------------------------------------------------------- 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 67 | -------------------------------------------------------------------------------- /lib/igetui/template/noty_pop_load_template.rb: -------------------------------------------------------------------------------- 1 | module IGeTui 2 | class NotyPopLoadTemplate < BaseTemplate 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 14 | 15 | def initialize 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) } 21 | end 22 | 23 | def get_action_chain 24 | # set actionchain 25 | action_chain_1 = GtReq::ActionChain.new 26 | action_chain_1.actionId = 1 27 | action_chain_1.type = GtReq::ActionChain::Type::Goto 28 | action_chain_1.next = 10000 29 | 30 | # notification 31 | action_chain_2 = GtReq::ActionChain.new 32 | action_chain_2.actionId = 10000 33 | action_chain_2.type = GtReq::ActionChain::Type::Notification 34 | action_chain_2.title = title 35 | action_chain_2.text = text 36 | action_chain_2.logo = logo 37 | action_chain_2.logoURL = logo_url 38 | action_chain_2.ring = is_ring 39 | action_chain_2.clearable = is_clearable 40 | action_chain_2.buzz = is_vibrate 41 | action_chain_2.next = 10010 42 | 43 | # goto 44 | action_chain_3 = GtReq::ActionChain.new 45 | action_chain_3.actionId = 10010 46 | action_chain_3.type = GtReq::ActionChain::Type::Goto 47 | action_chain_3.next = 10020 48 | 49 | action_chain_4 = GtReq::ActionChain.new 50 | 51 | button_1 = GtReq::Button.new 52 | button_1.text = pop_button_1 53 | button_1.next = 10040 54 | button_2 = GtReq::Button.new 55 | button_2.text = pop_button_2 56 | button_2.next = 100 57 | 58 | action_chain_4.actionId = 10020 59 | action_chain_4.type = GtReq::ActionChain::Type::Popup 60 | action_chain_4.title = pop_title 61 | action_chain_4.text = pop_text 62 | action_chain_4.img = pop_image 63 | action_chain_4.buttons = [button_1, button_2] 64 | action_chain_4.next = 6 65 | 66 | app_start_up = GtReq::AppStartUp.new(android: '', symbia: '', ios: '') 67 | action_chain_5 = GtReq::ActionChain.new 68 | action_chain_5.actionId = 10040 69 | action_chain_5.type = GtReq::ActionChain::Type::Appdownload 70 | action_chain_5.name = load_title 71 | action_chain_5.url = load_url 72 | action_chain_5.logo = load_icon 73 | action_chain_5.autoInstall = is_auto_install 74 | action_chain_5.autostart = is_active 75 | action_chain_5.appstartupid = app_start_up 76 | action_chain_5.next = 6 77 | 78 | # end 79 | action_chain_6 = GtReq::ActionChain.new 80 | action_chain_6.actionId = 100 81 | action_chain_6.type = GtReq::ActionChain::Type::Eoa 82 | 83 | [action_chain_1, action_chain_2, action_chain_3, action_chain_4, action_chain_5, action_chain_6] 84 | end 85 | 86 | def get_push_type 87 | "NotyPopLoadMsg" 88 | end 89 | end 90 | end 91 | -------------------------------------------------------------------------------- /lib/igetui/template/transmission_template.rb: -------------------------------------------------------------------------------- 1 | module IGeTui 2 | class TransmissionTemplate < BaseTemplate 3 | def initialize 4 | super 5 | end 6 | 7 | def get_action_chain 8 | # set actionChain 9 | action_chain_1 = GtReq::ActionChain.new 10 | action_chain_1.actionId = 1 11 | action_chain_1.type = GtReq::ActionChain::Type::Goto 12 | action_chain_1.next = 10030 13 | 14 | # appStartUp 15 | app_start_up = GtReq::AppStartUp.new(android: '', symbia: '', ios: '') 16 | 17 | # start up app 18 | action_chain_2 = GtReq::ActionChain.new 19 | action_chain_2.actionId = 10030 20 | action_chain_2.type = GtReq::ActionChain::Type::Startapp 21 | action_chain_2.appid = '' 22 | action_chain_2.autostart = transmission_type == 1 23 | action_chain_2.appstartupid = app_start_up 24 | action_chain_2.failedAction = 100 25 | action_chain_2.next = 100 26 | 27 | # end 28 | action_chain_3 = GtReq::ActionChain.new 29 | action_chain_3.actionId = 100 30 | action_chain_3.type = GtReq::ActionChain::Type::Eoa 31 | 32 | [action_chain_1, action_chain_2, action_chain_3] 33 | end 34 | 35 | def get_push_type 36 | "TransmissionMsg" 37 | end 38 | 39 | end 40 | end 41 | -------------------------------------------------------------------------------- /lib/igetui/validate.rb: -------------------------------------------------------------------------------- 1 | module IGeTui 2 | class Validate 3 | def validate(args = {}) 4 | # payload_map = get_payload(args) 5 | 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] 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 80 | end 81 | 82 | def get_payload(args = {}) 83 | apnsMap = Hash.new 84 | 85 | sound = "default" unless validate_length(args, :sound) 86 | apnsMap["sound"] = args[:sound] 87 | 88 | alertMap = Hash.new 89 | if validate_length(args, :launch_image) 90 | alertMap["launch-image"] = args[:launch_image] 91 | end 92 | 93 | if validate_length(args, :loc_key) 94 | alertMap["loc-key"] = args[:loc_key] 95 | if validate_length(args, :loc_args) 96 | alertMap["loc-args"] = args[:loc_args].split(", ") 97 | end 98 | elsif validate_length(nil, args[:message]) 99 | alertMap["body"] = args[:message] 100 | end 101 | 102 | apnsMap["alert"] = alertMap 103 | if validate_length(args, :action_loc_key) 104 | apnsMap["action-loc-key"] = args[:action_loc_key] 105 | end 106 | 107 | apnsMap["badge"] = args[:badge] 108 | 109 | h = Hash.new 110 | h["aps"] = apnsMap 111 | h["payload"] = args[:payload] if validate_length(nil, args[:payload]) 112 | 113 | return h 114 | end 115 | 116 | private 117 | 118 | def validate_length(args = {}, key) 119 | if key.class == Symbol 120 | args[key] && args[key].length > 0 121 | else 122 | key && key.length > 0 123 | end 124 | end 125 | end 126 | end 127 | -------------------------------------------------------------------------------- /lib/igetui/version.rb: -------------------------------------------------------------------------------- 1 | module IGeTui 2 | VERSION = "1.2.2" 3 | end 4 | -------------------------------------------------------------------------------- /lib/igetui_ruby.rb: -------------------------------------------------------------------------------- 1 | require 'igetui' 2 | -------------------------------------------------------------------------------- /lib/protobuf/GtReq.pb.rb: -------------------------------------------------------------------------------- 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 400 | -------------------------------------------------------------------------------- /test/pusher_test.rb: -------------------------------------------------------------------------------- 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_noty_pop_load 25 | single_message = IGeTui::SingleMessage.new 26 | single_message.data = noty_pop_load_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_notification 32 | single_message = IGeTui::SingleMessage.new 33 | single_message.data = notification_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_single_link_notification 39 | single_message = IGeTui::SingleMessage.new 40 | single_message.data = link_template 41 | ret = @pusher.push_message_to_single(single_message, @client_1) 42 | assert_equal ret["result"], "ok" 43 | end 44 | 45 | def test_to_single_transmission 46 | single_message = IGeTui::SingleMessage.new 47 | single_message.data = transmission_template 48 | ret = @pusher.push_message_to_single(single_message, @client_1) 49 | assert_equal ret["result"], "ok" 50 | end 51 | 52 | def test_to_list_transmission 53 | list_message = IGeTui::ListMessage.new 54 | list_message.data = transmission_template 55 | client_list = [@client_1, @client_2] 56 | content_id = @pusher.get_content_id(list_message) 57 | ret = @pusher.push_message_to_list(content_id, client_list) 58 | assert_equal ret["result"], "ok" 59 | end 60 | 61 | def test_to_app_notification 62 | app_message = IGeTui::AppMessage.new 63 | app_message.data = notification_template 64 | app_message.app_id_list = [@app_id] 65 | # app_message.province_list = ['浙江', '上海'] 66 | # app_message.tag_list = ['开心'] 67 | ret = @pusher.push_message_to_app(app_message) 68 | assert_equal ret["result"], "ok" 69 | end 70 | 71 | private 72 | 73 | def set_template_base_info(template) 74 | template.logo = 'push.png' 75 | template.logo_url = 'http://www.igetui.com/wp-content/uploads/2013/08/logo_getui1.png' 76 | template.title = '测试标题' 77 | template.text = '测试文本' 78 | end 79 | 80 | def link_template 81 | template = IGeTui::LinkTemplate.new 82 | set_template_base_info(template) 83 | template.url = "http://www.baidu.com" 84 | template.set_push_info("open", 4, "message", "") 85 | template 86 | end 87 | 88 | def notification_template 89 | template = IGeTui::NotificationTemplate.new 90 | set_template_base_info(template) 91 | template.set_push_info("open", 4, "message", "") 92 | template 93 | end 94 | 95 | def transmission_template 96 | template = IGeTui::TransmissionTemplate.new 97 | # Notice: content should be string. 98 | content = { 99 | "action" => "notification", 100 | "title" => "标题aaa", 101 | "content" => "内容", 102 | "type" => "Article", 103 | "id" => "1234" 104 | } 105 | 106 | content = content.to_s.gsub(":", "").gsub("=>", ":") 107 | template.transmission_content = content 108 | puts template.transmission_content 109 | template.set_push_info("test", 1, "test1", "") 110 | template 111 | end 112 | 113 | # attr_accessor :load_icon, :load_title, :load_url 114 | def noty_pop_load_template 115 | template = IGeTui::NotyPopLoadTemplate.new 116 | set_template_base_info(template) 117 | template.pop_title = "弹框标题" 118 | template.pop_text = "弹框内容" 119 | template.pop_image = "" 120 | template.pop_button_1 = "下载" 121 | template.pop_button_2 = "取消" 122 | template.load_icon = "file://icon.png" 123 | template.load_title = "下载内容" 124 | template.load_url = "http://gdown.baidu.com/data/wisegame/c95836e06c224f51/weixinxinqing_5.apk" 125 | template 126 | end 127 | 128 | end 129 | --------------------------------------------------------------------------------