simple_gcm 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +15 -0
- data/Gemfile.lock +35 -0
- data/LICENSE.txt +20 -0
- data/README.md +54 -0
- data/Rakefile +49 -0
- data/VERSION +1 -0
- data/lib/simple_gcm/error.rb +40 -0
- data/lib/simple_gcm/message.rb +26 -0
- data/lib/simple_gcm/result.rb +17 -0
- data/lib/simple_gcm/result_middleware.rb +39 -0
- data/lib/simple_gcm/sender.rb +37 -0
- data/lib/simple_gcm.rb +10 -0
- data/simple_gcm.gemspec +68 -0
- data/spec/gcm_spec.rb +48 -0
- data/spec/spec_helper.rb +12 -0
- metadata +147 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "rspec", "~> 2.10.0"
|
10
|
+
gem "rdoc", "~> 3.12"
|
11
|
+
gem "bundler", "~> 1.1.4"
|
12
|
+
gem "jeweler", "~> 1.8.4"
|
13
|
+
end
|
14
|
+
|
15
|
+
gem "faraday"
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
diff-lcs (1.1.3)
|
5
|
+
faraday (0.8.1)
|
6
|
+
multipart-post (~> 1.1)
|
7
|
+
git (1.2.5)
|
8
|
+
jeweler (1.8.4)
|
9
|
+
bundler (~> 1.0)
|
10
|
+
git (>= 1.2.5)
|
11
|
+
rake
|
12
|
+
rdoc
|
13
|
+
json (1.7.3)
|
14
|
+
multipart-post (1.1.5)
|
15
|
+
rake (0.9.2.2)
|
16
|
+
rdoc (3.12)
|
17
|
+
json (~> 1.4)
|
18
|
+
rspec (2.10.0)
|
19
|
+
rspec-core (~> 2.10.0)
|
20
|
+
rspec-expectations (~> 2.10.0)
|
21
|
+
rspec-mocks (~> 2.10.0)
|
22
|
+
rspec-core (2.10.1)
|
23
|
+
rspec-expectations (2.10.0)
|
24
|
+
diff-lcs (~> 1.1.3)
|
25
|
+
rspec-mocks (2.10.1)
|
26
|
+
|
27
|
+
PLATFORMS
|
28
|
+
ruby
|
29
|
+
|
30
|
+
DEPENDENCIES
|
31
|
+
bundler (~> 1.1.4)
|
32
|
+
faraday
|
33
|
+
jeweler (~> 1.8.4)
|
34
|
+
rdoc (~> 3.12)
|
35
|
+
rspec (~> 2.10.0)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Leonardo Bessa
|
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/README.md
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# gcm (Google Cloud Messaging)
|
2
|
+
|
3
|
+
simple_gcm sends push notifications to Android devices via google [gcm](http://developer.android.com/guide/google/gcm/index.html).
|
4
|
+
|
5
|
+
##Installation
|
6
|
+
|
7
|
+
```console
|
8
|
+
$ gem install simple_gcm
|
9
|
+
```
|
10
|
+
|
11
|
+
##Requirements
|
12
|
+
|
13
|
+
An Android device running 2.2 or newer, its registration token, and a google API Key registered for gcm.
|
14
|
+
|
15
|
+
##Usage
|
16
|
+
|
17
|
+
Sending one notification at a time:
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
require 'simple_gcm'
|
21
|
+
sender = SimpleGCM::Sender.new(api_key: "your_api_key")
|
22
|
+
message = SimpleGCM::Message.new(:data => {alert => "your message"})
|
23
|
+
begin
|
24
|
+
result = sender.send(:registration_id => "your_phone_registration_id", :message => message)
|
25
|
+
puts result.message_id
|
26
|
+
puts result.registration_id
|
27
|
+
rescue SimpleGCM::Error::MissingRegistration => e; puts e
|
28
|
+
rescue SimpleGCM::Error::InvalidRegistration => e; puts e
|
29
|
+
rescue SimpleGCM::Error::MismatchSenderId => e; puts e
|
30
|
+
rescue SimpleGCM::Error::NotRegistered => e; puts e
|
31
|
+
rescue SimpleGCM::Error::MessageTooBig => e; puts e
|
32
|
+
rescue SimpleGCM::Error::AuthenticationError => e; puts e
|
33
|
+
rescue SimpleGCM::Error::ServerUnavailable => e; puts e
|
34
|
+
rescue SimpleGCM::Error::Unkown => e; puts e
|
35
|
+
rescue Exception => e
|
36
|
+
end
|
37
|
+
```
|
38
|
+
|
39
|
+
|
40
|
+
## Contributing to gcm
|
41
|
+
|
42
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
43
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
44
|
+
* Fork the project.
|
45
|
+
* Start a feature/bugfix branch.
|
46
|
+
* Commit and push until you are happy with your contribution.
|
47
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
48
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
49
|
+
|
50
|
+
## Copyright
|
51
|
+
|
52
|
+
Copyright (c) 2012 Leonardo Bessa. See LICENSE.txt for
|
53
|
+
further details.
|
54
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "simple_gcm"
|
18
|
+
gem.homepage = "http://github.com/leobessa/simple_gcm"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{Sends push notifications to Android devices.}
|
21
|
+
gem.description = %Q{simple_gcm sends push notifications to Android devices via google GCM}
|
22
|
+
gem.email = "leobessa@gmail.com"
|
23
|
+
gem.authors = ["Leonardo Bessa"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rspec/core'
|
29
|
+
require 'rspec/core/rake_task'
|
30
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
31
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
32
|
+
end
|
33
|
+
|
34
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
35
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
36
|
+
spec.rcov = true
|
37
|
+
end
|
38
|
+
|
39
|
+
task :default => :spec
|
40
|
+
|
41
|
+
require 'rdoc/task'
|
42
|
+
Rake::RDocTask.new do |rdoc|
|
43
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
44
|
+
|
45
|
+
rdoc.rdoc_dir = 'rdoc'
|
46
|
+
rdoc.title = "simple_gcm #{version}"
|
47
|
+
rdoc.rdoc_files.include('README*')
|
48
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
49
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.0
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module SimpleGCM::Error
|
2
|
+
class BaseError < StandardError
|
3
|
+
attr_reader :response
|
4
|
+
|
5
|
+
def initialize(ex, response = nil)
|
6
|
+
@wrapped_exception = nil
|
7
|
+
@response = response
|
8
|
+
|
9
|
+
if ex.respond_to?(:backtrace)
|
10
|
+
super(ex.message)
|
11
|
+
@wrapped_exception = ex
|
12
|
+
elsif ex.respond_to?(:each_key)
|
13
|
+
super("GCM server responded with error #{ex[:error]} and status #{ex[:status]}")
|
14
|
+
@response = ex
|
15
|
+
else
|
16
|
+
super(ex.to_s)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def backtrace
|
21
|
+
if @wrapped_exception
|
22
|
+
@wrapped_exception.backtrace
|
23
|
+
else
|
24
|
+
super
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def inspect
|
29
|
+
%(#<#{self.class}>)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
class MissingRegistration < BaseError; end
|
33
|
+
class InvalidRegistration < BaseError; end
|
34
|
+
class MismatchSenderId < BaseError; end
|
35
|
+
class NotRegistered < BaseError; end
|
36
|
+
class MessageTooBig < BaseError; end
|
37
|
+
class AuthenticationError < BaseError; end
|
38
|
+
class ServerUnavailable < BaseError; end
|
39
|
+
class Unkown < BaseError; end
|
40
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class SimpleGCM::Message
|
2
|
+
ATTRIBUTES = [:data, :collapse_key, :delay_while_idle, :time_to_live].freeze
|
3
|
+
ATTRIBUTES.each do |attr|
|
4
|
+
attr_accessor attr
|
5
|
+
end
|
6
|
+
|
7
|
+
def initialize(args = {})
|
8
|
+
@data = {}
|
9
|
+
ATTRIBUTES.each do |attr|
|
10
|
+
if (args.key?(attr))
|
11
|
+
instance_variable_set("@#{attr}", args[attr])
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def inspect
|
17
|
+
ATTRIBUTES.inject({ }) do |h, attr|
|
18
|
+
h[attr] = instance_variable_get("@#{attr}")
|
19
|
+
h
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_json
|
24
|
+
self.inspect.to_json
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
##
|
2
|
+
# Result of a GCM message request that returned HTTP status code 200.
|
3
|
+
#
|
4
|
+
# There are cases when a request is accept and the message successfully
|
5
|
+
# created, but GCM has a canonical registration id for that device. In this
|
6
|
+
# case, the server should update the registration id to avoid rejected requests
|
7
|
+
# in the future.
|
8
|
+
|
9
|
+
class SimpleGCM::Result
|
10
|
+
attr_accessor :message_id, :registration_id
|
11
|
+
def inspect
|
12
|
+
{ message_id: message_id, registration_id: registration_id }
|
13
|
+
end
|
14
|
+
def to_s
|
15
|
+
"#<#{self.class} #{inspect.to_s}>"
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module SimpleGCM
|
2
|
+
class ResultMiddleware < ::Faraday::Response::Middleware
|
3
|
+
def on_complete(env)
|
4
|
+
case env[:status]
|
5
|
+
when 200
|
6
|
+
values = response_values(env)
|
7
|
+
if values[:error]
|
8
|
+
if Error.constants.include?(values[:error].to_sym)
|
9
|
+
raise Error.const_get(values[:error]), values
|
10
|
+
else
|
11
|
+
raise Error::Unkown, values
|
12
|
+
end
|
13
|
+
else
|
14
|
+
result = Result.new
|
15
|
+
result.message_id = values[:id] if values[:id]
|
16
|
+
result.registration_id = values[:registration_id] if values[:registration_id]
|
17
|
+
env[:gcm_result] = result
|
18
|
+
end
|
19
|
+
when 401
|
20
|
+
raise Error::AuthenticationError, response_values(env)
|
21
|
+
when 500,503
|
22
|
+
raise Error::ServerUnavailable, response_values(env)
|
23
|
+
when 400...600
|
24
|
+
raise Error::Unkown, response_values(env)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def response_values(env)
|
29
|
+
body = env[:body]
|
30
|
+
base = {:status => env[:status], :headers => env[:response_headers], :body => body}
|
31
|
+
response_body = Array(body.lines.map{ |l| Hash[l.scan(/(.*)=(.*)/)] }.inject(&:merge)).inject({}) do |m,(k,v)|
|
32
|
+
m[k.downcase.to_sym] = v
|
33
|
+
m
|
34
|
+
end
|
35
|
+
response_body.merge(base)
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
class SimpleGCM::Sender
|
2
|
+
BASE_ENDPOINT_URL = 'https://android.googleapis.com'
|
3
|
+
SEND_PATH = '/gcm/send'
|
4
|
+
|
5
|
+
attr_accessor :api_key, :connection
|
6
|
+
|
7
|
+
def initialize(options)
|
8
|
+
@api_key = options.delete(:api_key)
|
9
|
+
end
|
10
|
+
|
11
|
+
def send(options)
|
12
|
+
registration_id = options.delete(:registration_id)
|
13
|
+
message = options.delete(:message)
|
14
|
+
http_parameters = { :registration_id => registration_id }
|
15
|
+
message.data.each_pair do |k,v|
|
16
|
+
http_parameters["data.#{k}"] = v.to_s
|
17
|
+
end
|
18
|
+
http_parameters[:collapse_key] = message.collapse_key if message.collapse_key
|
19
|
+
http_parameters[:delay_while_idle] = "1" if message.delay_while_idle
|
20
|
+
http_parameters[:time_to_live] = message.time_to_live if message.time_to_live
|
21
|
+
response = connection.post SEND_PATH do |req|
|
22
|
+
req.headers['Content-Type'] = 'text/plain'
|
23
|
+
req.headers['Authorization'] = "key=#{api_key}"
|
24
|
+
req.params = http_parameters
|
25
|
+
end
|
26
|
+
response.env[:gcm_result]
|
27
|
+
end
|
28
|
+
|
29
|
+
def connection
|
30
|
+
@connection ||= ::Faraday.new(:url => BASE_ENDPOINT_URL) do |faraday|
|
31
|
+
faraday.request :url_encoded # form-encode POST params
|
32
|
+
faraday.adapter ::Faraday.default_adapter # make requests with Net::HTTP
|
33
|
+
faraday.use SimpleGCM::ResultMiddleware
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
data/lib/simple_gcm.rb
ADDED
data/simple_gcm.gemspec
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "simple_gcm"
|
8
|
+
s.version = "0.0.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Leonardo Bessa"]
|
12
|
+
s.date = "2012-07-03"
|
13
|
+
s.description = "simple_gcm sends push notifications to Android devices via google GCM"
|
14
|
+
s.email = "leobessa@gmail.com"
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.md"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".rspec",
|
22
|
+
"Gemfile",
|
23
|
+
"Gemfile.lock",
|
24
|
+
"LICENSE.txt",
|
25
|
+
"README.md",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"lib/simple_gcm.rb",
|
29
|
+
"lib/simple_gcm/error.rb",
|
30
|
+
"lib/simple_gcm/message.rb",
|
31
|
+
"lib/simple_gcm/result.rb",
|
32
|
+
"lib/simple_gcm/result_middleware.rb",
|
33
|
+
"lib/simple_gcm/sender.rb",
|
34
|
+
"simple_gcm.gemspec",
|
35
|
+
"spec/gcm_spec.rb",
|
36
|
+
"spec/spec_helper.rb"
|
37
|
+
]
|
38
|
+
s.homepage = "http://github.com/leobessa/simple_gcm"
|
39
|
+
s.licenses = ["MIT"]
|
40
|
+
s.require_paths = ["lib"]
|
41
|
+
s.rubygems_version = "1.8.24"
|
42
|
+
s.summary = "Sends push notifications to Android devices."
|
43
|
+
|
44
|
+
if s.respond_to? :specification_version then
|
45
|
+
s.specification_version = 3
|
46
|
+
|
47
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
48
|
+
s.add_runtime_dependency(%q<faraday>, [">= 0"])
|
49
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.10.0"])
|
50
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
51
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.1.4"])
|
52
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
|
53
|
+
else
|
54
|
+
s.add_dependency(%q<faraday>, [">= 0"])
|
55
|
+
s.add_dependency(%q<rspec>, ["~> 2.10.0"])
|
56
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
57
|
+
s.add_dependency(%q<bundler>, ["~> 1.1.4"])
|
58
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
59
|
+
end
|
60
|
+
else
|
61
|
+
s.add_dependency(%q<faraday>, [">= 0"])
|
62
|
+
s.add_dependency(%q<rspec>, ["~> 2.10.0"])
|
63
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
64
|
+
s.add_dependency(%q<bundler>, ["~> 1.1.4"])
|
65
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
data/spec/gcm_spec.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "SimpleGCM::Sender" do
|
4
|
+
subject { SimpleGCM::Sender.new(api_key: "fake_api_key") }
|
5
|
+
context "#send" do
|
6
|
+
context "The message is processed successfully" do
|
7
|
+
it "returns a SimpleGCM::Response with message_id" do
|
8
|
+
message_id = "1:08"
|
9
|
+
subject.connection.builder.adapter :test do |stub|
|
10
|
+
stub.post('/gcm/send') { [200, {}, "id=#{message_id}"] }
|
11
|
+
end
|
12
|
+
reponse = subject.send(:registration_id => "fake_registration_id", :message => SimpleGCM::Message.new)
|
13
|
+
reponse.message_id.should == message_id
|
14
|
+
end
|
15
|
+
it "returns a SimpleGCM::Response with message_id and registration_id" do
|
16
|
+
message_id = "1:2342"
|
17
|
+
registration_id = "32"
|
18
|
+
subject.connection.builder.adapter :test do |stub|
|
19
|
+
stub.post('/gcm/send') { [200, {}, "id=#{message_id}\nregistration_id=#{registration_id}"] }
|
20
|
+
end
|
21
|
+
reponse = subject.send(:registration_id => "fake_registration_id", :message => SimpleGCM::Message.new)
|
22
|
+
reponse.message_id.should == message_id
|
23
|
+
reponse.registration_id.should == registration_id
|
24
|
+
end
|
25
|
+
end
|
26
|
+
context "The message is not processed due errors" do
|
27
|
+
%w(MissingRegistration InvalidRegistration MismatchSenderId NotRegistered MessageTooBig).each do |error|
|
28
|
+
it "raises a SimpleGCM::Error::#{error}" do
|
29
|
+
subject.connection.builder.adapter(:test){ |stub| stub.post('/gcm/send') { [200, {}, "Error=#{error}"] } }
|
30
|
+
expect { subject.send(:registration_id => "fake_registration_id", :message => SimpleGCM::Message.new) }.to raise_error(SimpleGCM::Error.const_get(error))
|
31
|
+
end
|
32
|
+
end
|
33
|
+
it "raises a SimpleGCM::Error::AuthenticationError if return status is 401" do
|
34
|
+
subject.connection.builder.adapter(:test){ |stub| stub.post('/gcm/send') { [401, {}, ""] } }
|
35
|
+
expect { subject.send(:registration_id => "fake_registration_id", :message => SimpleGCM::Message.new) }.to raise_error(SimpleGCM::Error::AuthenticationError)
|
36
|
+
end
|
37
|
+
it "raises a SimpleGCM::Error::ServerUnavailable if return status is 500" do
|
38
|
+
subject.connection.builder.adapter(:test){ |stub| stub.post('/gcm/send') { [500, {}, ""] } }
|
39
|
+
expect { subject.send(:registration_id => "fake_registration_id", :message => SimpleGCM::Message.new) }.to raise_error(SimpleGCM::Error::ServerUnavailable)
|
40
|
+
end
|
41
|
+
it "raises a SimpleGCM::Error::ServerUnavailable if return status is 503" do
|
42
|
+
subject.connection.builder.adapter(:test){ |stub| stub.post('/gcm/send') { [503, {}, ""] } }
|
43
|
+
expect { subject.send(:registration_id => "fake_registration_id", :message => SimpleGCM::Message.new) }.to raise_error(SimpleGCM::Error::ServerUnavailable)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'simple_gcm'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: simple_gcm
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Leonardo Bessa
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-07-03 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: faraday
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 2.10.0
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 2.10.0
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rdoc
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '3.12'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.12'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: bundler
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 1.1.4
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 1.1.4
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: jeweler
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 1.8.4
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 1.8.4
|
94
|
+
description: simple_gcm sends push notifications to Android devices via google GCM
|
95
|
+
email: leobessa@gmail.com
|
96
|
+
executables: []
|
97
|
+
extensions: []
|
98
|
+
extra_rdoc_files:
|
99
|
+
- LICENSE.txt
|
100
|
+
- README.md
|
101
|
+
files:
|
102
|
+
- .document
|
103
|
+
- .rspec
|
104
|
+
- Gemfile
|
105
|
+
- Gemfile.lock
|
106
|
+
- LICENSE.txt
|
107
|
+
- README.md
|
108
|
+
- Rakefile
|
109
|
+
- VERSION
|
110
|
+
- lib/simple_gcm.rb
|
111
|
+
- lib/simple_gcm/error.rb
|
112
|
+
- lib/simple_gcm/message.rb
|
113
|
+
- lib/simple_gcm/result.rb
|
114
|
+
- lib/simple_gcm/result_middleware.rb
|
115
|
+
- lib/simple_gcm/sender.rb
|
116
|
+
- simple_gcm.gemspec
|
117
|
+
- spec/gcm_spec.rb
|
118
|
+
- spec/spec_helper.rb
|
119
|
+
homepage: http://github.com/leobessa/simple_gcm
|
120
|
+
licenses:
|
121
|
+
- MIT
|
122
|
+
post_install_message:
|
123
|
+
rdoc_options: []
|
124
|
+
require_paths:
|
125
|
+
- lib
|
126
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
127
|
+
none: false
|
128
|
+
requirements:
|
129
|
+
- - ! '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
segments:
|
133
|
+
- 0
|
134
|
+
hash: -4556715408940629349
|
135
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
136
|
+
none: false
|
137
|
+
requirements:
|
138
|
+
- - ! '>='
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: '0'
|
141
|
+
requirements: []
|
142
|
+
rubyforge_project:
|
143
|
+
rubygems_version: 1.8.24
|
144
|
+
signing_key:
|
145
|
+
specification_version: 3
|
146
|
+
summary: Sends push notifications to Android devices.
|
147
|
+
test_files: []
|