class Maia::FCM::Credentials
Constants
- SCOPE
Public Class Methods
new(path = ENV['GOOGLE_APPLICATION_CREDENTIALS'], cache: Rails.cache)
click to toggle source
# File lib/maia/fcm/credentials.rb, line 8 def initialize(path = ENV['GOOGLE_APPLICATION_CREDENTIALS'], cache: Rails.cache) @path = path @cache = cache end
Public Instance Methods
project()
click to toggle source
# File lib/maia/fcm/credentials.rb, line 13 def project @project ||= to_h['project_id'] end
to_h()
click to toggle source
# File lib/maia/fcm/credentials.rb, line 23 def to_h @to_h ||= JSON.parse file.read end
token()
click to toggle source
# File lib/maia/fcm/credentials.rb, line 17 def token @cache.fetch('maia-fcm-token', expires_in: 1.hour) do credentials.fetch_access_token!['access_token'] end end
Private Instance Methods
credentials()
click to toggle source
# File lib/maia/fcm/credentials.rb, line 36 def credentials @credentials ||= Google::Auth::ServiceAccountCredentials.make_creds( json_key_io: file, scope: SCOPE ) end
file()
click to toggle source
# File lib/maia/fcm/credentials.rb, line 28 def file if @path && File.exist?(@path) File.new @path else raise Maia::Error::NoCredentials end end