Class: FolioClient::Authenticator
- Inherits:
-
Object
- Object
- FolioClient::Authenticator
- Defined in:
- lib/folio_client/authenticator.rb
Overview
Fetch a token from the Folio API using login_params
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#login_params ⇒ Object
readonly
Returns the value of attribute login_params.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(login_params, connection) ⇒ Authenticator
constructor
A new instance of Authenticator.
-
#token ⇒ Object
Request an access_token.
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(login_params, connection) @login_params = login_params @connection = connection end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
24 25 26 |
# File 'lib/folio_client/authenticator.rb', line 24 def connection @connection end |
#login_params ⇒ Object (readonly)
Returns the value of attribute login_params.
24 25 26 |
# File 'lib/folio_client/authenticator.rb', line 24 def login_params @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(login_params, connection) new(login_params, connection).token end |
Instance Method Details
#token ⇒ Object
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", login_params.to_json) UnexpectedResponse.call(response) unless response.success? JSON.parse(response.body)["okapiToken"] end |