Commit 4a122fa4 by Victor Wang

LinkTemplate 和 NotificationTemplate 支持 iOS

parent 1e0a58be
......@@ -29,7 +29,9 @@ end
require "igetui/version"
require 'protobuf/GtReq.pb'
require "igetui/push_info"
require "igetui/template"
require "igetui/validate"
require "igetui/message"
require "igetui/pusher"
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
class BaseTemplate
attr_accessor :transmission_type, :transmission_content
attr_accessor :transmission_type, :transmission_content, :push_info
def initialize
@transmission_type = 0
@transmission_content = ''
@push_info = GtReq::PushInfo.new
@push_info = PushInfo.new
end
def get_transparent(pusher)
......@@ -15,7 +15,7 @@ module IGeTui
transparent.taskId = ''
transparent.action = 'pushmessage'
transparent.actionChain = get_action_chain
transparent.pushInfo = get_push_info
transparent.pushInfo = push_info
transparent.appId = pusher.app_id
transparent.appKey = pusher.app_key
transparent
......@@ -29,38 +29,19 @@ module IGeTui
raise NotImplementedError, 'Must be implemented by subtypes.'
end
def get_push_info
@push_info.actionKey = ''
@push_info.badge = ''
@push_info.message = ''
@push_info.sound = ''
@push_info
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,
# NOTE:
# iOS Pusher need the top four fields of 'push_info' are required.
# options can be includes [:payload, :loc_key, :loc_args, :launch_image]
# http://docs.igetui.com/pages/viewpage.action?pageId=590588
def set_push_info(action_loc_key, badge, message, sound, options = {})
args = options.merge({
action_loc_key: action_loc_key,
launch_image: launch_image,
badge: badge,
sound: sound,
payload: payload
}
message: message,
sound: sound
})
@push_info.update_properties(args)
# validate method need refactoring.
Validate.new.validate(args)
@push_info
end
......
......@@ -26,8 +26,8 @@ module IGeTui
if validate_length(args, :loc_args)
alertMap["loc-args"] = args[:loc_args].split(", ")
end
elsif validate_length(nil, message)
alertMap["body"] = message
elsif validate_length(nil, args[:message])
alertMap["body"] = args[:message]
end
apnsMap["alert"] = alertMap
......@@ -35,11 +35,11 @@ module IGeTui
apnsMap["action-loc-key"] = args[:action_loc_key]
end
apnsMap["badge"] = badge
apnsMap["badge"] = args[:badge]
h = Hash.new
h["aps"] = apnsMap
h["payload"] = payload if validate_length(nil, payload)
h["payload"] = args[:payload] if validate_length(nil, args[:payload])
return h
end
......
......@@ -81,12 +81,14 @@ class PusherTest < MiniTest::Unit::TestCase
template = IGeTui::LinkTemplate.new
set_template_base_info(template)
template.url = "http://www.baidu.com"
template.set_push_info("open", 4, "message", "")
template
end
def notification_template
template = IGeTui::NotificationTemplate.new
set_template_base_info(template)
template.set_push_info("open", 4, "message", "")
template
end
......@@ -94,14 +96,17 @@ class PusherTest < MiniTest::Unit::TestCase
template = IGeTui::TransmissionTemplate.new
# Notice: content should be string.
content = {
action: "notification",
title: "标题aaa",
content: "内容",
type: "article",
id: "4274"
"action" => "notification",
"title" => "标题aaa",
"content" => "内容",
"type" => "Article",
"id" => "1234"
}
content = content.to_s.gsub(":", "").gsub("=>", ":")
template.transmission_content = content
puts template.transmission_content
template.set_push_info("test", 1, "test1", "")
template
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