gcm 0.0.6 → 0.0.7
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.
- checksums.yaml +4 -4
- data/README.md +5 -2
- data/gcm.gemspec +1 -1
- data/lib/gcm.rb +10 -7
- data/spec/gcm_spec.rb +22 -14
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b91b8dd5c3122716b7790b84bf488997af4481b4
|
4
|
+
data.tar.gz: c61dcbb7792c73561ae858d02ea792dac6e8f193
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 88d2177d41c159d051057eea20c8171ab7fadb07cf5b2913005656df76fa3ddb5da451386ee299f8ca8884258b07eee1ea8f9f8e07d17b6f8151c501f918d8d6
|
7
|
+
data.tar.gz: aba44c2d89ea740c2ccf0abfef14a4d05283a0a51e979d4b5c1160b23906e9c0c8ecf53b932b94704cf2f62fe8407b4c5dfe90cfb6750a78eb0f202e0aed8695
|
data/README.md
CHANGED
@@ -15,7 +15,7 @@ gem 'gcm'
|
|
15
15
|
|
16
16
|
##Requirements
|
17
17
|
|
18
|
-
An Android device running 2.
|
18
|
+
An Android device running 2.2 or newer and an API key as per [GCM getting started guide](http://developer.android.com/google/gcm/gs.html).
|
19
19
|
|
20
20
|
One of the following, tested Ruby versions:
|
21
21
|
|
@@ -51,11 +51,14 @@ Currently `response` is just a hash containing the response `body`, `headers` an
|
|
51
51
|
|
52
52
|
## ChangeLog
|
53
53
|
|
54
|
+
## 0.0.7
|
55
|
+
* All responses now have a body and header hashes
|
56
|
+
|
54
57
|
### 0.0.6
|
55
58
|
|
56
59
|
* You can initialize GCM class with [HTTParty Options](https://github.com/jnunemaker/httparty/blob/master/lib/httparty.rb#L40-L68)
|
57
60
|
|
58
|
-
###
|
61
|
+
### 0.0.5
|
59
62
|
|
60
63
|
* Added support for [canonical registration ID](http://developer.android.com/google/gcm/adv.html#canonical)
|
61
64
|
* Only support Ruby versions [>= 1.9.3](https://www.ruby-lang.org/en/news/2014/01/10/ruby-1-9-3-will-end-on-2015/)
|
data/gcm.gemspec
CHANGED
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "gcm"
|
6
|
-
s.version = "0.0.
|
6
|
+
s.version = "0.0.7"
|
7
7
|
s.platform = Gem::Platform::RUBY
|
8
8
|
s.authors = ["Kashif Rasul", "Shoaib Burq"]
|
9
9
|
s.email = ["kashif@spacialdb.com", "shoaib@spacialdb.com"]
|
data/lib/gcm.rb
CHANGED
@@ -49,19 +49,22 @@ class GCM
|
|
49
49
|
end
|
50
50
|
|
51
51
|
def build_response(response, registration_ids)
|
52
|
+
body = response.body || {}
|
53
|
+
response_hash = {:body => body, :headers => response.headers, :status_code => response.code}
|
52
54
|
case response.code
|
53
55
|
when 200
|
54
|
-
|
55
|
-
|
56
|
+
response_hash[:response] = 'success'
|
57
|
+
response_hash[:canonical_ids] = build_canonical_ids(body, registration_ids)
|
56
58
|
when 400
|
57
|
-
|
59
|
+
response_hash[:response] = 'Only applies for JSON requests. Indicates that the request could not be parsed as JSON, or it contained invalid fields.'
|
58
60
|
when 401
|
59
|
-
|
60
|
-
when 500
|
61
|
-
{ :response => 'There was an internal error in the GCM server while trying to process the request.', :status_code => response.code }
|
61
|
+
response_hash[:response] = 'There was an error authenticating the sender account.'
|
62
62
|
when 503
|
63
|
-
|
63
|
+
response_hash[:response] = 'Server is temporarily unavailable.'
|
64
|
+
when 500..599
|
65
|
+
response_hash[:response] = 'There was an internal error in the GCM server while trying to process the request.'
|
64
66
|
end
|
67
|
+
response_hash
|
65
68
|
end
|
66
69
|
|
67
70
|
def build_canonical_ids(body, registration_ids)
|
data/spec/gcm_spec.rb
CHANGED
@@ -74,7 +74,7 @@ describe GCM do
|
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
77
|
-
context "
|
77
|
+
context "when send_notification responds with failure" do
|
78
78
|
|
79
79
|
let(:mock_request_attributes) do
|
80
80
|
{
|
@@ -98,6 +98,8 @@ describe GCM do
|
|
98
98
|
end
|
99
99
|
it "should not send notification due to 400" do
|
100
100
|
subject.send_notification(registration_ids).should eq({
|
101
|
+
:body => {},
|
102
|
+
:headers => {},
|
101
103
|
:response => "Only applies for JSON requests. Indicates that the request could not be parsed as JSON, or it contained invalid fields.",
|
102
104
|
:status_code => 400
|
103
105
|
})
|
@@ -118,13 +120,15 @@ describe GCM do
|
|
118
120
|
|
119
121
|
it "should not send notification due to 401" do
|
120
122
|
subject.send_notification(registration_ids).should eq({
|
123
|
+
:body => {},
|
124
|
+
:headers => {},
|
121
125
|
:response => "There was an error authenticating the sender account.",
|
122
126
|
:status_code => 401
|
123
127
|
})
|
124
128
|
end
|
125
129
|
end
|
126
130
|
|
127
|
-
context "on failure code
|
131
|
+
context "on failure code 503" do
|
128
132
|
before do
|
129
133
|
stub_request(:post, GCM::PUSH_URL).with(
|
130
134
|
mock_request_attributes
|
@@ -132,40 +136,44 @@ describe GCM do
|
|
132
136
|
# ref: http://developer.android.com/guide/google/gcm/gcm.html#success
|
133
137
|
:body => {},
|
134
138
|
:headers => {},
|
135
|
-
:status =>
|
139
|
+
:status => 503
|
136
140
|
)
|
137
141
|
end
|
138
142
|
|
139
|
-
it "should not send notification due to
|
143
|
+
it "should not send notification due to 503" do
|
140
144
|
subject.send_notification(registration_ids).should eq({
|
141
|
-
:
|
142
|
-
:
|
145
|
+
:body => {},
|
146
|
+
:headers => {},
|
147
|
+
:response => 'Server is temporarily unavailable.',
|
148
|
+
:status_code => 503
|
143
149
|
})
|
144
150
|
end
|
145
151
|
end
|
146
152
|
|
147
|
-
context "on failure code
|
153
|
+
context "on failure code 5xx" do
|
148
154
|
before do
|
149
155
|
stub_request(:post, GCM::PUSH_URL).with(
|
150
156
|
mock_request_attributes
|
151
157
|
).to_return(
|
152
158
|
# ref: http://developer.android.com/guide/google/gcm/gcm.html#success
|
153
|
-
:body => {},
|
154
|
-
:headers => {},
|
155
|
-
:status =>
|
159
|
+
:body => { "body-key" => "Body value" },
|
160
|
+
:headers => { "header-key" => "Header value" },
|
161
|
+
:status => 599
|
156
162
|
)
|
157
163
|
end
|
158
164
|
|
159
|
-
it "should not send notification due to
|
165
|
+
it "should not send notification due to 599" do
|
160
166
|
subject.send_notification(registration_ids).should eq({
|
161
|
-
:
|
162
|
-
:
|
167
|
+
:body => { "body-key" => "Body value" },
|
168
|
+
:headers => { "header-key" => ["Header value"] },
|
169
|
+
:response => 'There was an internal error in the GCM server while trying to process the request.',
|
170
|
+
:status_code => 599
|
163
171
|
})
|
164
172
|
end
|
165
173
|
end
|
166
174
|
end
|
167
175
|
|
168
|
-
context "
|
176
|
+
context "when send_notification responds canonical_ids" do
|
169
177
|
|
170
178
|
let(:mock_request_attributes) do
|
171
179
|
{
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gcm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kashif Rasul
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-02-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: httparty
|