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
66a6f5b9
Commit
66a6f5b9
authored
Sep 03, 2014
by
Victor Wang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
支持 ios 推送
parent
4a122fa4
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
108 additions
and
55 deletions
+108
-55
lib/igetui.rb
+0
-1
lib/igetui/push_info.rb
+0
-30
lib/igetui/pusher.rb
+3
-8
lib/igetui/template/base_template.rb
+30
-10
lib/igetui/validate.rb
+74
-5
lib/igetui/version.rb
+1
-1
No files found.
lib/igetui.rb
View file @
66a6f5b9
...
...
@@ -29,7 +29,6 @@ end
require
"igetui/version"
require
'protobuf/GtReq.pb'
require
"igetui/push_info"
require
"igetui/template"
require
"igetui/validate"
require
"igetui/message"
...
...
lib/igetui/push_info.rb
deleted
100644 → 0
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/pusher.rb
View file @
66a6f5b9
...
...
@@ -14,7 +14,7 @@ module IGeTui
data
=
{
'action'
=>
'pushMessageToSingleAction'
,
'appkey'
=>
app_key
,
'clientData'
=>
base64Str
(
template
),
'clientData'
=>
template
.
get_client_data
(
self
),
'transmissionContent'
=>
template
.
transmission_content
,
'isOffline'
=>
message
.
is_offline
,
'offlineExpireTime'
=>
message
.
offline_expire_time
,
...
...
@@ -50,7 +50,7 @@ module IGeTui
data
=
{
'action'
=>
'pushMessageToAppAction'
,
'appkey'
=>
app_key
,
'clientData'
=>
base64Str
(
template
),
'clientData'
=>
template
.
get_client_data
(
self
),
'transmissionContent'
=>
template
.
transmission_content
,
'isOffline'
=>
message
.
is_offline
,
'offlineExpireTime'
=>
message
.
offline_expire_time
,
...
...
@@ -91,7 +91,7 @@ module IGeTui
data
=
{
'action'
=>
'getContentIdAction'
,
'appkey'
=>
app_key
,
'clientData'
=>
base64Str
(
template
),
'clientData'
=>
template
.
get_client_data
(
self
),
'transmissionContent'
=>
template
.
transmission_content
,
'isOffline'
=>
message
.
is_offline
,
'offlineExpireTime'
=>
message
.
offline_expire_time
,
...
...
@@ -113,11 +113,6 @@ module IGeTui
private
def
base64Str
(
template
)
string
=
template
.
get_transparent
(
self
).
serialize_to_string
Base64
.
strict_encode64
string
end
def
connect
time_stamp
=
Time
.
now
.
to_i
sign
=
Digest
::
MD5
.
hexdigest
(
app_key
+
time_stamp
.
to_s
+
master_secret
)
...
...
lib/igetui/template/base_template.rb
View file @
66a6f5b9
...
...
@@ -5,7 +5,6 @@ module IGeTui
def
initialize
@transmission_type
=
0
@transmission_content
=
''
@push_info
=
PushInfo
.
new
end
def
get_transparent
(
pusher
)
...
...
@@ -15,7 +14,7 @@ module IGeTui
transparent
.
taskId
=
''
transparent
.
action
=
'pushmessage'
transparent
.
actionChain
=
get_action_chain
transparent
.
pushInfo
=
push_info
transparent
.
pushInfo
=
get_
push_info
transparent
.
appId
=
pusher
.
app_id
transparent
.
appKey
=
pusher
.
app_key
transparent
...
...
@@ -29,20 +28,41 @@ module IGeTui
raise
NotImplementedError
,
'Must be implemented by subtypes.'
end
def
get_client_data
(
pusher
)
string
=
self
.
get_transparent
(
pusher
).
serialize_to_string
Base64
.
strict_encode64
string
end
def
get_push_info
@push_info
||
init_push_info
end
# 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
,
badge:
badge
,
message:
message
,
sound:
sound
})
@push_info
.
update_properties
(
args
)
init_push_info
@push_info
.
actionLocKey
=
action_loc_key
@push_info
.
badge
=
badge
.
to_s
@push_info
.
message
=
message
@push_info
.
sound
=
sound
@push_info
.
payload
=
options
[
:payload
]
@push_info
.
locKey
=
options
[
:loc_key
]
@push_info
.
locArgs
=
options
[
:loc_args
]
@push_info
.
launchImage
=
options
[
:launch_image
]
# validate method need refactoring.
Validate
.
new
.
validate
(
args
)
# Validate.new.validate(args)
end
private
def
init_push_info
@push_info
=
GtReq
::
PushInfo
.
new
@push_info
.
message
=
''
@push_info
.
actionKey
=
''
@push_info
.
sound
=
''
@push_info
.
badge
=
''
@push_info
end
...
...
lib/igetui/validate.rb
View file @
66a6f5b9
require
'json'
module
IGeTui
class
Validate
def
validate
(
args
=
{})
payload_map
=
get_payload
(
args
)
#
payload_map = get_payload(args)
json
=
JSON
.
generate
payload_map
if
(
json
.
length
>
256
)
raise
ArgumentError
.
new
(
"PushInfo length over limit:
#{
json
.
length
}
. Allowed: 256."
)
# json = JSON.generate payload_map
# if (json.length > 256)
# raise ArgumentError.new("PushInfo length over limit: #{json.length}. Allowed: 256.")
# end
is_validate
=
validate_payload
(
args
)
unless
is_validate
payload_len
=
validate_payload_length
(
args
)
raise
ArgumentError
.
new
(
"PushInfo length over limit:
#{
payload_len
.
length
}
. Allowed: 256."
)
end
end
def
validate_payload
(
args
)
length
=
validate_payload_length
(
args
)
length
<=
256
end
def
validate_payload_length
(
args
)
json
=
process_payload
(
args
)
json
.
length
end
def
process_payload
(
args
)
is_valid
=
false
pb
=
Payload
.
new
if
!
args
[
:loc_key
].
nil?
&&
args
[
:loc_key
].
length
>
0
pb
.
alert_loc_key
=
args
[
:loc_key
]
if
!
args
[
:loc_args
].
nil?
&&
args
[
:loc_args
].
length
>
0
pb
.
alert_loc_args
=
args
[
:loc_args
].
split
(
","
)
end
is_valid
=
true
end
if
!
args
[
:message
].
nil?
&&
args
[
:message
].
length
>
0
pb
.
alert_body
=
args
[
:message
]
is_valid
=
true
end
if
!
args
[
:action_loc_key
].
nil?
&&
args
[
:action_loc_key
].
length
>
0
pb
.
alert_action_loc_key
=
args
[
:action_loc_key
]
end
if
!
args
[
:launch_image
].
nil?
&&
args
[
:launch_image
].
length
>
0
pb
.
alert_launch_image
=
args
[
:launch_image
]
end
badge_num
=
args
[
:badge
].
to_i
if
badge_num
>=
0
pb
.
badge
=
badge_num
is_valid
=
true
end
if
!
args
[
:sound
].
nil?
&&
args
[
:sound
].
length
>
0
pb
.
sound
=
args
[
:sound
]
end
if
!
args
[
:payload
].
nil?
&&
args
[
:payload
].
length
>
0
pb
.
add_param
(
"payload"
,
payload
)
end
unless
is_valid
puts
"one of the params(locKey,message,badge) must not be null"
end
json
=
pb
.
to_s
if
json
.
nil?
puts
"payload json is null"
end
json
# do something
end
def
get_payload
(
args
=
{})
...
...
lib/igetui/version.rb
View file @
66a6f5b9
module
IGeTui
VERSION
=
"1.
1
.0"
VERSION
=
"1.
2
.0"
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