Class: SimpleGCM::Sender
- Inherits:
-
Object
- Object
- SimpleGCM::Sender
- Defined in:
- lib/simple_gcm/sender.rb
Constant Summary collapse
- BASE_ENDPOINT_URL =
'https://android.googleapis.com'
- SEND_PATH =
'/gcm/send'
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#connection ⇒ Object
Returns the value of attribute connection.
Instance Method Summary collapse
-
#initialize(options) ⇒ Sender
constructor
A new instance of Sender.
- #send(options) ⇒ Object
Constructor Details
#initialize(options) ⇒ Sender
Returns a new instance of Sender.
7 8 9 |
# File 'lib/simple_gcm/sender.rb', line 7 def initialize() @api_key = .delete(:api_key) end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
5 6 7 |
# File 'lib/simple_gcm/sender.rb', line 5 def api_key @api_key end |
#connection ⇒ Object
Returns the value of attribute connection.
5 6 7 |
# File 'lib/simple_gcm/sender.rb', line 5 def connection @connection end |
Instance Method Details
#send(options) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/simple_gcm/sender.rb', line 11 def send() registration_id = .delete(:registration_id) = .delete(:message) http_parameters = { :registration_id => registration_id } .data.each_pair do |k,v| http_parameters["data.#{k}"] = v.to_s end http_parameters[:collapse_key] = .collapse_key if .collapse_key http_parameters[:delay_while_idle] = "1" if .delay_while_idle http_parameters[:time_to_live] = .time_to_live if .time_to_live response = connection.post SEND_PATH do |req| req.headers['Content-Type'] = 'text/plain' req.headers['Authorization'] = "key=#{api_key}" req.params = http_parameters end response.env[:gcm_result] end |