Permalink
Browse files

rename project to simple_gcm

  • Loading branch information...
1 parent 9f1f5c7 commit cfd49436489a25c98222afd67e59ae62a538065d @leobessa committed Jul 3, 2012
View
@@ -1,11 +1,11 @@
# 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
```console
-$ gem install gcm
+$ gem install simple_gcm
```
##Requirements
@@ -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:
```ruby
-require 'gcm'
-sender = GCM::Sender.new(api_key: "your_api_key")
-message = GCM::Message.new(:data => {alert => "your message"})
+require 'simple_gcm'
+sender = SimpleGCM::Sender.new(api_key: "your_api_key")
+message = SimpleGCM::Message.new(:data => {alert => "your message"})
begin
result = sender.send(:registration_id => "your_phone_registration_id", :message => message)
puts result.message_id
puts result.registration_id
-rescue GCM::Error::MissingRegistration => e; puts e
-rescue GCM::Error::InvalidRegistration => e; puts e
-rescue GCM::Error::MismatchSenderId => e; puts e
-rescue GCM::Error::NotRegistered => e; puts e
-rescue GCM::Error::MessageTooBig => e; puts e
-rescue GCM::Error::AuthenticationError => e; puts e
-rescue GCM::Error::ServerUnavailable => e; puts e
-rescue GCM::Error::Unkown => e; puts e
+rescue SimpleGCM::Error::MissingRegistration => e; puts e
+rescue SimpleGCM::Error::InvalidRegistration => e; puts e
+rescue SimpleGCM::Error::MismatchSenderId => e; puts e
+rescue SimpleGCM::Error::NotRegistered => e; puts e
+rescue SimpleGCM::Error::MessageTooBig => e; puts e
+rescue SimpleGCM::Error::AuthenticationError => e; puts e
+rescue SimpleGCM::Error::ServerUnavailable => e; puts e
+rescue SimpleGCM::Error::Unkown => e; puts e
rescue Exception => e
end
```
View
@@ -14,11 +14,11 @@ require 'rake'
require 'jeweler'
Jeweler::Tasks.new do |gem|
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
- gem.name = "gcm"
- gem.homepage = "http://github.com/leobessa/gcm"
+ gem.name = "simple_gcm"
+ gem.homepage = "http://github.com/leobessa/simple_gcm"
gem.license = "MIT"
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.authors = ["Leonardo Bessa"]
# dependencies defined in Gemfile
@@ -43,7 +43,7 @@ Rake::RDocTask.new do |rdoc|
version = File.exist?('VERSION') ? File.read('VERSION') : ""
rdoc.rdoc_dir = 'rdoc'
- rdoc.title = "gcm #{version}"
+ rdoc.title = "simple_gcm #{version}"
rdoc.rdoc_files.include('README*')
rdoc.rdoc_files.include('lib/**/*.rb')
end
View
@@ -1,10 +0,0 @@
-require 'faraday'
-
-module GCM
-end
-
-require_relative 'gcm/message'
-require_relative 'gcm/sender'
-require_relative 'gcm/result_middleware'
-require_relative 'gcm/result'
-require_relative 'gcm/error'
View
@@ -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'
@@ -1,4 +1,4 @@
-module GCM::Error
+module SimpleGCM::Error
class BaseError < StandardError
attr_reader :response
@@ -1,4 +1,4 @@
-class GCM::Message
+class SimpleGCM::Message
ATTRIBUTES = [:data, :collapse_key, :delay_while_idle, :time_to_live].freeze
ATTRIBUTES.each do |attr|
attr_accessor attr
@@ -6,7 +6,7 @@
# case, the server should update the registration id to avoid rejected requests
# in the future.
-class GCM::Result
+class SimpleGCM::Result
attr_accessor :message_id, :registration_id
def inspect
{ message_id: message_id, registration_id: registration_id }
@@ -1,4 +1,4 @@
-module GCM
+module SimpleGCM
class ResultMiddleware < ::Faraday::Response::Middleware
def on_complete(env)
case env[:status]
@@ -1,4 +1,4 @@
-class GCM::Sender
+class SimpleGCM::Sender
BASE_ENDPOINT_URL = 'https://android.googleapis.com'
SEND_PATH = '/gcm/send'
@@ -30,7 +30,7 @@ def connection
@connection ||= ::Faraday.new(:url => BASE_ENDPOINT_URL) do |faraday|
faraday.request :url_encoded # form-encode POST params
faraday.adapter ::Faraday.default_adapter # make requests with Net::HTTP
- faraday.use GCM::ResultMiddleware
+ faraday.use SimpleGCM::ResultMiddleware
end
end
@@ -4,13 +4,13 @@
# -*- encoding: utf-8 -*-
Gem::Specification.new do |s|
- s.name = "gcm"
+ s.name = "simple_gcm"
s.version = "0.0.0"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Leonardo Bessa"]
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.extra_rdoc_files = [
"LICENSE.txt",
@@ -25,16 +25,11 @@ Gem::Specification.new do |s|
"README.md",
"Rakefile",
"VERSION",
- "lib/gcm.rb",
- "lib/gcm/error.rb",
- "lib/gcm/message.rb",
- "lib/gcm/result.rb",
- "lib/gcm/result_middleware.rb",
- "lib/gcm/sender.rb",
+ "gcm.gemspec",
"spec/gcm_spec.rb",
"spec/spec_helper.rb"
]
- s.homepage = "http://github.com/leobessa/gcm"
+ s.homepage = "http://github.com/leobessa/simple_gcm"
s.licenses = ["MIT"]
s.require_paths = ["lib"]
s.rubygems_version = "1.8.24"
View
@@ -1,46 +1,46 @@
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
-describe "GCM::Sender" do
- subject { GCM::Sender.new(api_key: "fake_api_key") }
+describe "SimpleGCM::Sender" do
+ subject { SimpleGCM::Sender.new(api_key: "fake_api_key") }
context "#send" 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"
subject.connection.builder.adapter :test do |stub|
stub.post('/gcm/send') { [200, {}, "id=#{message_id}"] }
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
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"
registration_id = "32"
subject.connection.builder.adapter :test do |stub|
stub.post('/gcm/send') { [200, {}, "id=#{message_id}\nregistration_id=#{registration_id}"] }
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.registration_id.should == registration_id
end
end
context "The message is not processed due errors" do
%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}"] } }
- 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
- 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, {}, ""] } }
- 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
- 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, {}, ""] } }
- 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
- 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, {}, ""] } }
- 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
View
@@ -1,7 +1,7 @@
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.dirname(__FILE__))
require 'rspec'
-require 'gcm'
+require 'simple_gcm'
# Requires supporting files with custom matchers and macros, etc,
# in ./support/ and its subdirectories.

0 comments on commit cfd4943

Please sign in to comment.