Class: Pushr::Daemon::GcmSupport::ConnectionGcm

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#configurationObject (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

#nameObject (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

#responseObject (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

#connectObject



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.to_message)
    handle_response(response, data, retry_count)
  rescue => e
    retry_count += 1
    if retry_count < 10
      retry
    else
      raise e
    end
  end
end