gcm 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5c2094f1f941e71303802d03af0af0c60841598e
4
- data.tar.gz: 533de2aad017e25cc44b8d56af68932655869881
3
+ metadata.gz: 48e5d1ac537918960d5702a017f448561502ad78
4
+ data.tar.gz: 2524bc50e068dbd90fc0b2d1c5eb012011edc963
5
5
  SHA512:
6
- metadata.gz: b9d5138d41d34d02bffc3b8c0c6a71d61b7862b4eb9c8de5647df9cc52e127b9e5510709de0bfb13a346823588eb6740b41e4de51c7fa19ef4192a5560b2cb83
7
- data.tar.gz: a838377705386fe708f8cdfc281fba52d586c36d9da3472fe3d7086016a2ee1228ae6a22745b0049c8d5ad5d3afe25b242b61f894bf68c1b9dbbc6d164d2e648
6
+ metadata.gz: 35fb8ca2fd2b83e4226a6d24a034923ce5a2281accf4261c1663873f2d3cd79c47306dcca9d9dd1e79a97ffeb3ba21477d8bc3102c63f441610634bdb3263c86
7
+ data.tar.gz: 994846feefe82634bd46e0aa530367cc8e7514cb635a9d977cc29dfdd9859bf1c3b3820258d9a90e6772462e4d47552c68d6219e1421dc7c3f4e28b34a1c13b9
data/.travis.yml CHANGED
@@ -1,3 +1,5 @@
1
+ language: ruby
1
2
  rvm:
2
3
  - 1.9.3
3
4
  - 2.0.0
5
+ - 2.1.0
data/Gemfile CHANGED
@@ -2,6 +2,6 @@ source "https://rubygems.org"
2
2
  gemspec
3
3
 
4
4
  gem 'rake'
5
- gem 'rspec'
5
+ gem 'rspec', '~> 3.0.0.beta'
6
6
  gem 'webmock'
