Class: Push::Daemon::GcmSupport::ConnectionGcm
- Inherits:
-
Object
- Object
- Push::Daemon::GcmSupport::ConnectionGcm
- Defined in:
- lib/push/daemon/gcm_support/connection_gcm.rb
Constant Summary collapse
- PUSH_URL =
"https://android.googleapis.com/gcm/send"
- IDLE_PERIOD =
5.minutes
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#provider ⇒ Object
readonly
Returns the value of attribute provider.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
- #connect ⇒ Object
-
#initialize(provider, i) ⇒ ConnectionGcm
constructor
A new instance of ConnectionGcm.
- #write(data) ⇒ Object
Constructor Details
#initialize(provider, i) ⇒ ConnectionGcm
Returns a new instance of ConnectionGcm.
11 12 13 14 |
# File 'lib/push/daemon/gcm_support/connection_gcm.rb', line 11 def initialize(provider, i) @provider = provider @name = "#{@provider.configuration[:name]}: ConnectionGcm #{i}" end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/push/daemon/gcm_support/connection_gcm.rb', line 7 def name @name end |
#provider ⇒ Object (readonly)
Returns the value of attribute provider.
7 8 9 |
# File 'lib/push/daemon/gcm_support/connection_gcm.rb', line 7 def provider @provider end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
7 8 9 |
# File 'lib/push/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/push/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 Push::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 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/push/daemon/gcm_support/connection_gcm.rb', line 24 def write(data) @response = notification_request(data) # if @response.code.eql? "200" # puts "success, but can have an exception in " # elsif @response.code.eql? "400" # puts "formatting exception" # elsif @response.code.eql? "401" # puts "authentication exception" # elsif @response.code.eql? "500" # puts "internal error GCM server" # elsif response.code.eql? "503" # puts "service un-available: exponential back-off" # # # do not retry for now # # # @response.header.each_header do |key, value| # # if key.capitalize == "Retry-After".capitalize # # # TODO USE DELAY # # @delay_by = value # # end # # end # # TODO or exponentional back-off # end end |