Class: Acclir::AtCoder::Connection

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

Overview

Communication with AtCoder

Constant Summary collapse

ATCODER_ROOT_URL =
"https://atcoder.jp"
"/tmp/acclir_cookie.yml"

Class Method Summary collapse

Class Method Details

.connectionObject



11
12
13
14
15
16
# File 'lib/acclir/at_coder/connection.rb', line 11

def connection
  @connection ||= Faraday.new(url: ATCODER_ROOT_URL) do |faraday|
    faraday.use :cookie_jar, jar: cookie_jar
    faraday.response :raise_error
  end
end

.get(path, &block) ⇒ Object



18
19
20
# File 'lib/acclir/at_coder/connection.rb', line 18

def get(path, &block)
  connection.get(path, &block)
end

.post(path, save_cookie: false, &block) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/acclir/at_coder/connection.rb', line 22

def post(path, save_cookie: false, &block)
  FileUtils.rm(COOKIE_JAR_FILE_PATH) if save_cookie

  connection.post(path, &block).tap do
    save_cookie_jar if save_cookie
  end
end