Class: Arb::Api::Aoc

Inherits:
Object
  • Object
show all
Defined in:
lib/arb/api/aoc.rb

Instance Method Summary collapse

Constructor Details

#initialize(cookie:) ⇒ Aoc

Returns a new instance of Aoc.



6
7
8
9
10
11
12
13
14
# File 'lib/arb/api/aoc.rb', line 6

def initialize(cookie:)
  @connection = Faraday.new(
    url: "https://adventofcode.com",
    headers: {
      "Cookie" => "session=#{cookie}",
      "User-Agent" => "github.com/fpsvogel/advent_of_ruby by [email protected]",
    }
  )
end

Instance Method Details

#input(year:, day:) ⇒ Object



16
17
18
19
20
# File 'lib/arb/api/aoc.rb', line 16

def input(year:, day:)
  logged_in {
    connection.get("/#{year}/day/#{day.delete_prefix("0")}/input")
  }
end

#instructions(year:, day:) ⇒ Object



22
23
24
25
26
# File 'lib/arb/api/aoc.rb', line 22

def instructions(year:, day:)
  logged_in {
    connection.get("/#{year}/day/#{day.delete_prefix("0")}")
  }
end

#submit(year:, day:, part:, answer:) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/arb/api/aoc.rb', line 28

def submit(year:, day:, part:, answer:)
  logged_in {
    connection.post(
      "/#{year}/day/#{day.delete_prefix("0")}/answer",
      "level=#{part}&answer=#{answer}",
    )
  }
end