gcm 0.0.5 → 0.0.6

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: 48e5d1ac537918960d5702a017f448561502ad78
4
- data.tar.gz: 2524bc50e068dbd90fc0b2d1c5eb012011edc963
3
+ metadata.gz: e0b2ae57d4b3b71772d8a69cc595ec6272cdb7db
4
+ data.tar.gz: 1818a7075e84ea587e62a599cb6ffda67a2a925a
5
5
  SHA512:
6
- metadata.gz: 35fb8ca2fd2b83e4226a6d24a034923ce5a2281accf4261c1663873f2d3cd79c47306dcca9d9dd1e79a97ffeb3ba21477d8bc3102c63f441610634bdb3263c86
7
- data.tar.gz: 994846feefe82634bd46e0aa530367cc8e7514cb635a9d977cc29dfdd9859bf1c3b3820258d9a90e6772462e4d47552c68d6219e1421dc7c3f4e28b34a1c13b9
6
+ metadata.gz: a3fa246decd26545e799c645fc64e788a4be1cbeba209fae04e983559e665135d61f4a33fb48bbe37f18fbe7368bcb53784d02371f3f1fca6ea341d2a0cae52c
7
+ data.tar.gz: a3f675537384617d32993141954920be7604a4b687951d612d9ddf85539ff788af57433df337a91911c79646edf393d276636c4dffe9d6c965566da37d24d723
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012 Kashif Rasul and Shoaib Burq
1
+ Copyright (c) 2014 Kashif Rasul and Shoaib Burq
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -7,9 +7,15 @@ GCM sends notifications to Android devices via [GCM](http://developer.android.co
7
7
 
8
8
  $ gem install gcm
9
9
 
10
+ or in your `Gemfile` just include it:
11
+
12
+ ```ruby
13
+ gem 'gcm'
14
+ ```
15
+
10
16
  ##Requirements
11
17
 
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).
18
+ An Android device running 2.0 or newer and an API key as per [GCM getting started guide](http://developer.android.com/google/gcm).
13
19
 
14
20
  One of the following, tested Ruby versions:
15
21
 
@@ -19,22 +25,25 @@ One of the following, tested Ruby versions:
19
25
 
20
26
  ##Usage
21
27
 
22
- Sending notifications:
28
+ For your server to send a message to one or more devices, you must first initialize a new `GCM` class with your api key, and then call the `send_notification` method on this and give it 1 or more (up to 1000) registration IDs as an array of strings. You can also optionally send further [HTTP message parameters](http://developer.android.com/google/gcm/server.html#params) like `data` or `time_to_live` etc. as a hash via the second optional argument to `send_notification`.
29
+
30
+ Example sending notifications:
23
31
 
24
32
  ```ruby
25
33
  require 'gcm'
26
34
 
27
35
  gcm = GCM.new(api_key)
36
+ # you can set option parameters in here
37
+ # - all options are pass to HTTParty method arguments
38
+ # - ref: https://github.com/jnunemaker/httparty/blob/master/lib/httparty.rb#L40-L68
39
+ # gcm = GCM.new(api_key, timeout: 3)
40
+
28
41
  registration_ids= ["12", "13"] # an array of one or more client registration IDs
29
42
  options = {data: {score: "123"}, collapse_key: "updated_score"}
30
43
  response = gcm.send_notification(registration_ids, options)
31
44
  ```
32
45
 
33
- Currently `response` is just a hash containing the response `body`, `headers` and `status`.
34
-
35
- If the above code is stored in a file like `trigger_gcm.rb`, thats how you can call it.
36
-
37
- $ ruby -rubygems trigger_gcm.rb
46
+ Currently `response` is just a hash containing the response `body`, `headers` and `status`. Check [here](http://developer.android.com/google/gcm/http.html#response) to see how to interpret the responses.
38
47
 
39
48
  ## Blog posts
40
49
 
@@ -42,15 +51,19 @@ If the above code is stored in a file like `trigger_gcm.rb`, thats how you can c
42
51
 
43
52
  ## ChangeLog
44
53
 
54
+ ### 0.0.6
55
+
56
+ * You can initialize GCM class with [HTTParty Options](https://github.com/jnunemaker/httparty/blob/master/lib/httparty.rb#L40-L68)
57
+
45
58
  ### Version 0.0.5
46
59
 
47
- * Added support for canonical registration ID
60
+ * Added support for [canonical registration ID](http://developer.android.com/google/gcm/adv.html#canonical)
48
61
  * 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
62
  * Fixed Rspec deprecation warnings for Rspec 3.0.0.beta
50
63
 
51
64
  ##MIT License
52
65
 
53
- * Copyright (c) 2012 Kashif Rasul and Shoaib Burq. See LICENSE.txt for details.
66
+ * Copyright (c) 2014 Kashif Rasul and Shoaib Burq. See LICENSE.txt for details.
54
67
 
55
68
  ##Many thanks to all the contributors
56
69
 
data/Rakefile CHANGED
@@ -7,11 +7,9 @@ RSpec::Core::RakeTask.new(:spec => ["ci:setup:rspec"]) do |t|
7
7
  t.pattern = 'spec/**/*_spec.rb'
8
8
  end
9
9
 
10
-
11
10
  RSpec::Core::RakeTask.new(:spec) do |spec|
12
11
  spec.pattern = 'spec/**/*_spec.rb'
13
12
  spec.rspec_opts = ['--format documentation']
14
13
  end
15
14
 
16
-
17
15
  task :default => :spec
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.5"
6
+ s.version = "0.0.6"
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
@@ -11,8 +11,9 @@ class GCM
11
11
 
12
12
  attr_accessor :timeout, :api_key
13
13
 
14
- def initialize(api_key)
14
+ def initialize(api_key, client_options = {})
15
15
  @api_key = api_key
16
+ @client_options = client_options
16
17
  end
17
18
 
18
19
  # {
@@ -37,8 +38,7 @@ class GCM
37
38
  'Content-Type' => 'application/json',
38
39
  }
39
40
  }
40
-
41
- response = self.class.post('', params)
41
+ response = self.class.post('', params.merge(@client_options))
42
42
  build_response(response, registration_ids)
43
43
  end
44
44
 
data/spec/gcm_spec.rb CHANGED
@@ -22,7 +22,7 @@ describe GCM do
22
22
  }
23
23
  end
24
24
 
25
- before(:each) do
25
+ let(:stub_gcm_request) do
26
26
  stub_request(:post, GCM::PUSH_URL).with(
27
27
  :body => valid_request_body.to_json,
28
28
  :headers => valid_request_headers
@@ -34,9 +34,28 @@ describe GCM do
34
34
  )
35
35
  end
36
36
 
37
+ let(:stub_gcm_request_with_basic_auth) do
38
+ uri = URI.parse(GCM::PUSH_URL)
39
+ uri.user = 'a'
40
+ uri.password = 'b'
41
+ stub_request(:post, uri.to_s).to_return(:body => {}, :headers => {}, :status => 200)
42
+ end
43
+
44
+ before(:each) do
45
+ stub_gcm_request
46
+ stub_gcm_request_with_basic_auth
47
+ end
48
+
37
49
  it "should send notification using POST to GCM server" do
38
50
  gcm = GCM.new(api_key)
39
51
  gcm.send_notification(registration_ids).should eq({:response => 'success', :body => {}, :headers => {}, :status_code => 200, :canonical_ids => []})
52
+ stub_gcm_request.should have_been_made.times(1)
53
+ end
54
+
55
+ it "should use basic authentication provided by options" do
56
+ gcm = GCM.new(api_key, basic_auth: {username: 'a', password: 'b'})
57
+ gcm.send_notification(registration_ids).should eq({:response => 'success', :body => {}, :headers => {}, :status_code => 200, :canonical_ids => []})
58
+ stub_gcm_request_with_basic_auth.should have_been_made.times(1)
40
59
  end
41
60
 
42
61
  context "send notification with data" do
@@ -157,7 +176,7 @@ describe GCM do
157
176
 
158
177
  let(:valid_response_body_with_canonical_ids) do
159
178
  {
160
- :canonical_ids => 1, :results => [{:registration_id => "43", :message_id => "0:1385025861956342%572c22801bb3" }]
179
+ :canonical_ids => 1, :results => [{:registration_id => "43", :message_id => "0:1385025861956342%572c22801bb3" }]
161
180
  }
162
181
  end
163
182
 
@@ -168,23 +187,23 @@ describe GCM do
168
187
  stub_request(:post, GCM::PUSH_URL).with(
169
188
  mock_request_attributes
170
189
  ).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
190
+ # ref: http://developer.android.com/guide/google/gcm/gcm.html#success
191
+ :body => valid_response_body_with_canonical_ids.to_json,
192
+ :headers => {},
193
+ :status => 200
175
194
  )
176
195
  end
177
196
 
178
197
  it "should contain canonical_ids" do
179
198
  response = subject.send_notification(registration_ids)
180
199
 
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
- })
200
+ response.should eq({
201
+ :headers => {},
202
+ :canonical_ids => [{:old => "42", :new => "43"}],
203
+ :status_code => 200,
204
+ :response => 'success',
205
+ :body => "{\"canonical_ids\":1,\"results\":[{\"registration_id\":\"43\",\"message_id\":\"0:1385025861956342%572c22801bb3\"}]}"
206
+ })
188
207
  end
189
208
  end
190
209
  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.5
4
+ version: 0.0.6
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-01-10 00:00:00.000000000 Z
12
+ date: 2014-01-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty