Class: KonoMailup::API
- Inherits:
-
MailUp::API
- Object
- MailUp::API
- KonoMailup::API
- Defined in:
- lib/kono_mailup/api.rb
Overview
Classe che si occupa restituire il client di mailup configurato
Instance Attribute Summary collapse
-
#original_api ⇒ Object
Returns the value of attribute original_api.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(debug: false) ⇒ API
constructor
A new instance of API.
- #refresh_access_token ⇒ Object
Constructor Details
#initialize(debug: false) ⇒ API
Returns a new instance of API.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/kono_mailup/api.rb', line 19 def initialize(debug: false) # build up file path/name in var tmpname... @original_api = MailUp::API.new({ client_id: KonoMailup.mailup_client_id, client_secret: KonoMailup.mailup_client_secret, oauth: { token: KonoMailup::Cfg.token, refresh_token: KonoMailup::Cfg.refresh_token, expires_at: KonoMailup::Cfg.expires_at } }, debug) super(@original_api) refresh_access_token end |
Instance Attribute Details
#original_api ⇒ Object
Returns the value of attribute original_api.
8 9 10 |
# File 'lib/kono_mailup/api.rb', line 8 def original_api @original_api end |
Class Method Details
.client_ready? ⇒ Boolean
10 11 12 13 14 15 16 17 |
# File 'lib/kono_mailup/api.rb', line 10 def self.client_ready? #TODO could be made better? self.new true rescue Exception => e Rails.logger.warn { "MailupClient not responding, #{e.}" } false end |
.save_tokens(token:, refresh_token:, expires_at:, expires: true) ⇒ Object
51 52 53 54 55 56 |
# File 'lib/kono_mailup/api.rb', line 51 def self.save_tokens(token:, refresh_token:, expires_at:, expires: true) KonoMailup::Cfg.token=token KonoMailup::Cfg.refresh_token=refresh_token KonoMailup::Cfg.expires_at=expires_at KonoMailup::Cfg.expires=expires end |
Instance Method Details
#refresh_access_token ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/kono_mailup/api.rb', line 38 def refresh_access_token if self.access_token if self.access_token.expired? self.access_token = self.access_token.refresh! API.save_tokens(token: self.access_token.token, refresh_token: self.access_token.refresh_token, expires_at: self.access_token.expires_at) end end end |