module TelphinApi::Authorization

A module containing the methods for authorization.

@note `TelphinApi::Authorization` extends `TelphinApi` so these methods should be called from the latter.

Constants

OPTIONS

Authorization options.

Public Instance Methods

authorization_url() click to toggle source

Not used for this strategy

@raise [NotImplementedError]

# File lib/telphin_api/authorization.rb, line 19
def authorization_url
  fail(NotImplementedError, 'The authorization endpoint is not used in this strategy')
end
authorize(options = {}) click to toggle source

Authorization (getting the access token and building a `TelphinApi::Client` with it). @raise [ArgumentError] raises after receiving an unknown authorization type. @return [TelphinApi::Client] An API client.

# File lib/telphin_api/authorization.rb, line 26
def authorize(options = {})
  options[:client_id] ||= TelphinApi.app_key
  options[:client_secret] ||= TelphinApi.app_secret
  token = client.client_credentials.get_token(options, OPTIONS[:client_credentials].dup)
  Client.new(token)
end

Private Instance Methods

client() click to toggle source
# File lib/telphin_api/authorization.rb, line 34
def client
  @client ||= OAuth2::Client.new(TelphinApi.app_key, TelphinApi.app_secret, {site: TelphinApi.site}.merge(OPTIONS[:client]))
end