Class: Pushr::Daemon::FcmSupport::ConnectionFcm
- Inherits:
-
Object
- Object
- Pushr::Daemon::FcmSupport::ConnectionFcm
- Defined in:
- lib/pushr/daemon/fcm_support/connection_fcm.rb
Constant Summary collapse
- IDLE_PERIOD =
5 * 60
Instance Attribute Summary collapse
-
#authenticator ⇒ Object
readonly
Returns the value of attribute authenticator.
-
#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.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #connect ⇒ Object
-
#initialize(configuration, i) ⇒ ConnectionFcm
constructor
A new instance of ConnectionFcm.
- #write(data) ⇒ Object
Constructor Details
#initialize(configuration, i) ⇒ ConnectionFcm
Returns a new instance of ConnectionFcm.
10 11 12 13 14 15 |
# File 'lib/pushr/daemon/fcm_support/connection_fcm.rb', line 10 def initialize(configuration, i) @configuration = configuration @name = "#{@configuration.app}: ConnectionFcm #{i}" @authenticator = Pushr::Daemon::FcmSupport::Authenticator.new(configuration, i) @url = "https://fcm.googleapis.com/v1/projects/#{configuration.project_id}/messages:send" end |
Instance Attribute Details
#authenticator ⇒ Object (readonly)
Returns the value of attribute authenticator.
7 8 9 |
# File 'lib/pushr/daemon/fcm_support/connection_fcm.rb', line 7 def authenticator @authenticator end |
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
7 8 9 |
# File 'lib/pushr/daemon/fcm_support/connection_fcm.rb', line 7 def configuration @configuration end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/pushr/daemon/fcm_support/connection_fcm.rb', line 7 def name @name end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
7 8 9 |
# File 'lib/pushr/daemon/fcm_support/connection_fcm.rb', line 7 def response @response end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
7 8 9 |
# File 'lib/pushr/daemon/fcm_support/connection_fcm.rb', line 7 def url @url end |
Instance Method Details
#connect ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/pushr/daemon/fcm_support/connection_fcm.rb', line 17 def connect @last_use = Time.now uri = URI.parse(@url) @connection = open_http(uri.host, uri.port) @connection.start Pushr::Daemon.logger.info("[#{@name}] Connected to #{@url}") end |
#write(data) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/pushr/daemon/fcm_support/connection_fcm.rb', line 25 def write(data) retry_count = 0 begin response = notification_request(data.) handler = Pushr::Daemon::FcmSupport::ResponseHandler.new(response, data, retry_count) handler.handle rescue => e retry_count += 1 if retry_count < 10 retry else raise e end end end |