Class: Aocli::AdventOfCode::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/aocli/advent_of_code/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeClient

Returns a new instance of Client.

Raises:

  • (StandardError)


18
19
20
21
22
# File 'lib/aocli/advent_of_code/client.rb', line 18

def initialize
  @cookie = Aocli::Config.value_for(:cookie)
  @conn = initialise_conn_object
  raise(StandardError, "No cookie is set") unless @cookie
end

Instance Attribute Details

#connObject (readonly)

Returns the value of attribute conn.



17
18
19
# File 'lib/aocli/advent_of_code/client.rb', line 17

def conn
  @conn
end

Instance Method Details

#get_problem_description(year:, day:) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/aocli/advent_of_code/client.rb', line 42

def get_problem_description(year:, day:)
  res = conn.get("/#{year}/day/#{day}")
  case res.status
  when 200
    Response.new(status: res.status, body: res.body, should_retry: false)
  when 404
    Response.new(
      status: res.status,
      body: res.body,
      should_retry: res.body.include?("Please don't repeatedly request this endpoint before it unlocks!"),
    )
  else
    Response.new(
      status: res.status,
      body: res.body,
      should_retry: false,
    )
  end
end

#get_problem_inputs(year:, day:) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/aocli/advent_of_code/client.rb', line 24

def get_problem_inputs(year:, day:)
  res = conn.get("/#{year}/day/#{day}/input")
  case res.status
  when 200
    Response.new(
      status: res.status,
      body: res.body,
      should_retry: false,
    )
  else
    Response.new(
      status: res.status,
      body: res.body,
      should_retry: false,
    )
  end
end