gcm 0.0.9 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -1
- data/LICENSE.txt +1 -1
- data/README.md +19 -10
- data/gcm.gemspec +1 -1
- data/lib/gcm.rb +14 -0
- data/spec/gcm_spec.rb +12 -12
- 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: 2d3097180eb7e2fdcf713691a11c2d4e9dcc7d89
|
4
|
+
data.tar.gz: 8bc696acca36e7b4472a6ceaa1aa69663339e945
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2bc02dc787c817c1b4a3b6a45141f13d62672946e55c927c60cd56ff998b4f8fbef93e8ee1155a56ad62c01d7db0662f56893ec0e03a3f63c86ffbe07e46928f
|
7
|
+
data.tar.gz: 4228c061988eec7e0409bea59404ffe1c047f78a4c910738cd0008896516fcccf0268228c9705104741754198eeecb7a0b52948fa29e2912d81d07c763e79bd6
|
data/.travis.yml
CHANGED
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -15,13 +15,14 @@ gem 'gcm'
|
|
15
15
|
|
16
16
|
##Requirements
|
17
17
|
|
18
|
-
An Android device running 2.
|
18
|
+
An Android device running 2.3 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
|
|
22
22
|
* `1.9.3`
|
23
23
|
* `2.0.0`
|
24
|
-
* `2.1.
|
24
|
+
* `2.1.5`
|
25
|
+
* `2.2.0`
|
25
26
|
|
26
27
|
##Usage
|
27
28
|
|
@@ -59,11 +60,10 @@ response = gcm.create(key_name: "appUser-Chris",
|
|
59
60
|
```
|
60
61
|
|
61
62
|
### Send to Notification Key
|
62
|
-
Now you can send a message to a particular `notification_key` via the `
|
63
|
+
Now you can send a message to a particular `notification_key` via the `send_with_notification_key` method. This allows the server to send a single data to multiple app instances (typically on multiple devices) owned by a single user (instead of sending to registration IDs). Note: the maximum number of members allowed for a `notification_key` is 10.
|
63
64
|
|
64
65
|
```ruby
|
65
|
-
response = gcm.
|
66
|
-
notification_key: "appUser-Chris-key",
|
66
|
+
response = gcm.send_with_notification_key("notification_key", {
|
67
67
|
data: {score: "3x1"},
|
68
68
|
collapse_key: "updated_score"})
|
69
69
|
```
|
@@ -75,12 +75,12 @@ You can also add/remove registration IDs to/from a particular `notification_key`
|
|
75
75
|
```ruby
|
76
76
|
response = gcm.add(key_name: "appUser-Chris",
|
77
77
|
project_id: "my_project_id",
|
78
|
-
notification_key:"appUser-Chris-key"
|
78
|
+
notification_key:"appUser-Chris-key",
|
79
79
|
registration_ids:["7", "3"])
|
80
80
|
|
81
81
|
response = gcm.remove(key_name: "appUser-Chris",
|
82
82
|
project_id: "my_project_id",
|
83
|
-
notification_key:"appUser-Chris-key"
|
83
|
+
notification_key:"appUser-Chris-key",
|
84
84
|
registration_ids:["8", "15"])
|
85
85
|
```
|
86
86
|
|
@@ -90,15 +90,19 @@ response = gcm.remove(key_name: "appUser-Chris",
|
|
90
90
|
* [Как отправлять push уведомления из Вашего Rails приложения](http://habrahabr.ru/post/214607/)
|
91
91
|
* [GCM – 서버 만들기](http://susemi99.kr/1023)
|
92
92
|
* [ruby から gcm を使って android 端末へメッセージを送信する](http://qiita.com/ma2saka/items/5852308b7c2855eef552)
|
93
|
+
* [titanium alloy android push通知 by ruby](http://shoprev.hatenablog.com/entry/2014/08/30/202531)
|
93
94
|
|
94
95
|
## Android Client
|
95
96
|
|
96
|
-
You can find an Android Client app to receive notifications
|
97
|
+
You can find a guide to implement an Android Client app to receive notifications here: [Implementing GCM Client](https://developer.android.com/google/gcm/client.html).
|
97
98
|
|
98
99
|
## ChangeLog
|
99
100
|
|
101
|
+
### 0.1.0
|
102
|
+
* Added `send_with_notification_key` to send message to a notification key since the documented API for it is [wrong]( http://stackoverflow.com/questions/19720767/gcm-user-notifications-missing-registration-ids-field/25183892#25183892).
|
103
|
+
|
100
104
|
### 0.0.9
|
101
|
-
* Check for NotRegistered error and return unregistered ids if this occurs
|
105
|
+
* Check for [NotRegistered](http://developer.android.com/google/gcm/adv.html#unreg) error and return unregistered ids if this occurs
|
102
106
|
|
103
107
|
### 0.0.8
|
104
108
|
* Added support for User Notifications API
|
@@ -117,8 +121,13 @@ You can find an Android Client app to receive notifications from here: [Google C
|
|
117
121
|
|
118
122
|
##MIT License
|
119
123
|
|
120
|
-
* Copyright (c)
|
124
|
+
* Copyright (c) 2015 Kashif Rasul and Shoaib Burq. See LICENSE.txt for details.
|
121
125
|
|
122
126
|
##Many thanks to all the contributors
|
123
127
|
|
124
128
|
* [Contributors](https://github.com/spacialdb/gcm/contributors)
|
129
|
+
|
130
|
+
## Donations
|
131
|
+
We accept tips through [Gratipay](https://gratipay.com/spacialdb/).
|
132
|
+
|
133
|
+
[![Gratipay](https://img.shields.io/gratipay/spacialdb.svg)](https://www.gittip.com/spacialdb/)
|
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.1.0"
|
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
@@ -101,6 +101,20 @@ class GCM
|
|
101
101
|
end
|
102
102
|
alias_method :remove, :remove_registration_ids
|
103
103
|
|
104
|
+
def send_with_notification_key(notification_key, options)
|
105
|
+
body = { :to => notification_key }.merge(options)
|
106
|
+
|
107
|
+
params = {
|
108
|
+
:body => body.to_json,
|
109
|
+
:headers => {
|
110
|
+
'Authorization' => "key=#{@api_key}",
|
111
|
+
'Content-Type' => 'application/json',
|
112
|
+
}
|
113
|
+
}
|
114
|
+
response = self.class.post('/send', params.merge(@client_options))
|
115
|
+
build_response(response)
|
116
|
+
end
|
117
|
+
|
104
118
|
private
|
105
119
|
|
106
120
|
def build_post_body(registration_ids, options={})
|
data/spec/gcm_spec.rb
CHANGED
@@ -30,7 +30,7 @@ describe GCM do
|
|
30
30
|
:headers => valid_request_headers
|
31
31
|
).to_return(
|
32
32
|
# ref: http://developer.android.com/guide/google/gcm/gcm.html#success
|
33
|
-
:body => {},
|
33
|
+
:body => "{}",
|
34
34
|
:headers => {},
|
35
35
|
:status => 200
|
36
36
|
)
|
@@ -40,7 +40,7 @@ describe GCM do
|
|
40
40
|
uri = URI.parse(send_url)
|
41
41
|
uri.user = 'a'
|
42
42
|
uri.password = 'b'
|
43
|
-
stub_request(:post, uri.to_s).to_return(:body => {}, :headers => {}, :status => 200)
|
43
|
+
stub_request(:post, uri.to_s).to_return(:body => "{}", :headers => {}, :status => 200)
|
44
44
|
end
|
45
45
|
|
46
46
|
before(:each) do
|
@@ -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 => [], :not_registered_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 => [],:not_registered_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
|
|
@@ -93,14 +93,14 @@ describe GCM do
|
|
93
93
|
mock_request_attributes
|
94
94
|
).to_return(
|
95
95
|
# ref: http://developer.android.com/guide/google/gcm/gcm.html#success
|
96
|
-
:body => {},
|
96
|
+
:body => "{}",
|
97
97
|
:headers => {},
|
98
98
|
:status => 400
|
99
99
|
)
|
100
100
|
end
|
101
101
|
it "should not send notification due to 400" do
|
102
102
|
subject.send(registration_ids).should eq({
|
103
|
-
:body => {},
|
103
|
+
:body => "{}",
|
104
104
|
:headers => {},
|
105
105
|
:response => "Only applies for JSON requests. Indicates that the request could not be parsed as JSON, or it contained invalid fields.",
|
106
106
|
:status_code => 400
|
@@ -114,7 +114,7 @@ describe GCM do
|
|
114
114
|
mock_request_attributes
|
115
115
|
).to_return(
|
116
116
|
# ref: http://developer.android.com/guide/google/gcm/gcm.html#success
|
117
|
-
:body => {},
|
117
|
+
:body => "{}",
|
118
118
|
:headers => {},
|
119
119
|
:status => 401
|
120
120
|
)
|
@@ -122,7 +122,7 @@ describe GCM do
|
|
122
122
|
|
123
123
|
it "should not send notification due to 401" do
|
124
124
|
subject.send(registration_ids).should eq({
|
125
|
-
:body => {},
|
125
|
+
:body => "{}",
|
126
126
|
:headers => {},
|
127
127
|
:response => "There was an error authenticating the sender account.",
|
128
128
|
:status_code => 401
|
@@ -136,7 +136,7 @@ describe GCM do
|
|
136
136
|
mock_request_attributes
|
137
137
|
).to_return(
|
138
138
|
# ref: http://developer.android.com/guide/google/gcm/gcm.html#success
|
139
|
-
:body => {},
|
139
|
+
:body => "{}",
|
140
140
|
:headers => {},
|
141
141
|
:status => 503
|
142
142
|
)
|
@@ -144,7 +144,7 @@ describe GCM do
|
|
144
144
|
|
145
145
|
it "should not send notification due to 503" do
|
146
146
|
subject.send(registration_ids).should eq({
|
147
|
-
:body => {},
|
147
|
+
:body => "{}",
|
148
148
|
:headers => {},
|
149
149
|
:response => 'Server is temporarily unavailable.',
|
150
150
|
:status_code => 503
|
@@ -158,7 +158,7 @@ describe GCM do
|
|
158
158
|
mock_request_attributes
|
159
159
|
).to_return(
|
160
160
|
# ref: http://developer.android.com/guide/google/gcm/gcm.html#success
|
161
|
-
:body => {
|
161
|
+
:body => "{\"body-key\" => \"Body value\"}",
|
162
162
|
:headers => { "header-key" => "Header value" },
|
163
163
|
:status => 599
|
164
164
|
)
|
@@ -166,7 +166,7 @@ describe GCM do
|
|
166
166
|
|
167
167
|
it "should not send notification due to 599" do
|
168
168
|
subject.send(registration_ids).should eq({
|
169
|
-
:body => {
|
169
|
+
:body => "{\"body-key\" => \"Body value\"}",
|
170
170
|
:headers => { "header-key" => ["Header value"] },
|
171
171
|
:response => 'There was an internal error in the GCM server while trying to process the request.',
|
172
172
|
:status_code => 599
|
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.1.0
|
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:
|
12
|
+
date: 2015-01-15 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.4.
|
82
|
+
rubygems_version: 2.4.5
|
83
83
|
signing_key:
|
84
84
|
specification_version: 4
|
85
85
|
summary: send data to Android applications on Android devices
|