Class: Jbcn::UserCredentials

Inherits:
Credentials show all
Defined in:
lib/jbcn/credentials.rb

Constant Summary collapse

AUTH_ENDPOINT =
"https://ssl.jobcan.jp/login/pc-employee/try"

Instance Attribute Summary collapse

Attributes inherited from Credentials

#token

Instance Method Summary collapse

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_idObject (readonly)

Returns the value of attribute client_id.



41
42
43
# File 'lib/jbcn/credentials.rb', line 41

def client_id
  @client_id
end

#passwordObject (readonly)

Returns the value of attribute password.



41
42
43
# File 'lib/jbcn/credentials.rb', line 41

def password
  @password
end

#usernameObject (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