Skip to content

Commit

Permalink
rename project to simple_gcm
Browse files Browse the repository at this point in the history
  • Loading branch information
leobessa committed Jul 3, 2012
1 parent 9f1f5c7 commit cfd4943
Show file tree
Hide file tree
Showing 12 changed files with 52 additions and 57 deletions.
26 changes: 13 additions & 13 deletions README.md
Original file line number Original file line Diff line number Diff line change
@@ -1,11 +1,11 @@
# gcm (Google Cloud Messaging) # gcm (Google Cloud Messaging)


gcm sends push notifications to Android devices via google [gcm](http://developer.android.com/guide/google/gcm/index.html). simple_gcm sends push notifications to Android devices via google [gcm](http://developer.android.com/guide/google/gcm/index.html).


##Installation ##Installation


```console ```console
$ gem install gcm $ gem install simple_gcm
``` ```


##Requirements ##Requirements
Expand All @@ -17,21 +17,21 @@ An Android device running 2.2 or newer, its registration token, and a google API
Sending one notification at a time: Sending one notification at a time:


```ruby ```ruby
require 'gcm' require 'simple_gcm'
sender = GCM::Sender.new(api_key: "your_api_key") sender = SimpleGCM::Sender.new(api_key: "your_api_key")
message = GCM::Message.new(:data => {alert => "your message"}) message = SimpleGCM::Message.new(:data => {alert => "your message"})
begin begin
result = sender.send(:registration_id => "your_phone_registration_id", :message => message) result = sender.send(:registration_id => "your_phone_registration_id", :message => message)
puts result.message_id puts result.message_id
puts result.registration_id puts result.registration_id
rescue GCM::Error::MissingRegistration => e; puts e rescue SimpleGCM::Error::MissingRegistration => e; puts e
rescue GCM::Error::InvalidRegistration => e; puts e rescue SimpleGCM::Error::InvalidRegistration => e; puts e
rescue GCM::Error::MismatchSenderId => e; puts e rescue SimpleGCM::Error::MismatchSenderId => e; puts e
rescue GCM::Error::NotRegistered => e; puts e rescue SimpleGCM::Error::NotRegistered => e; puts e
rescue GCM::Error::MessageTooBig => e; puts e rescue SimpleGCM::Error::MessageTooBig => e; puts e
rescue GCM::Error::AuthenticationError => e; puts e rescue SimpleGCM::Error::AuthenticationError => e; puts e
rescue GCM::Error::ServerUnavailable => e; puts e rescue SimpleGCM::Error::ServerUnavailable => e; puts e
rescue GCM::Error::Unkown => e; puts e rescue SimpleGCM::Error::Unkown => e; puts e
rescue Exception => e rescue Exception => e
end end
``` ```
Expand Down
8 changes: 4 additions & 4 deletions Rakefile
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ require 'rake'
require 'jeweler' require 'jeweler'
Jeweler::Tasks.new do |gem| Jeweler::Tasks.new do |gem|
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
gem.name = "gcm" gem.name = "simple_gcm"
gem.homepage = "http://github.com/leobessa/gcm" gem.homepage = "http://github.com/leobessa/simple_gcm"
gem.license = "MIT" gem.license = "MIT"
gem.summary = %Q{Sends push notifications to Android devices.} gem.summary = %Q{Sends push notifications to Android devices.}
gem.description = %Q{gcm sends push notifications to Android devices via google GCM} gem.description = %Q{simple_gcm sends push notifications to Android devices via google GCM}
gem.email = "leobessa@gmail.com" gem.email = "leobessa@gmail.com"
gem.authors = ["Leonardo Bessa"] gem.authors = ["Leonardo Bessa"]
# dependencies defined in Gemfile # dependencies defined in Gemfile
Expand All @@ -43,7 +43,7 @@ Rake::RDocTask.new do |rdoc|
version = File.exist?('VERSION') ? File.read('VERSION') : "" version = File.exist?('VERSION') ? File.read('VERSION') : ""


rdoc.rdoc_dir = 'rdoc' rdoc.rdoc_dir = 'rdoc'
rdoc.title = "gcm #{version}" rdoc.title = "simple_gcm #{version}"
rdoc.rdoc_files.include('README*') rdoc.rdoc_files.include('README*')
rdoc.rdoc_files.include('lib/**/*.rb') rdoc.rdoc_files.include('lib/**/*.rb')
end end
10 changes: 0 additions & 10 deletions lib/gcm.rb

This file was deleted.

10 changes: 10 additions & 0 deletions lib/simple_gcm.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,10 @@
require 'faraday'

module SimpleGCM
end

require_relative 'simple_gcm/message'
require_relative 'simple_gcm/sender'
require_relative 'simple_gcm/result_middleware'
require_relative 'simple_gcm/result'
require_relative 'simple_gcm/error'
2 changes: 1 addition & 1 deletion lib/gcm/error.rb → lib/simple_gcm/error.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,4 +1,4 @@
module GCM::Error module SimpleGCM::Error
class BaseError < StandardError class BaseError < StandardError
attr_reader :response attr_reader :response


Expand Down
2 changes: 1 addition & 1 deletion lib/gcm/message.rb → lib/simple_gcm/message.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,4 +1,4 @@
class GCM::Message class SimpleGCM::Message
ATTRIBUTES = [:data, :collapse_key, :delay_while_idle, :time_to_live].freeze ATTRIBUTES = [:data, :collapse_key, :delay_while_idle, :time_to_live].freeze
ATTRIBUTES.each do |attr| ATTRIBUTES.each do |attr|
attr_accessor attr attr_accessor attr
Expand Down
2 changes: 1 addition & 1 deletion lib/gcm/result.rb → lib/simple_gcm/result.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# case, the server should update the registration id to avoid rejected requests # case, the server should update the registration id to avoid rejected requests
# in the future. # in the future.


class GCM::Result class SimpleGCM::Result
attr_accessor :message_id, :registration_id attr_accessor :message_id, :registration_id
def inspect def inspect
{ message_id: message_id, registration_id: registration_id } { message_id: message_id, registration_id: registration_id }
Expand Down
Original file line number Original file line Diff line number Diff line change
@@ -1,4 +1,4 @@
module GCM module SimpleGCM
class ResultMiddleware < ::Faraday::Response::Middleware class ResultMiddleware < ::Faraday::Response::Middleware
def on_complete(env) def on_complete(env)
case env[:status] case env[:status]
Expand Down
4 changes: 2 additions & 2 deletions lib/gcm/sender.rb → lib/simple_gcm/sender.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,4 +1,4 @@
class GCM::Sender class SimpleGCM::Sender
BASE_ENDPOINT_URL = 'https://android.googleapis.com' BASE_ENDPOINT_URL = 'https://android.googleapis.com'
SEND_PATH = '/gcm/send' SEND_PATH = '/gcm/send'


Expand Down Expand Up @@ -30,7 +30,7 @@ def connection
@connection ||= ::Faraday.new(:url => BASE_ENDPOINT_URL) do |faraday| @connection ||= ::Faraday.new(:url => BASE_ENDPOINT_URL) do |faraday|
faraday.request :url_encoded # form-encode POST params faraday.request :url_encoded # form-encode POST params
faraday.adapter ::Faraday.default_adapter # make requests with Net::HTTP faraday.adapter ::Faraday.default_adapter # make requests with Net::HTTP
faraday.use GCM::ResultMiddleware faraday.use SimpleGCM::ResultMiddleware
end end
end end


Expand Down
13 changes: 4 additions & 9 deletions gcm.gemspec → simple_gcm.gemspec
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
# -*- encoding: utf-8 -*- # -*- encoding: utf-8 -*-


Gem::Specification.new do |s| Gem::Specification.new do |s|
s.name = "gcm" s.name = "simple_gcm"
s.version = "0.0.0" s.version = "0.0.0"


s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Leonardo Bessa"] s.authors = ["Leonardo Bessa"]
s.date = "2012-07-03" s.date = "2012-07-03"
s.description = "gcm sends push notifications to Android devices via google GCM" s.description = "simple_gcm sends push notifications to Android devices via google GCM"
s.email = "leobessa@gmail.com" s.email = "leobessa@gmail.com"
s.extra_rdoc_files = [ s.extra_rdoc_files = [
"LICENSE.txt", "LICENSE.txt",
Expand All @@ -25,16 +25,11 @@ Gem::Specification.new do |s|
"README.md", "README.md",
"Rakefile", "Rakefile",
"VERSION", "VERSION",
"lib/gcm.rb", "gcm.gemspec",
"lib/gcm/error.rb",
"lib/gcm/message.rb",
"lib/gcm/result.rb",
"lib/gcm/result_middleware.rb",
"lib/gcm/sender.rb",
"spec/gcm_spec.rb", "spec/gcm_spec.rb",
"spec/spec_helper.rb" "spec/spec_helper.rb"
] ]
s.homepage = "http://github.com/leobessa/gcm" s.homepage = "http://github.com/leobessa/simple_gcm"
s.licenses = ["MIT"] s.licenses = ["MIT"]
s.require_paths = ["lib"] s.require_paths = ["lib"]
s.rubygems_version = "1.8.24" s.rubygems_version = "1.8.24"
Expand Down
28 changes: 14 additions & 14 deletions spec/gcm_spec.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,46 +1,46 @@
require File.expand_path(File.dirname(__FILE__) + '/spec_helper') require File.expand_path(File.dirname(__FILE__) + '/spec_helper')


describe "GCM::Sender" do describe "SimpleGCM::Sender" do
subject { GCM::Sender.new(api_key: "fake_api_key") } subject { SimpleGCM::Sender.new(api_key: "fake_api_key") }
context "#send" do context "#send" do
context "The message is processed successfully" do context "The message is processed successfully" do
it "returns a GCM::Response with message_id" do it "returns a SimpleGCM::Response with message_id" do
message_id = "1:08" message_id = "1:08"
subject.connection.builder.adapter :test do |stub| subject.connection.builder.adapter :test do |stub|
stub.post('/gcm/send') { [200, {}, "id=#{message_id}"] } stub.post('/gcm/send') { [200, {}, "id=#{message_id}"] }
end end
reponse = subject.send(:registration_id => "fake_registration_id", :message => GCM::Message.new) reponse = subject.send(:registration_id => "fake_registration_id", :message => SimpleGCM::Message.new)
reponse.message_id.should == message_id reponse.message_id.should == message_id
end end
it "returns a GCM::Response with message_id and registration_id" do it "returns a SimpleGCM::Response with message_id and registration_id" do
message_id = "1:2342" message_id = "1:2342"
registration_id = "32" registration_id = "32"
subject.connection.builder.adapter :test do |stub| subject.connection.builder.adapter :test do |stub|
stub.post('/gcm/send') { [200, {}, "id=#{message_id}\nregistration_id=#{registration_id}"] } stub.post('/gcm/send') { [200, {}, "id=#{message_id}\nregistration_id=#{registration_id}"] }
end end
reponse = subject.send(:registration_id => "fake_registration_id", :message => GCM::Message.new) reponse = subject.send(:registration_id => "fake_registration_id", :message => SimpleGCM::Message.new)
reponse.message_id.should == message_id reponse.message_id.should == message_id
reponse.registration_id.should == registration_id reponse.registration_id.should == registration_id
end end
end end
context "The message is not processed due errors" do context "The message is not processed due errors" do
%w(MissingRegistration InvalidRegistration MismatchSenderId NotRegistered MessageTooBig).each do |error| %w(MissingRegistration InvalidRegistration MismatchSenderId NotRegistered MessageTooBig).each do |error|
it "raises a GCM::Error::#{error}" do it "raises a SimpleGCM::Error::#{error}" do
subject.connection.builder.adapter(:test){ |stub| stub.post('/gcm/send') { [200, {}, "Error=#{error}"] } } subject.connection.builder.adapter(:test){ |stub| stub.post('/gcm/send') { [200, {}, "Error=#{error}"] } }
expect { subject.send(:registration_id => "fake_registration_id", :message => GCM::Message.new) }.to raise_error(GCM::Error.const_get(error)) expect { subject.send(:registration_id => "fake_registration_id", :message => SimpleGCM::Message.new) }.to raise_error(SimpleGCM::Error.const_get(error))
end end
end end
it "raises a GCM::Error::AuthenticationError if return status is 401" do it "raises a SimpleGCM::Error::AuthenticationError if return status is 401" do
subject.connection.builder.adapter(:test){ |stub| stub.post('/gcm/send') { [401, {}, ""] } } subject.connection.builder.adapter(:test){ |stub| stub.post('/gcm/send') { [401, {}, ""] } }
expect { subject.send(:registration_id => "fake_registration_id", :message => GCM::Message.new) }.to raise_error(GCM::Error::AuthenticationError) expect { subject.send(:registration_id => "fake_registration_id", :message => SimpleGCM::Message.new) }.to raise_error(SimpleGCM::Error::AuthenticationError)
end end
it "raises a GCM::Error::ServerUnavailable if return status is 500" do it "raises a SimpleGCM::Error::ServerUnavailable if return status is 500" do
subject.connection.builder.adapter(:test){ |stub| stub.post('/gcm/send') { [500, {}, ""] } } subject.connection.builder.adapter(:test){ |stub| stub.post('/gcm/send') { [500, {}, ""] } }
expect { subject.send(:registration_id => "fake_registration_id", :message => GCM::Message.new) }.to raise_error(GCM::Error::ServerUnavailable) expect { subject.send(:registration_id => "fake_registration_id", :message => SimpleGCM::Message.new) }.to raise_error(SimpleGCM::Error::ServerUnavailable)
end end
it "raises a GCM::Error::ServerUnavailable if return status is 503" do it "raises a SimpleGCM::Error::ServerUnavailable if return status is 503" do
subject.connection.builder.adapter(:test){ |stub| stub.post('/gcm/send') { [503, {}, ""] } } subject.connection.builder.adapter(:test){ |stub| stub.post('/gcm/send') { [503, {}, ""] } }
expect { subject.send(:registration_id => "fake_registration_id", :message => GCM::Message.new) }.to raise_error(GCM::Error::ServerUnavailable) expect { subject.send(:registration_id => "fake_registration_id", :message => SimpleGCM::Message.new) }.to raise_error(SimpleGCM::Error::ServerUnavailable)
end end
end end
end end
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,7 +1,7 @@
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.dirname(__FILE__)) $LOAD_PATH.unshift(File.dirname(__FILE__))
require 'rspec' require 'rspec'
require 'gcm' require 'simple_gcm'


# Requires supporting files with custom matchers and macros, etc, # Requires supporting files with custom matchers and macros, etc,
# in ./support/ and its subdirectories. # in ./support/ and its subdirectories.
Expand Down

0 comments on commit cfd4943

Please sign in to comment.