speedy_gcm 0.9.0 → 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -1
- data/lib/speedy_gcm/version.rb +1 -1
- data/lib/speedy_gcm.rb +12 -0
- data/test/test_speedy_gcm.rb +15 -12
- metadata +2 -2
data/.gitignore
CHANGED
data/lib/speedy_gcm/version.rb
CHANGED
data/lib/speedy_gcm.rb
CHANGED
@@ -32,6 +32,9 @@ module SpeedyGCM
|
|
32
32
|
headers = { "Content-Type" => "application/json",
|
33
33
|
"Authorization" => "key=#{@api_key}" }
|
34
34
|
|
35
|
+
# symbolize all keys
|
36
|
+
message_opts = symbolize_keys(message_opts)
|
37
|
+
|
35
38
|
# validate the message options
|
36
39
|
message_validation(message_opts)
|
37
40
|
|
@@ -46,6 +49,14 @@ module SpeedyGCM
|
|
46
49
|
end
|
47
50
|
|
48
51
|
private
|
52
|
+
|
53
|
+
def symbolize_keys(myhash)
|
54
|
+
myhash.keys.each do |key|
|
55
|
+
myhash[(key.to_sym rescue key) || key] = myhash.delete(key)
|
56
|
+
end
|
57
|
+
return myhash
|
58
|
+
end
|
59
|
+
|
49
60
|
def message_validation(message_opts)
|
50
61
|
# check if message_opts has required info
|
51
62
|
raise ArgumentError, "registration_ids is a required param of the GCM message" unless message_opts.has_key? :registration_ids
|
@@ -67,6 +78,7 @@ module SpeedyGCM
|
|
67
78
|
|
68
79
|
# registration_ids must contain at least 1 and at most 1000 registration IDs
|
69
80
|
registration_ids = message_opts[:registration_ids]
|
81
|
+
|
70
82
|
if (registration_ids.length < 1) or (registration_ids.length > 1000)
|
71
83
|
raise ArgumentError, "registration_ids must contain at least 1 and at most 1000 registration IDs"
|
72
84
|
end
|
data/test/test_speedy_gcm.rb
CHANGED
@@ -7,6 +7,11 @@ require "net/https"
|
|
7
7
|
|
8
8
|
class TestSpeedyGCM < Test::Unit::TestCase
|
9
9
|
|
10
|
+
# If you receive an "Unavailable" error code when you try to send a GCM:
|
11
|
+
# Generate a Browser API Key from the Google APIs Console, and use it instead of the server key in the "Authorization" header. Once you do that, this error will go away.
|
12
|
+
# This is caused by a serious mistake in the GCM Documentation that states you should use a Server Key in the Authorization header (as written here: http://developer.android.com/guide/google/gcm/gs.html)
|
13
|
+
|
14
|
+
# use a "browser_api_key" - see note above!
|
10
15
|
GCM_API_KEY = "TODO - Fill in with your GCM API Key"
|
11
16
|
TEST_PHONE_GCM_REGISTRATION_ID = "TODO - Fill in with some GCM Registration ID"
|
12
17
|
|
@@ -143,35 +148,33 @@ class TestSpeedyGCM < Test::Unit::TestCase
|
|
143
148
|
end
|
144
149
|
end
|
145
150
|
|
146
|
-
should "not raise an error
|
151
|
+
should "not raise an error and send a message with a success response" do
|
147
152
|
assert_nothing_raised do
|
148
153
|
SpeedyGCM::API.set_account(GCM_API_KEY)
|
149
154
|
|
150
155
|
message_options = {}
|
151
|
-
message_options.merge!({ :registration_ids => [
|
152
|
-
message_options.merge!({ :collapse_key =>
|
153
|
-
message_options.merge!({ :data => { :
|
154
|
-
message_options.merge!({ :time_to_live => 1 })
|
156
|
+
message_options.merge!({ :registration_ids => [TEST_PHONE_GCM_REGISTRATION_ID] })
|
157
|
+
message_options.merge!({ :collapse_key => Time.now.to_s })
|
158
|
+
message_options.merge!({ :data => { :vmr_id => "3" } })
|
155
159
|
|
156
160
|
response = SpeedyGCM::API.send_notification(message_options)
|
161
|
+
|
162
|
+
assert response[:code].eql? 200
|
157
163
|
end
|
158
164
|
end
|
159
165
|
|
160
|
-
should "not raise an error and send a message with a success response" do
|
166
|
+
should "not raise an error and send a message with a success response if using strings instead of symbols for keys" do
|
161
167
|
assert_nothing_raised do
|
162
168
|
SpeedyGCM::API.set_account(GCM_API_KEY)
|
163
169
|
|
164
170
|
message_options = {}
|
165
|
-
message_options.merge!({
|
166
|
-
message_options.merge!({
|
167
|
-
message_options.merge!({
|
171
|
+
message_options.merge!({ "registration_ids" => [TEST_PHONE_GCM_REGISTRATION_ID] })
|
172
|
+
message_options.merge!({ "collapse_key" => Time.now.to_s })
|
173
|
+
message_options.merge!({ "data" => { "vmr_id" => "3" } })
|
168
174
|
|
169
175
|
response = SpeedyGCM::API.send_notification(message_options)
|
170
176
|
|
171
177
|
assert response[:code].eql? 200
|
172
|
-
|
173
|
-
# puts response[:code]
|
174
|
-
# puts response[:message]
|
175
178
|
end
|
176
179
|
end
|
177
180
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: speedy_gcm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-10-
|
12
|
+
date: 2012-10-03 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Speedy GCM efficiently sends push notifications to Android devices via
|
15
15
|
GCM (Google Cloud Messaging).
|