Commit 4a122fa4 by Victor Wang

LinkTemplate 和 NotificationTemplate 支持 iOS

parent 1e0a58be
...@@ -29,7 +29,9 @@ end ...@@ -29,7 +29,9 @@ end
require "igetui/version" require "igetui/version"
require 'protobuf/GtReq.pb' require 'protobuf/GtReq.pb'
require "igetui/push_info"
require "igetui/template" require "igetui/template"
require "igetui/validate"
require "igetui/message" require "igetui/message"
require "igetui/pusher" require "igetui/pusher"
require "igetui/client" require "igetui/client"
module IGeTui
# PushInfo support Apple Push Notification
class PushInfo < GtReq::PushInfo
STRING_ATTRIBUTES = %i(
action_loc_key badge message sound
action_key payload loc_key loc_args launch_image
).freeze
attr_accessor *STRING_ATTRIBUTES
def initialize
STRING_ATTRIBUTES.each { |attr| instance_variable_set("@#{attr}", '') }
end
def update_properties(args)
args.each { |k, v| instance_variable_set("@#{k}", v) }
@actionLocKey = action_loc_key
@locKey = loc_key
@locArgs = loc_args
@launchImage = launch_image
@actionKey = action_key
end
# alias_method :actionLocKey, :action_loc_key
# alias_method :locKey, :loc_key
# alias_method :locArgs, :loc_args
# alias_method :launchImage, :launch_image
# alias_method :actionKey, :action_key
end
end
module IGeTui module IGeTui
class BaseTemplate class BaseTemplate
attr_accessor :transmission_type, :transmission_content attr_accessor :transmission_type, :transmission_content, :push_info
def initialize def initialize
@transmission_type = 0 @transmission_type = 0
@transmission_content = '' @transmission_content = ''
@push_info = GtReq::PushInfo.new @push_info = PushInfo.new
end end
def get_transparent(pusher) def get_transparent(pusher)
...@@ -15,7 +15,7 @@ module IGeTui ...@@ -15,7 +15,7 @@ module IGeTui
transparent.taskId = '' transparent.taskId = ''
transparent.action = 'pushmessage' transparent.action = 'pushmessage'
transparent.actionChain = get_action_chain transparent.actionChain = get_action_chain
transparent.pushInfo = get_push_info transparent.pushInfo = push_info
transparent.appId = pusher.app_id transparent.appId = pusher.app_id
transparent.appKey = pusher.app_key transparent.appKey = pusher.app_key
transparent transparent
...@@ -29,38 +29,19 @@ module IGeTui ...@@ -29,38 +29,19 @@ module IGeTui
raise NotImplementedError, 'Must be implemented by subtypes.' raise NotImplementedError, 'Must be implemented by subtypes.'
end end
def get_push_info # NOTE:
@push_info.actionKey = '' # iOS Pusher need the top four fields of 'push_info' are required.
@push_info.badge = '' # options can be includes [:payload, :loc_key, :loc_args, :launch_image]
@push_info.message = '' # http://docs.igetui.com/pages/viewpage.action?pageId=590588
@push_info.sound = '' def set_push_info(action_loc_key, badge, message, sound, options = {})
@push_info args = options.merge({
end
# Need TEST:
# iOS Pusher need the top three fields of 'push_info' are required.
# the others can be blank string.
def set_push_info(action_loc_key, badge, message, sound, payload, loc_key, loc_args, launch_image)
@push_info.actionLocKey = action_loc_key
@push_info.badge = badge
@push_info.message = message
@push_info.sound = sound if sound
@push_info.payload = payload if payload
@push_info.locKey = loc_key if loc_key
@push_info.locArgs = loc_args if loc_args
@push_info.launchImage = launch_image if launch_image
args = {
loc_key: loc_key,
loc_args: locArgs,
message: message,
action_loc_key: action_loc_key, action_loc_key: action_loc_key,
launch_image: launch_image,
badge: badge, badge: badge,
sound: sound, message: message,
payload: payload sound: sound
} })
@push_info.update_properties(args)
# validate method need refactoring.
Validate.new.validate(args) Validate.new.validate(args)
@push_info @push_info
end end
......
...@@ -26,8 +26,8 @@ module IGeTui ...@@ -26,8 +26,8 @@ module IGeTui
if validate_length(args, :loc_args) if validate_length(args, :loc_args)
alertMap["loc-args"] = args[:loc_args].split(", ") alertMap["loc-args"] = args[:loc_args].split(", ")
end end
elsif validate_length(nil, message) elsif validate_length(nil, args[:message])
alertMap["body"] = message alertMap["body"] = args[:message]
end end
apnsMap["alert"] = alertMap apnsMap["alert"] = alertMap
...@@ -35,11 +35,11 @@ module IGeTui ...@@ -35,11 +35,11 @@ module IGeTui
apnsMap["action-loc-key"] = args[:action_loc_key] apnsMap["action-loc-key"] = args[:action_loc_key]
end end
apnsMap["badge"] = badge apnsMap["badge"] = args[:badge]
h = Hash.new h = Hash.new
h["aps"] = apnsMap h["aps"] = apnsMap
h["payload"] = payload if validate_length(nil, payload) h["payload"] = args[:payload] if validate_length(nil, args[:payload])
return h return h
end end
......
...@@ -81,12 +81,14 @@ class PusherTest < MiniTest::Unit::TestCase ...@@ -81,12 +81,14 @@ class PusherTest < MiniTest::Unit::TestCase
template = IGeTui::LinkTemplate.new template = IGeTui::LinkTemplate.new
set_template_base_info(template) set_template_base_info(template)
template.url = "http://www.baidu.com" template.url = "http://www.baidu.com"
template.set_push_info("open", 4, "message", "")
template template
end end
def notification_template def notification_template
template = IGeTui::NotificationTemplate.new template = IGeTui::NotificationTemplate.new
set_template_base_info(template) set_template_base_info(template)
template.set_push_info("open", 4, "message", "")
template template
end end
...@@ -94,14 +96,17 @@ class PusherTest < MiniTest::Unit::TestCase ...@@ -94,14 +96,17 @@ class PusherTest < MiniTest::Unit::TestCase
template = IGeTui::TransmissionTemplate.new template = IGeTui::TransmissionTemplate.new
# Notice: content should be string. # Notice: content should be string.
content = { content = {
action: "notification", "action" => "notification",
title: "标题aaa", "title" => "标题aaa",
content: "内容", "content" => "内容",
type: "article", "type" => "Article",
id: "4274" "id" => "1234"
} }
content = content.to_s.gsub(":", "").gsub("=>", ":") content = content.to_s.gsub(":", "").gsub("=>", ":")
template.transmission_content = content template.transmission_content = content
puts template.transmission_content
template.set_push_info("test", 1, "test1", "")
template template
end end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment