gcm 0.0.1
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.
- data/.gitignore +49 -0
- data/.rspec +2 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +20 -0
- data/Rakefile +1 -0
- data/gcm.gemspec +23 -0
- data/lib/gcm.rb +52 -0
- data/spec/gcm_spec.rb +42 -0
- data/spec/spec_helper.rb +11 -0
- metadata +95 -0
data/.gitignore
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# rcov generated
|
2
|
+
coverage
|
3
|
+
|
4
|
+
# rdoc generated
|
5
|
+
rdoc
|
6
|
+
|
7
|
+
# yard generated
|
8
|
+
doc
|
9
|
+
.yardoc
|
10
|
+
|
11
|
+
# bundler
|
12
|
+
.bundle
|
13
|
+
|
14
|
+
# jeweler generated
|
15
|
+
pkg
|
16
|
+
|
17
|
+
# Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
|
18
|
+
#
|
19
|
+
# * Create a file at ~/.gitignore
|
20
|
+
# * Include files you want ignored
|
21
|
+
# * Run: git config --global core.excludesfile ~/.gitignore
|
22
|
+
#
|
23
|
+
# After doing this, these files will be ignored in all your git projects,
|
24
|
+
# saving you from having to 'pollute' every project you touch with them
|
25
|
+
#
|
26
|
+
# Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
|
27
|
+
#
|
28
|
+
# For MacOS:
|
29
|
+
#
|
30
|
+
.DS_Store
|
31
|
+
#
|
32
|
+
# For TextMate
|
33
|
+
#*.tmproj
|
34
|
+
#tmtags
|
35
|
+
#
|
36
|
+
# For emacs:
|
37
|
+
#*~
|
38
|
+
#\#*
|
39
|
+
#.\#*
|
40
|
+
#
|
41
|
+
# For vim:
|
42
|
+
#*.swp
|
43
|
+
|
44
|
+
bin
|
45
|
+
cache
|
46
|
+
gems
|
47
|
+
specifications
|
48
|
+
Gemfile.lock
|
49
|
+
.rvmrc
|
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Kashif Rasul and Shoaib Burq
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/gcm.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "gcm"
|
6
|
+
s.version = "0.0.1"
|
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"
|
10
|
+
s.summary = %q{send data to Android applications on Android devices}
|
11
|
+
s.description = %q{gcm is a service that helps developers send data from servers to their Android applications on Android devices.}
|
12
|
+
s.license = "MIT"
|
13
|
+
|
14
|
+
s.rubyforge_project = "gcm"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
s.add_dependency('httparty')
|
22
|
+
s.add_dependency('json')
|
23
|
+
end
|
data/lib/gcm.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require 'cgi'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
class GCM
|
6
|
+
include HTTParty
|
7
|
+
PUSH_URL = 'https://android.googleapis.com/gcm/send'
|
8
|
+
base_uri PUSH_URL
|
9
|
+
default_timeout 30
|
10
|
+
format :json
|
11
|
+
|
12
|
+
attr_accessor :timeout, :api_key
|
13
|
+
|
14
|
+
def initialize(api_key)
|
15
|
+
@api_key = api_key
|
16
|
+
end
|
17
|
+
|
18
|
+
# {
|
19
|
+
# "collapse_key": "score_update",
|
20
|
+
# "time_to_live": 108,
|
21
|
+
# "delay_while_idle": true,
|
22
|
+
# "registration_ids": ["4", "8", "15", "16", "23", "42"],
|
23
|
+
# "data" : {
|
24
|
+
# "score": "5x1",
|
25
|
+
# "time": "15:10"
|
26
|
+
# }
|
27
|
+
# }
|
28
|
+
# gcm = GCM.new(api_key)
|
29
|
+
# gcm.send_notification({registration_ids: ["4sdsx", "8sdsd"], data: {score: "5x1"}})
|
30
|
+
def send_notification(registration_ids, options = {})
|
31
|
+
post_body = build_post_body(registration_ids, options)
|
32
|
+
|
33
|
+
params = {
|
34
|
+
:body => post_body.to_json,
|
35
|
+
:headers => {
|
36
|
+
'Authorization' => "key=#{@api_key}",
|
37
|
+
'Content-Type' => 'application/json',
|
38
|
+
}
|
39
|
+
}
|
40
|
+
|
41
|
+
response = self.class.post('', params)
|
42
|
+
{body: response.body, headers: response.headers, status: response.code}
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def build_post_body(registration_ids, options={})
|
48
|
+
body = {registration_ids: registration_ids}
|
49
|
+
#raise exception if options[:time_to_live] && !options[:collapse_key]
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
data/spec/gcm_spec.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe GCM do
|
4
|
+
it "should raise an error if the api key is not provided" do
|
5
|
+
expect {GCM.new}.to raise_error
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should raise error if time_to_live is given" do
|
9
|
+
# ref: http://developer.android.com/guide/google/gcm/gcm.html#send-msg
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "sending notification" do
|
13
|
+
let(:api_key) { 'AIzaSyB-1uEai2WiUapxCs2Q0GZYzPu7Udno5aA' }
|
14
|
+
let(:registration_ids) { [ "42" ]}
|
15
|
+
let(:valid_request_body) do
|
16
|
+
{ registration_ids: registration_ids }
|
17
|
+
end
|
18
|
+
let(:valid_request_headers) do
|
19
|
+
{
|
20
|
+
"Content-Type" => 'application/json',
|
21
|
+
"Authorization" => "key=#{api_key}"
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
before(:each) do
|
26
|
+
stub_request(:post, GCM::PUSH_URL).with(
|
27
|
+
body: valid_request_body.to_json,
|
28
|
+
headers: valid_request_headers
|
29
|
+
).to_return(
|
30
|
+
# ref: http://developer.android.com/guide/google/gcm/gcm.html#success
|
31
|
+
body: {},
|
32
|
+
headers: {},
|
33
|
+
status: 200
|
34
|
+
)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should send notification using POST to GCM server" do
|
38
|
+
gcm = GCM.new(api_key)
|
39
|
+
gcm.send_notification(registration_ids).should eq({body: {}, headers: {}, status: 200})
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
require 'webmock/rspec'
|
4
|
+
|
5
|
+
require 'gcm'
|
6
|
+
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
9
|
+
config.run_all_when_everything_filtered = true
|
10
|
+
# config.filter_run :focus
|
11
|
+
end
|
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gcm
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Amro Mousa
|
9
|
+
- Kashif Rasul
|
10
|
+
- Shoaib Burq
|
11
|
+
autorequire:
|
12
|
+
bindir: bin
|
13
|
+
cert_chain: []
|
14
|
+
date: 2012-06-29 00:00:00.000000000 Z
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: httparty
|
18
|
+
requirement: !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ! '>='
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: '0'
|
24
|
+
type: :runtime
|
25
|
+
prerelease: false
|
26
|
+
version_requirements: !ruby/object:Gem::Requirement
|
27
|
+
none: false
|
28
|
+
requirements:
|
29
|
+
- - ! '>='
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: '0'
|
32
|
+
- !ruby/object:Gem::Dependency
|
33
|
+
name: json
|
34
|
+
requirement: !ruby/object:Gem::Requirement
|
35
|
+
none: false
|
36
|
+
requirements:
|
37
|
+
- - ! '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
none: false
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
description: gcm is a service that helps developers send data from servers to their
|
49
|
+
Android applications on Android devices.
|
50
|
+
email:
|
51
|
+
- amromousa@gmail.com
|
52
|
+
- kashif@spacialdb.com
|
53
|
+
- shoaib@spacialdb.com
|
54
|
+
executables: []
|
55
|
+
extensions: []
|
56
|
+
extra_rdoc_files: []
|
57
|
+
files:
|
58
|
+
- .gitignore
|
59
|
+
- .rspec
|
60
|
+
- Gemfile
|
61
|
+
- LICENSE.txt
|
62
|
+
- Rakefile
|
63
|
+
- gcm.gemspec
|
64
|
+
- lib/gcm.rb
|
65
|
+
- spec/gcm_spec.rb
|
66
|
+
- spec/spec_helper.rb
|
67
|
+
homepage: http://github.com/spacialdb/gcm
|
68
|
+
licenses:
|
69
|
+
- MIT
|
70
|
+
post_install_message:
|
71
|
+
rdoc_options: []
|
72
|
+
require_paths:
|
73
|
+
- lib
|
74
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
76
|
+
requirements:
|
77
|
+
- - ! '>='
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
requirements: []
|
87
|
+
rubyforge_project: gcm
|
88
|
+
rubygems_version: 1.8.23
|
89
|
+
signing_key:
|
90
|
+
specification_version: 3
|
91
|
+
summary: send data to Android applications on Android devices
|
92
|
+
test_files:
|
93
|
+
- spec/gcm_spec.rb
|
94
|
+
- spec/spec_helper.rb
|
95
|
+
has_rdoc:
|