Class: Pushr::Daemon::FcmSupport::Authenticator

Inherits:
Object
  • Object
show all
Defined in:
lib/pushr/daemon/fcm_support/authenticator.rb

Constant Summary collapse

SCOPE =
'https://www.googleapis.com/auth/firebase.messaging'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configuration, i) ⇒ Authenticator

Returns a new instance of Authenticator.



18
19
20
21
# File 'lib/pushr/daemon/fcm_support/authenticator.rb', line 18

def initialize(configuration, i)
  @configuration = configuration
  @name = "#{@configuration.app}: AuthenticatorFcm #{i}"
end

Instance Attribute Details

#configurationObject (readonly)

Returns the value of attribute configuration.



15
16
17
# File 'lib/pushr/daemon/fcm_support/authenticator.rb', line 15

def configuration
  @configuration
end

Instance Method Details

#fetch_access_tokenObject



23
24
25
26
27
28
29
30
31
32
# File 'lib/pushr/daemon/fcm_support/authenticator.rb', line 23

def fetch_access_token
  if @response.nil? || (@request_at + @response['expires_in'] < Time.now)
    Pushr::Daemon.logger.info("[#{@name}] Refresh access token")
    authorizer = fetch_credentials
    @request_at = Time.now
    @response = authorizer.fetch_access_token!
  end
  puts @response['access_token'].inspect
  @response['access_token']
end