class KonoMailup::API

Classe che si occupa restituire il client di mailup configurato

Attributes

original_api[RW]

Public Class Methods

client_ready?() click to toggle source
# 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.message}" }
  false
end
new(debug: false) click to toggle source
Calls superclass method
# 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
save_tokens(token:, refresh_token:, expires_at:, expires: true) click to toggle source
# 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

Public Instance Methods

refresh_access_token() click to toggle source
# 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