Class: BRL::Auth::TokenService

Inherits:
Object
  • Object
show all
Defined in:
lib/brl/auth/token_service.rb

Instance Method Summary collapse

Constructor Details

#initialize(connection: Connection.new) ⇒ TokenService

Returns a new instance of TokenService.



6
7
8
# File 'lib/brl/auth/token_service.rb', line 6

def initialize(connection: Connection.new)
  @connection = connection
end

Instance Method Details

#retrieveObject



10
11
12
13
14
15
16
17
18
19
# File 'lib/brl/auth/token_service.rb', line 10

def retrieve
  res = @connection.post(url: BRL::Auth::TOKEN_ENDPOINT, body: BRL::Auth::TokenService.)

  return parse_response(res.body) if res.status == 200

  raise BRL::Auth::BadRequestError if res.status == 400
  raise BRL::Auth::InvalidCredentialsError if res.status == 401
  raise BRL::Auth::ServerError if res.status == 500
  raise BRL::Auth::UnexpectedError
end