gcm 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/README.md +35 -0
  2. data/gcm.gemspec +1 -1
  3. data/lib/gcm.rb +1 -1
  4. data/spec/gcm_spec.rb +16 -0
  5. metadata +3 -2
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # Google Cloud Messaging for Android (GCM)
2
+
3
+ GCM sends notifications to Android devices via [GCM](http://developer.android.com/guide/google/gcm/gcm.html).
4
+
5
+ ##Installation
6
+
7
+ $ gem install gcm
8
+
9
+ ##Requirements
10
+
11
+ 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).
12
+
13
+ ##Usage
14
+
15
+
16
+ Sending notifications:
17
+
18
+ ```ruby
19
+ gcm = GCM.new(api_key)
20
+ registration_ids= ["12", "13"] # an array of one or more client registration IDs
21
+ options = {body: data: {key: "value"}}
22
+ response = gcm.send_notification(registration_ids, options)
23
+ ```
24
+
25
+ Currently `response` is just a hash containing the response `body`, `headers` and `status`.
26
+
27
+ ##Copyright
28
+
29
+ * Copyright (c) 2012 Kashif Rasul and Shoaib Burq. See LICENSE.txt for details.
30
+
31
+ ##Thanks
32
+
33
+ This gem is based on a fork of the older Google push service:
34
+
35
+ * [Amro Mousa](https://github.com/amro/c2dm/)
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.1"
6
+ s.version = "0.0.2"
7
7
  s.authors = ["Amro Mousa", "Kashif Rasul", "Shoaib Burq"]
8
8
  s.email = ["amromousa@gmail.com", "kashif@spacialdb.com", "shoaib@spacialdb.com"]
9
9
  s.homepage = "http://github.com/spacialdb/gcm"
data/lib/gcm.rb CHANGED
@@ -45,7 +45,7 @@ class GCM
45
45
  private
46
46
 
47
47
  def build_post_body(registration_ids, options={})
48
- body = {registration_ids: registration_ids}
48
+ body = {registration_ids: registration_ids}.merge(options)
49
49
  #raise exception if options[:time_to_live] && !options[:collapse_key]
50
50
  end
51
51
 
data/spec/gcm_spec.rb CHANGED
@@ -38,5 +38,21 @@ describe GCM do
38
38
  gcm = GCM.new(api_key)
39
39
  gcm.send_notification(registration_ids).should eq({body: {}, headers: {}, status: 200})
40
40
  end
41
+
42
+ context "send notification with data" do
43
+ let!(:stub_with_data){
44
+ stub_request(:post, GCM::PUSH_URL).
45
+ with(body: "{\"registration_ids\":[\"42\"],\"data\":{\"score\":\"5x1\",\"time\":\"15:10\"}}",
46
+ headers: valid_request_headers ).
47
+ to_return(status: 200, body: "", headers: {})
48
+ }
49
+ before do
50
+ end
51
+ it "should send the data in a post request to gcm" do
52
+ gcm = GCM.new(api_key)
53
+ gcm.send_notification(registration_ids, { data: { score: "5x1", time: "15:10"} })
54
+ stub_with_data.should have_been_requested
55
+ end
56
+ end
41
57
  end
42
58
  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.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2012-06-29 00:00:00.000000000 Z
14
+ date: 2012-07-02 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: httparty
@@ -59,6 +59,7 @@ files:
59
59
  - .rspec
60
60
  - Gemfile
61
61
  - LICENSE.txt
62
+ - README.md
62
63
  - Rakefile
63
64
  - gcm.gemspec
64
65
  - lib/gcm.rb