Class: Maia::FCM::Credentials
- Inherits:
-
Object
- Object
- Maia::FCM::Credentials
- Defined in:
- lib/maia/fcm/credentials.rb
Constant Summary collapse
- SCOPE =
'https://www.googleapis.com/auth/firebase.messaging'.freeze
Instance Method Summary collapse
-
#initialize(path = ENV['GOOGLE_APPLICATION_CREDENTIALS'], cache: Rails.cache) ⇒ Credentials
constructor
A new instance of Credentials.
- #project ⇒ Object
- #to_h ⇒ Object
- #token ⇒ Object
Constructor Details
#initialize(path = ENV['GOOGLE_APPLICATION_CREDENTIALS'], cache: Rails.cache) ⇒ Credentials
Returns a new instance of Credentials.
8 9 10 11 |
# File 'lib/maia/fcm/credentials.rb', line 8 def initialize(path = ENV['GOOGLE_APPLICATION_CREDENTIALS'], cache: Rails.cache) @path = path @cache = cache end |
Instance Method Details
#project ⇒ Object
13 14 15 |
# File 'lib/maia/fcm/credentials.rb', line 13 def project @project ||= to_h['project_id'] end |
#to_h ⇒ Object
23 24 25 |
# File 'lib/maia/fcm/credentials.rb', line 23 def to_h @to_h ||= JSON.parse file.read end |
#token ⇒ Object
17 18 19 20 21 |
# 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 |