7
7
  gem "ci_reporter"
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # Google Cloud Messaging for Android (GCM)
2
- [![Build Status](https://secure.travis-ci.org/shamithc/gcm.png?branch=master)](http://travis-ci.org/shamithc/gcm)
2
+ [![Build Status](https://secure.travis-ci.org/spacialdb/gcm.png?branch=master)](http://travis-ci.org/spacialdb/gcm)
3
3
 
4
4
  GCM sends notifications to Android devices via [GCM](http://developer.android.com/guide/google/gcm/gcm.html).
5
5
 
@@ -11,6 +11,12 @@ GCM sends notifications to Android devices via [GCM](http://developer.android.co
11
11
 
12
12
  An Android device running 2.0 or newer and an API key as per [GCM getting started guide](http://developer.android.com/guide/google/gcm/gs.html).
13
13
 
14
+ One of the following, tested Ruby versions:
15
+
16
+ * `1.9.3`
17
+ * `2.0.0`
18
+ * `2.1.0`
19
+
14
20
  ##Usage
15
21
 
16
22
  Sending notifications:
@@ -30,6 +36,18 @@ If the above code is stored in a file like `trigger_gcm.rb`, thats how you can c
30
36
 
31
37
  $ ruby -rubygems trigger_gcm.rb
32
38
 
39
+ ## Blog posts
40
+
41
+ * [How to send iOS and Android notifications from your Rails backend](http://blog.wellwith.me/how-to-send-ios-and-android-notifications-from-your-rails-backend)
42
+
43
+ ## ChangeLog
44
+
45
+ ### Version 0.0.5
46
+
47
+ * Added support for canonical registration ID
48
+ * 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/)
49
+ * Fixed Rspec deprecation warnings for Rspec 3.0.0.beta
50
+
33
51
  ##MIT License
34
52
 
35
53
  * Copyright (c) 2012 Kashif Rasul and Shoaib Burq. See LICENSE.txt for details.
data/gcm.gemspec CHANGED
@@ -3,14 +3,17 @@ $:.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.4"
7
- s.authors = ["Amro Mousa", "Kashif Rasul", "Shoaib Burq"]
8
- s.email = ["amromousa@gmail.com", "kashif@spacialdb.com", "shoaib@spacialdb.com"]
9
- s.homepage = "http://github.com/spacialdb/gcm"
6
+ s.version = "0.0.5"
7
+ s.platform = Gem::Platform::RUBY
8
+ s.authors = ["Kashif Rasul", "Shoaib Burq"]
9
+ s.email = ["kashif@spacialdb.com", "shoaib@spacialdb.com"]
10
+ s.homepage = "https://github.com/spacialdb/gcm"
10
11
  s.summary = %q{send data to Android applications on Android devices}
11
12
  s.description = %q{gcm is a service that helps developers send data from servers to their Android applications on Android devices.}
12
13
  s.license = "MIT"
13
14
 
15
+ s.required_ruby_version = '>= 1.9.3'
16
+
14
17
  s.rubyforge_project = "gcm"
15
18
 
16
19
  s.files = `git ls-files`.split("\n")
data/lib/gcm.rb CHANGED
@@ -39,7 +39,7 @@ class GCM
39
39
  }
40
40
 
41
41
  response = self.class.post('', params)
42
- build_response(response)
42
+ build_response(response, registration_ids)
43
43
  end
44
44
 
45
45
  private
@@ -48,11 +48,11 @@ class GCM
48
48
  { :registration_ids => registration_ids }.merge(options)
49
49
  end
50
50
 
51
- def build_response(response)
51
+ def build_response(response, registration_ids)
52
52
  case response.code
53
53
  when 200
54
54
  body = response.body || {}
55
- { :response => 'success', :body => body, :headers => response.headers, :status_code => response.code }
55
+ { :response => 'success', :body => body, :headers => response.headers, :status_code => response.code, :canonical_ids => build_canonical_ids(body, registration_ids) }
56
56
  when 400
57
57
  { :response => 'Only applies for JSON requests. Indicates that the request could not be parsed as JSON, or it contained invalid fields.', :status_code => response.code }
58
58
  when 401
@@ -63,4 +63,21 @@ class GCM
63
63
  { :response => 'Server is temporarily unavailable.', :status_code => response.code }
64
64
  end
65
65
  end
66
+
67
+ def build_canonical_ids(body, registration_ids)
68
+ canonical_ids = []
69
+ unless body.empty?
70
+ body = JSON.parse(body)
71
+ if body['canonical_ids'] > 0
72
+ body['results'].each_with_index do |result, index|
73
+ canonical_ids << { :old => registration_ids[index], :new => result['registration_id'] } if has_canonical_id?(result)
74
+ end
75
+ end
76
+ end
77
+ canonical_ids
78
+ end
79
+
80
+ def has_canonical_id?(result)
81
+ !result['registration_id'].nil?
82
+ end
66
83
  end
data/spec/gcm_spec.rb CHANGED
@@ -36,13 +36,13 @@ describe GCM do
36
36
 
37
37
  it "should send notification using POST to GCM server" do
38
38
  gcm = GCM.new(api_key)
39
- gcm.send_notification(registration_ids).should eq({:response => 'success', :body => {}, :headers => {}, :status_code => 200})
39
+ gcm.send_notification(registration_ids).should eq({:response => 'success', :body => {}, :headers => {}, :status_code => 200, :canonical_ids => []})
40
40
  end
41
41
 
42
42
  context "send notification with data" do
43
43
  let!(:stub_with_data){
44
44
  stub_request(:post, GCM::PUSH_URL).
45
- with(:body => "{\"data\":{\"score\":\"5x1\",\"time\":\"15:10\"},\"registration_ids\":[\"42\"]}",
45
+ with(:body => "{\"registration_ids\":[\"42\"],\"data\":{\"score\":\"5x1\",\"time\":\"15:10\"}}",
46
46
  :headers => valid_request_headers ).
47
47
  to_return(:status => 200, :body => "", :headers => {})
48
48
  }
@@ -145,5 +145,47 @@ describe GCM do
145
145
  end
146
146
  end
147
147
  end
148
+
149
+ context " when send_notification responds canonical_ids" do
150
+
151
+ let(:mock_request_attributes) do
152
+ {
153
+ :body => valid_request_body.to_json,
154
+ :headers => valid_request_headers
155
+ }
156
+ end
157
+
158
+ let(:valid_response_body_with_canonical_ids) do
159
+ {
160
+ :canonical_ids => 1, :results => [{:registration_id => "43", :message_id => "0:1385025861956342%572c22801bb3" }]
161
+ }
162
+ end
163
+
164
+ subject { GCM.new(api_key) }
165
+
166
+
167
+ before do
168
+ stub_request(:post, GCM::PUSH_URL).with(
169
+ mock_request_attributes
170
+ ).to_return(
171
+ # ref: http://developer.android.com/guide/google/gcm/gcm.html#success
172
+ :body => valid_response_body_with_canonical_ids.to_json,
173
+ :headers => {},
174
+ :status => 200
175
+ )
176
+ end
177
+
178
+ it "should contain canonical_ids" do
179
+ response = subject.send_notification(registration_ids)
180
+
181
+ response.should eq({
182
+ :headers => {},
183
+ :canonical_ids => [{:old => "42", :new => "43"}],
184
+ :status_code => 200,
185
+ :response => 'success',
186
+ :body => "{\"canonical_ids\":1,\"results\":[{\"registration_id\":\"43\",\"message_id\":\"0:1385025861956342%572c22801bb3\"}]}"
187
+ })
188
+ end
189
+ end
148
190
  end
149
191
  end
data/spec/spec_helper.rb CHANGED
@@ -5,7 +5,9 @@ require 'webmock/rspec'
5
5
  require 'gcm'
6
6
 
7
7
  RSpec.configure do |config|
8
- config.treat_symbols_as_metadata_keys_with_true_values = true
9
8
  config.run_all_when_everything_filtered = true
9
+ config.expect_with :rspec do |c|
10
+ c.syntax = [:should, :expect]
11
+ end
10
12
  # config.filter_run :focus
11
13
  end
metadata CHANGED
@@ -1,58 +1,56 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gcm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
- - Amro Mousa
8
7
  - Kashif Rasul
9
8
  - Shoaib Burq
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2013-06-04 00:00:00.000000000 Z
12
+ date: 2014-01-10 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: httparty
17
16
  requirement: !ruby/object:Gem::Requirement
18
17
  requirements:
19
- - - '>='
18
+ - - ">="
20
19
  - !ruby/object:Gem::Version
21
20
  version: '0'
22
21
  type: :runtime
23
22
  prerelease: false
24
23
  version_requirements: !ruby/object:Gem::Requirement
25
24
  requirements:
26
- - - '>='
25
+ - - ">="
27
26
  - !ruby/object:Gem::Version
28
27
  version: '0'
29
28
  - !ruby/object:Gem::Dependency
30
29
  name: json
31
30
  requirement: !ruby/object:Gem::Requirement
32
31
  requirements:
33
- - - '>='
32
+ - - ">="
34
33
  - !ruby/object:Gem::Version
35
34
  version: '0'
36
35
  type: :runtime
37
36
  prerelease: false
38
37
  version_requirements: !ruby/object:Gem::Requirement
39
38
  requirements:
40
- - - '>='
39
+ - - ">="
41
40
  - !ruby/object:Gem::Version
42
41
  version: '0'
43
42
  description: gcm is a service that helps developers send data from servers to their
44
43
  Android applications on Android devices.
45
44
  email:
46
- - amromousa@gmail.com
47
45
  - kashif@spacialdb.com
48
46
  - shoaib@spacialdb.com
49
47
  executables: []
50
48
  extensions: []
51
49
  extra_rdoc_files: []
52
50
  files:
53
- - .gitignore
54
- - .rspec
55
- - .travis.yml
51
+ - ".gitignore"
52
+ - ".rspec"
53
+ - ".travis.yml"
56
54
  - Gemfile
57
55
  - LICENSE.txt
58
56
  - README.md
@@ -61,7 +59,7 @@ files:
61
59
  - lib/gcm.rb
62
60
  - spec/gcm_spec.rb
63
61
  - spec/spec_helper.rb
64
- homepage: http://github.com/spacialdb/gcm
62
+ homepage: https://github.com/spacialdb/gcm
65
63
  licenses:
66
64
  - MIT
67
65
  metadata: {}
@@ -71,17 +69,17 @@ require_paths:
71
69
  - lib
72
70
  required_ruby_version: !ruby/object:Gem::Requirement
73
71
  requirements:
74
- - - '>='
72
+ - - ">="
75
73
  - !ruby/object:Gem::Version
76
- version: '0'
74
+ version: 1.9.3
77
75
  required_rubygems_version: !ruby/object:Gem::Requirement
78
76
  requirements:
79
- - - '>='
77
+ - - ">="
80
78
  - !ruby/object:Gem::Version
81
79
  version: '0'
82
80
  requirements: []
83
81
  rubyforge_project: gcm
84
- rubygems_version: 2.0.0
82
+ rubygems_version: 2.2.1
85
83
  signing_key:
86
84
  specification_version: 4
87
85
  summary: send data to Android applications on Android devices