Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
I
igetui-ruby
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ikcrm_common
igetui-ruby
Commits
4a122fa4
Commit
4a122fa4
authored
Sep 02, 2014
by
Victor Wang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
LinkTemplate 和 NotificationTemplate 支持 iOS
parent
1e0a58be
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
60 additions
and
42 deletions
+60
-42
lib/igetui.rb
+2
-0
lib/igetui/push_info.rb
+30
-0
lib/igetui/template/base_template.rb
+14
-33
lib/igetui/validate.rb
+4
-4
test/pusher_test.rb
+10
-5
No files found.
lib/igetui.rb
View file @
4a122fa4
...
...
@@ -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"
lib/igetui/push_info.rb
0 → 100644
View file @
4a122fa4
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
lib/igetui/template/base_template.rb
View file @
4a122fa4
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
...
...
lib/igetui/validate.rb
View file @
4a122fa4
...
...
@@ -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
...
...
test/pusher_test.rb
View file @
4a122fa4
...
...
@@ -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:
"a
rticle"
,
id:
"427
4"
"action"
=>
"notification"
,
"title"
=>
"标题aaa"
,
"content"
=>
"内容"
,
"type"
=>
"A
rticle"
,
"id"
=>
"123
4"
}
content
=
content
.
to_s
.
gsub
(
":"
,
""
).
gsub
(
"=>"
,
":"
)
template
.
transmission_content
=
content
puts
template
.
transmission_content
template
.
set_push_info
(
"test"
,
1
,
"test1"
,
""
)
template
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment