Class: BeyondApi::Token

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/beyond_api/resources/token.rb

Defined Under Namespace

Classes: InvalidSessionError

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils

#handle_all_request, #handle_error, #sanitize_key, #sanitize_response, #to_object_struct

Constructor Details

#initialize(session) ⇒ Token

Returns a new instance of Token.


13
14
15
16
17
18
# File 'lib/beyond_api/resources/token.rb', line 13

def initialize(session)
  @session = session

  raise InvalidSessionError.new("Invalid session") unless session.is_a? BeyondApi::Session
  raise InvalidSessionError.new("Session api_url cannot be nil") if session.api_url.nil?
end

Instance Attribute Details

#sessionObject (readonly)

Returns the value of attribute session


11
12
13
# File 'lib/beyond_api/resources/token.rb', line 11

def session
  @session
end

Instance Method Details

#client_credentialsObject


36
37
38
39
40
41
# File 'lib/beyond_api/resources/token.rb', line 36

def client_credentials
  response, status = BeyondApi::Request.token(@session.api_url + "/oauth/token",
                                              grant_type: "client_credentials")

  handle_response(response, status)
end

#create(code) ⇒ Object


20
21
22
23
24
25
26
# File 'lib/beyond_api/resources/token.rb', line 20

def create(code)
  response, status = BeyondApi::Request.token(@session.api_url + "/oauth/token",
                                              grant_type: "authorization_code",
                                              code: code)

  handle_response(response, status)
end

#refreshObject


28
29
30
31
32
33
34
# File 'lib/beyond_api/resources/token.rb', line 28

def refresh
  response, status = BeyondApi::Request.token(@session.api_url + "/oauth/token",
                                              grant_type: "refresh_token",
                                              refresh_token: @session.refresh_token)

  handle_response(response, status)
end