Class: FolioClient::Authenticator

Inherits:
Object
  • Object
show all
Defined in:
lib/folio_client/authenticator.rb

Overview

Fetch a token from the Folio API using login_params

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(login_params, connection) ⇒ Authenticator

Returns a new instance of Authenticator.



10
11
12
13
# File 'lib/folio_client/authenticator.rb', line 10

def initialize(, connection)
  @login_params = 
  @connection = connection
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



24
25
26
# File 'lib/folio_client/authenticator.rb', line 24

def connection
  @connection
end

#login_paramsObject (readonly)

Returns the value of attribute login_params.



24
25
26
# File 'lib/folio_client/authenticator.rb', line 24

def 
  @login_params
end

Class Method Details

.token(login_params, connection) ⇒ Object



6
7
8
# File 'lib/folio_client/authenticator.rb', line 6

def self.token(, connection)
  new(, connection).token
end

Instance Method Details

#tokenObject

Request an access_token



16
17
18
19
20
21
22
# File 'lib/folio_client/authenticator.rb', line 16

def token
  response = connection.post("/authn/login", .to_json)

  UnexpectedResponse.call(response) unless response.success?

  JSON.parse(response.body)["okapiToken"]
end