Class: Pushr::Daemon::GcmSupport::ConnectionGcm
- Inherits:
-
Object
- Object
- Pushr::Daemon::GcmSupport::ConnectionGcm
- Defined in:
- lib/pushr/daemon/gcm_support/connection_gcm.rb
Constant Summary collapse
- PUSH_URL =
'https://android.googleapis.com/gcm/send'- IDLE_PERIOD =
5 * 60
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
- #connect ⇒ Object
-
#initialize(configuration, i) ⇒ ConnectionGcm
constructor
A new instance of ConnectionGcm.
- #write(data) ⇒ Object
Constructor Details
#initialize(configuration, i) ⇒ ConnectionGcm
Returns a new instance of ConnectionGcm.
11 12 13 14 |
# File 'lib/pushr/daemon/gcm_support/connection_gcm.rb', line 11 def initialize(configuration, i) @configuration = configuration @name = "#{@configuration.app}: ConnectionGcm #{i}" end |
Instance Attribute Details
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
7 8 9 |
# File 'lib/pushr/daemon/gcm_support/connection_gcm.rb', line 7 def configuration @configuration end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/pushr/daemon/gcm_support/connection_gcm.rb', line 7 def name @name end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
7 8 9 |
# File 'lib/pushr/daemon/gcm_support/connection_gcm.rb', line 7 def response @response end |
Instance Method Details
#connect ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/pushr/daemon/gcm_support/connection_gcm.rb', line 16 def connect @last_use = Time.now uri = URI.parse(PUSH_URL) @connection = open_http(uri.host, uri.port) @connection.start Pushr::Daemon.logger.info("[#{@name}] Connected to #{PUSH_URL}") end |
#write(data) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/pushr/daemon/gcm_support/connection_gcm.rb', line 24 def write(data) retry_count = 0 begin response = notification_request(data.) handle_response(response, data, retry_count) rescue => e retry_count += 1 if retry_count < 10 retry else raise e end end end |