Class: Acclir::AtCoder::LoginSession

Inherits:
Object
  • Object
show all
Defined in:
lib/acclir/at_coder/login_session.rb

Overview

AtCoder session

Constant Summary collapse

PATH =
"/login"

Class Method Summary collapse

Class Method Details

.create(username, password) ⇒ Object

Raises:



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/acclir/at_coder/login_session.rb', line 10

def create(username, password)
  response = Connection.post(PATH, save_cookie: true) do |req|
    req.headers["Content-Type"] = "application/x-www-form-urlencoded"
    req.body =
      URI.encode_www_form({ username: username, password: password, csrf_token: csrf_token })
  end

  raise LoginFailedError if response.headers["location"] == PATH

  true
end