dr-apns 0.1.5 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/apns/core.rb +26 -8
- metadata +2 -2
data/lib/apns/core.rb
CHANGED
@@ -64,7 +64,28 @@ module APNS
|
|
64
64
|
return self.has_connection?(self.host, self.port)
|
65
65
|
end
|
66
66
|
|
67
|
+
def self.validate_message(message)
|
68
|
+
if message.is_a?(Hash)
|
69
|
+
if message.to_json.bytesize > 256
|
70
|
+
raise "Message(json) bytesize > 256"
|
71
|
+
end
|
72
|
+
elsif message.is_a?(String)
|
73
|
+
if message.bytesize > 256
|
74
|
+
raise "Message bytesize > 256"
|
75
|
+
end
|
76
|
+
else
|
77
|
+
raise "Message needs to be either a hash or string"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def self.validate_messages(notifications)
|
82
|
+
notifications.each do |n|
|
83
|
+
self.validate_message(n[1])
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
67
87
|
def self.send_notification(device_token, message)
|
88
|
+
self.validate_message(message)
|
68
89
|
self.with_notification_connection do |conn|
|
69
90
|
conn.write(self.packaged_notification(device_token, message))
|
70
91
|
conn.flush
|
@@ -72,6 +93,7 @@ module APNS
|
|
72
93
|
end
|
73
94
|
|
74
95
|
def self.send_notifications(notifications)
|
96
|
+
self.validate_messages(notifications)
|
75
97
|
self.with_notification_connection do |conn|
|
76
98
|
notifications.each do |n|
|
77
99
|
conn.write(self.packaged_notification(n[0], n[1]))
|
@@ -80,14 +102,16 @@ module APNS
|
|
80
102
|
end
|
81
103
|
end
|
82
104
|
|
83
|
-
def self.
|
105
|
+
def self.send_notification_async(device_token, message)
|
106
|
+
self.validate_message(message)
|
84
107
|
thread = Thread.new do
|
85
108
|
self.send_notification(device_token, message)
|
86
109
|
end
|
87
110
|
return thread
|
88
111
|
end
|
89
112
|
|
90
|
-
def self.
|
113
|
+
def self.send_notifications_async(notifications)
|
114
|
+
self.validate_messages(notifications)
|
91
115
|
thread = Thread.new do
|
92
116
|
self.send_notifications(notifications)
|
93
117
|
end
|
@@ -135,14 +159,8 @@ module APNS
|
|
135
159
|
|
136
160
|
def self.packaged_message(message)
|
137
161
|
if message.is_a?(Hash)
|
138
|
-
if message.to_json.bytesize > 256
|
139
|
-
raise "Message(json) bytesize > 256"
|
140
|
-
end
|
141
162
|
message.to_json
|
142
163
|
elsif message.is_a?(String)
|
143
|
-
if message.bytesize > 256
|
144
|
-
raise "Message bytesize > 256"
|
145
|
-
end
|
146
164
|
'{"aps":{"alert":"'+ message + '"}}'
|
147
165
|
else
|
148
166
|
raise "Message needs to be either a hash or string"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dr-apns
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire: apns
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-06-
|
12
|
+
date: 2012-06-28 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Simple Apple push notification service gem
|
15
15
|
email: dongriab@gmail.com
|