gcm 0.0.8 → 0.0.9
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/.travis.yml +1 -1
- data/README.md +6 -5
- data/gcm.gemspec +1 -1
- data/lib/gcm.rb +18 -1
- data/spec/gcm_spec.rb +45 -4
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dbbe0aa081da1b94de83f82e56ffb7c9cdc7869c
|
4
|
+
data.tar.gz: 319b8cab6eea37aad1f9d852ee85abf146286299
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 37a76c47d0278b570a3d161f7343038053baf627017ec4a7cf620d716436a53689348b4fc195d26e57fb0c504590aefeb21bba01a9853c25fa08f580b7884a56
|
7
|
+
data.tar.gz: ee5dc6e0ffe73ca211cfe49126bd46dca629e5ff2086fe06abbd2d756220d31046c3922a50d9d51d1ee99eb43d97b665affd9516c469b65ea3c56b8969d1a4c9
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -84,7 +84,7 @@ response = gcm.remove(key_name: "appUser-Chris",
|
|
84
84
|
registration_ids:["8", "15"])
|
85
85
|
```
|
86
86
|
|
87
|
-
## Blog
|
87
|
+
## Blog Posts
|
88
88
|
|
89
89
|
* [How to send iOS and Android notifications from your Rails backend](http://juretriglav.si/how-to-send-ios-and-android-notifications-from-your-rails-backend/)
|
90
90
|
* [Как отправлять push уведомления из Вашего Rails приложения](http://habrahabr.ru/post/214607/)
|
@@ -97,19 +97,20 @@ You can find an Android Client app to receive notifications from here: [Google C
|
|
97
97
|
|
98
98
|
## ChangeLog
|
99
99
|
|
100
|
-
|
100
|
+
### 0.0.9
|
101
|
+
* Check for NotRegistered error and return unregistered ids if this occurs
|
102
|
+
|
103
|
+
### 0.0.8
|
101
104
|
* Added support for User Notifications API
|
102
105
|
* Added alias method `send` for `send_notification`
|
103
106
|
|
104
|
-
|
107
|
+
### 0.0.7
|
105
108
|
* All responses now have a body and header hashes
|
106
109
|
|
107
110
|
### 0.0.6
|
108
|
-
|
109
111
|
* You can initialise GCM class with [HTTParty Options](https://github.com/jnunemaker/httparty/blob/master/lib/httparty.rb#L41-L69)
|
110
112
|
|
111
113
|
### 0.0.5
|
112
|
-
|
113
114
|
* Added support for [canonical registration ID](http://developer.android.com/google/gcm/adv.html#canonical)
|
114
115
|
* 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/)
|
115
116
|
* Fixed Rspec deprecation warnings for Rspec 3.0.0.beta
|
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.9"
|
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
@@ -113,7 +113,9 @@ class GCM
|
|
113
113
|
case response.code
|
114
114
|
when 200
|
115
115
|
response_hash[:response] = 'success'
|
116
|
+
body = JSON.parse(body) unless body.empty?
|
116
117
|
response_hash[:canonical_ids] = build_canonical_ids(body, registration_ids) unless registration_ids.empty?
|
118
|
+
response_hash[:not_registered_ids] = build_not_registered_ids(body,registration_ids) unless registration_ids.empty?
|
117
119
|
when 400
|
118
120
|
response_hash[:response] = 'Only applies for JSON requests. Indicates that the request could not be parsed as JSON, or it contained invalid fields.'
|
119
121
|
when 401
|
@@ -129,7 +131,6 @@ class GCM
|
|
129
131
|
def build_canonical_ids(body, registration_ids)
|
130
132
|
canonical_ids = []
|
131
133
|
unless body.empty?
|
132
|
-
body = JSON.parse(body)
|
133
134
|
if body['canonical_ids'] > 0
|
134
135
|
body['results'].each_with_index do |result, index|
|
135
136
|
canonical_ids << { :old => registration_ids[index], :new => result['registration_id'] } if has_canonical_id?(result)
|
@@ -139,7 +140,23 @@ class GCM
|
|
139
140
|
canonical_ids
|
140
141
|
end
|
141
142
|
|
143
|
+
def build_not_registered_ids(body, registration_id)
|
144
|
+
not_registered_ids = []
|
145
|
+
unless body.empty?
|
146
|
+
if body['failure'] > 0
|
147
|
+
body['results'].each_with_index do |result,index|
|
148
|
+
not_registered_ids << registration_id[index] if is_not_registered?(result)
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
not_registered_ids
|
153
|
+
end
|
154
|
+
|
142
155
|
def has_canonical_id?(result)
|
143
156
|
!result['registration_id'].nil?
|
144
157
|
end
|
158
|
+
|
159
|
+
def is_not_registered?(result)
|
160
|
+
result['error'] == 'NotRegistered'
|
161
|
+
end
|
145
162
|
end
|
data/spec/gcm_spec.rb
CHANGED
@@ -50,13 +50,13 @@ describe GCM do
|
|
50
50
|
|
51
51
|
it "should send notification using POST to GCM server" do
|
52
52
|
gcm = GCM.new(api_key)
|
53
|
-
gcm.send(registration_ids).should eq({:response => 'success', :body => {}, :headers => {}, :status_code => 200, :canonical_ids => []})
|
53
|
+
gcm.send(registration_ids).should eq({:response => 'success', :body => {}, :headers => {}, :status_code => 200, :canonical_ids => [], :not_registered_ids => []})
|
54
54
|
stub_gcm_send_request.should have_been_made.times(1)
|
55
55
|
end
|
56
56
|
|
57
57
|
it "should use basic authentication provided by options" do
|
58
58
|
gcm = GCM.new(api_key, basic_auth: {username: 'a', password: 'b'})
|
59
|
-
gcm.send(registration_ids).should eq({:response => 'success', :body => {}, :headers => {}, :status_code => 200, :canonical_ids => []})
|
59
|
+
gcm.send(registration_ids).should eq({:response => 'success', :body => {}, :headers => {}, :status_code => 200, :canonical_ids => [],:not_registered_ids => []})
|
60
60
|
stub_gcm_send_request_with_basic_auth.should have_been_made.times(1)
|
61
61
|
end
|
62
62
|
|
@@ -186,7 +186,7 @@ describe GCM do
|
|
186
186
|
|
187
187
|
let(:valid_response_body_with_canonical_ids) do
|
188
188
|
{
|
189
|
-
:canonical_ids => 1, :results => [{:registration_id => "43", :message_id => "0:1385025861956342%572c22801bb3" }]
|
189
|
+
:failure => 0, :canonical_ids => 1, :results => [{:registration_id => "43", :message_id => "0:1385025861956342%572c22801bb3" }]
|
190
190
|
}
|
191
191
|
end
|
192
192
|
|
@@ -210,11 +210,52 @@ describe GCM do
|
|
210
210
|
response.should eq({
|
211
211
|
:headers => {},
|
212
212
|
:canonical_ids => [{:old => "42", :new => "43"}],
|
213
|
+
:not_registered_ids => [],
|
213
214
|
:status_code => 200,
|
214
215
|
:response => 'success',
|
215
|
-
:body => "{\"canonical_ids\":1,\"results\":[{\"registration_id\":\"43\",\"message_id\":\"0:1385025861956342%572c22801bb3\"}]}"
|
216
|
+
:body => "{\"failure\":0,\"canonical_ids\":1,\"results\":[{\"registration_id\":\"43\",\"message_id\":\"0:1385025861956342%572c22801bb3\"}]}"
|
216
217
|
})
|
217
218
|
end
|
218
219
|
end
|
220
|
+
|
221
|
+
context "when send_notification responds with NotRegistered" do
|
222
|
+
|
223
|
+
subject { GCM.new(api_key) }
|
224
|
+
|
225
|
+
let(:mock_request_attributes) do
|
226
|
+
{
|
227
|
+
:body => valid_request_body.to_json,
|
228
|
+
:headers => valid_request_headers
|
229
|
+
}
|
230
|
+
end
|
231
|
+
|
232
|
+
let(:valid_response_body_with_not_registered_ids) do
|
233
|
+
{
|
234
|
+
:canonical_ids => 0, :failure => 1, :results => [{ :error => "NotRegistered" }]
|
235
|
+
}
|
236
|
+
end
|
237
|
+
|
238
|
+
before do
|
239
|
+
stub_request(:post,send_url).with(
|
240
|
+
mock_request_attributes
|
241
|
+
).to_return(
|
242
|
+
:body => valid_response_body_with_not_registered_ids.to_json,
|
243
|
+
:headers => {},
|
244
|
+
:status => 200
|
245
|
+
)
|
246
|
+
end
|
247
|
+
|
248
|
+
it "should contain not_registered_ids" do
|
249
|
+
response = subject.send(registration_ids)
|
250
|
+
response.should eq(
|
251
|
+
:headers => {},
|
252
|
+
:canonical_ids => [],
|
253
|
+
:not_registered_ids => registration_ids,
|
254
|
+
:status_code => 200,
|
255
|
+
:response => 'success',
|
256
|
+
:body => "{\"canonical_ids\":0,\"failure\":1,\"results\":[{\"error\":\"NotRegistered\"}]}"
|
257
|
+
)
|
258
|
+
end
|
259
|
+
end
|
219
260
|
end
|
220
261
|
end
|
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.9
|
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-08
|
12
|
+
date: 2014-10-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: httparty
|
@@ -79,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
79
79
|
version: '0'
|
80
80
|
requirements: []
|
81
81
|
rubyforge_project: gcm
|
82
|
-
rubygems_version: 2.
|
82
|
+
rubygems_version: 2.4.2
|
83
83
|
signing_key:
|
84
84
|
specification_version: 4
|
85
85
|
summary: send data to Android applications on Android devices
|