class SptyAPI::Authorization
Constants
- ACCOUNT_API
Attributes
access_token[RW]
errors[RW]
expires_in[RW]
scope[RW]
token_type[RW]
Public Class Methods
new(type:)
click to toggle source
# File lib/spty_api/authorization.rb, line 10 def initialize(type:) if type == 'client_credentials' self.class.via_client_credentials(self) end end
via_client_credentials(auth)
click to toggle source
# File lib/spty_api/authorization.rb, line 16 def self.via_client_credentials(auth) auth.login end
Public Instance Methods
login()
click to toggle source
# File lib/spty_api/authorization.rb, line 20 def login client_id = SptyAPI.configuration.client_id secret_key = SptyAPI.configuration.secret_key auth_cred = Base64.strict_encode64("#{client_id}:#{secret_key}") http = SptyAPI::HTTP::Client.new( http_method: 'post', token_type: 'Basic', access_token: auth_cred, endpoint: 'token' ) http.api_overwrite = ACCOUNT_API http.content_type_overwrite = 'application/x-www-form-urlencoded' http.body_parameter = 'grant_type=client_credentials' res = JSON.parse(http.request.read_body) res['access_token'] ? authorize(res) : reject(res) end
reject(res)
click to toggle source
# File lib/spty_api/authorization.rb, line 53 def reject(res) self.authorized = false self.errors = res end
Private Instance Methods
setup_credentials()
click to toggle source
# File lib/spty_api/authorization.rb, line 60 def setup_credentials end