Class: Jbcn::UserCredentials
- Inherits:
-
Credentials
- Object
- Credentials
- Jbcn::UserCredentials
- Defined in:
- lib/jbcn/credentials.rb
Constant Summary collapse
- AUTH_ENDPOINT =
"https://ssl.jobcan.jp/login/pc-employee/try"
Instance Attribute Summary collapse
-
#client_id ⇒ Object
readonly
Returns the value of attribute client_id.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Attributes inherited from Credentials
Instance Method Summary collapse
- #authenticate(faraday) ⇒ Object
-
#initialize(client_id:, username:, password:) ⇒ UserCredentials
constructor
A new instance of UserCredentials.
Constructor Details
#initialize(client_id:, username:, password:) ⇒ UserCredentials
Returns a new instance of UserCredentials.
43 44 45 46 47 |
# File 'lib/jbcn/credentials.rb', line 43 def initialize(client_id:, username:, password:) @client_id = client_id @username = username @password = password end |
Instance Attribute Details
#client_id ⇒ Object (readonly)
Returns the value of attribute client_id.
41 42 43 |
# File 'lib/jbcn/credentials.rb', line 41 def client_id @client_id end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
41 42 43 |
# File 'lib/jbcn/credentials.rb', line 41 def password @password end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
41 42 43 |
# File 'lib/jbcn/credentials.rb', line 41 def username @username end |
Instance Method Details
#authenticate(faraday) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/jbcn/credentials.rb', line 49 def authenticate(faraday) response = faraday.post(AUTH_ENDPOINT, params) rescue fail(AuthError.new(credentials: self)) unless response.status == 200 fail(AuthError.new(response: response)) end token = response.body[/<input type="hidden" class="token" name="token" value="([^"]+)">/, 1] unless token fail(AuthTokenNotFoundError.new(response: response)) end token end |