gcm_on_rails 0.1.2 → 0.1.3

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.
@@ -64,7 +64,7 @@ A couple of notes:
64
64
  - The api_key is the api key that you received from Google when signing up for GCM
65
65
  - Note that unlike the old C2dm on Rails, GCM on Rails switches to a simple API key for authentication. ClientLogin or OAuth2 tokens will NOT work.
66
66
  - The app_name is simply the name of the pacakge of your Android app.
67
- - GCM on Rails message requests can be either be sent in plain text or JSON format. Specify 'json' fro JSON and 'plain_text' for plain text format.
67
+ - GCM on Rails message requests can be either be sent in plain text or JSON format. Specify 'json' for JSON and 'plain_text' for plain text format.
68
68
 
69
69
  That's it, you are now ready to start creating notifications.
70
70
 
@@ -120,6 +120,13 @@ from the GCM servers are:
120
120
 
121
121
  h2. To-Do's:
122
122
 
123
+ - For some reason Gcm servers sometimes return a status code 200 with a nil 'message' key in the json returned but the
124
+ message is still sent successfully. For version 0.1.3 a nil check has been introduced to check if the message key in the json
125
+ is nil. The issue that still exists, is that if the message is nil we have no way of knowing if the message was successfully sent
126
+ just by going by the http status code 200 because HTTP status code 200 could still mean that the errors mentioned above could have
127
+ occurred. So I still consider this as temporary 'hack' until someone figures out why the Gcm servers may be sometimes sending nil
128
+ in the message object of the return json.
129
+
123
130
  - Tests, tests then some more tests. These need to be implemented.
124
131
  - Implement "broadcasting" sending and processing responses to multiple registration id's within one request. Currently only one message to a single registration id is implemented.
125
132
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.1.3
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "gcm_on_rails"
8
- s.version = "0.1.2"
8
+ s.version = "0.1.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Dennis Ondeng"]
12
- s.date = "2012-07-10"
12
+ s.date = "2012-10-08"
13
13
  s.description = "gcm_on_rails is a Ruby on Rails gem that allows you to easily incorporate Google's\n 'Google Cloud Messaging for Android' into your Rails application. This gem was derived from\n c2dm_on_rails (https://github.com/pimeys/c2dm_on_rails) after Google deprecated C2DM on June 27, 2012"
14
14
  s.email = "dondeng2@gmail.com"
15
15
  s.extra_rdoc_files = [
@@ -11,6 +11,8 @@
11
11
  class Gcm::Device < Gcm::Base
12
12
  self.table_name = "gcm_devices"
13
13
 
14
+ attr_accessible :registration_id
15
+
14
16
  has_many :notifications, :class_name => 'Gcm::Notification', :dependent => :destroy
15
17
  validates_presence_of :registration_id
16
18
  validates_uniqueness_of :registration_id
@@ -21,6 +21,13 @@ class Gcm::Notification < Gcm::Base
21
21
  #
22
22
  # This can be run from the following Rake task:
23
23
  # $ rake gcm:notifications:deliver
24
+ #
25
+ # Below is sample successful response as received from Google servers when the format is JSON
26
+ #
27
+ # response: 200;
28
+ # {:message=>"{\"multicast_id\":6085691036338669615,\"success\":1,\"failure\":0,\"canonical_ids\":0,\"results\":[{\"message_id\":\"0:1349723376618187%d702725e98d39af3\"}]}", :code=>200}
29
+ #
30
+ #
24
31
  def send_notifications(notifications = Gcm::Notification.all(:conditions => {:sent_at => nil}, :joins => :device, :readonly => false))
25
32
 
26
33
  if configatron.gcm_on_rails.delivery_format and configatron.gcm_on_rails.delivery_format == 'plain_text'
@@ -33,16 +40,22 @@ class Gcm::Notification < Gcm::Base
33
40
  api_key = Gcm::Connection.open
34
41
  if api_key
35
42
  notifications.each do |notification|
36
- #puts "sending notification #{notification.id} to device #{notification.device.registration_id}"
43
+
44
+ logger.info "notification = #{notification.inspect}"
37
45
  response = Gcm::Connection.send_notification(notification, api_key, format)
38
- #puts "response: #{response[:code]}; #{response.inspect}"
46
+ logger.info "response = #{response.inspect}"
47
+
39
48
  if response[:code] == 200
40
- if format == "json"
49
+ if response[:message].nil?
50
+ # TODO - Making this assumption might not be right. HTTP status code 200 does not really signify success
51
+ # if Gcm servers returned nil for the message
52
+ error = "success"
53
+ elsif format == "json"
41
54
  error = ""
42
55
  message_data = JSON.parse response[:message]
43
56
  success = message_data['success']
44
57
  error = message_data['results'][0]['error'] if success == 0
45
- else #format is plain text
58
+ elsif format == "plain_text" #format is plain text
46
59
  message_data = response[:message]
47
60
  error = response[:message].split('=')[1]
48
61
  end
@@ -5,7 +5,6 @@ module Gcm
5
5
  module Connection
6
6
  class << self
7
7
  def send_notification(notification, api_key, format)
8
-
9
8
  if format == 'json'
10
9
  headers = {"Content-Type" => "application/json",
11
10
  "Authorization" => "key=#{api_key}"}
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gcm_on_rails
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 29
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 2
10
- version: 0.1.2
9
+ - 3
10
+ version: 0.1.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Dennis Ondeng
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-07-10 00:00:00 Z
18
+ date: 2012-10-08 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  requirement: &id001 !ruby/object:Gem::Requirement