Class: PixivApi::Authentication
- Inherits:
-
Object
- Object
- PixivApi::Authentication
- Defined in:
- lib/pixiv_api/authentication.rb
Defined Under Namespace
Classes: InvalidAuthError
Instance Method Summary collapse
- #body ⇒ Object
-
#initialize(id:, password:) ⇒ Authentication
constructor
A new instance of Authentication.
- #success? ⇒ Boolean
- #to_client ⇒ Object
Constructor Details
#initialize(id:, password:) ⇒ Authentication
Returns a new instance of Authentication.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/pixiv_api/authentication.rb', line 9 def initialize(id:, password:) connection = Faraday.new() do |conn| # Set default middleware conn.request :multipart conn.request :url_encoded conn.adapter Faraday.default_adapter end @response = connection.post( URI(configuration[:token_url]).path, client_id: configuration[:client_id], client_secret: configuration[:client_secret], grant_type: 'password', username: id, password: password ) raise InvalidAuthError, body['errors'].to_s unless success? end |
Instance Method Details
#body ⇒ Object
29 30 31 |
# File 'lib/pixiv_api/authentication.rb', line 29 def body @body ||= JSON.parse(@response.body).freeze end |
#success? ⇒ Boolean
41 42 43 |
# File 'lib/pixiv_api/authentication.rb', line 41 def success? @response.success? end |