Class: AocRb::AocApi

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/aoc_rb/aoc_api.rb

Instance Method Summary collapse

Constructor Details

#initialize(session) ⇒ AocApi

Returns a new instance of AocApi.



8
9
10
# File 'lib/aoc_rb/aoc_api.rb', line 8

def initialize(session)
  @options = { headers: { 'Cookie' => "session=#{session}" }, follow_redirects: false }
end

Instance Method Details

#puzzle_input(year, day) ⇒ Object



16
17
18
# File 'lib/aoc_rb/aoc_api.rb', line 16

def puzzle_input(year, day)
  self.class.get(input_path(year, day), @options)
end

#puzzle_instructions(year, day) ⇒ Object



12
13
14
# File 'lib/aoc_rb/aoc_api.rb', line 12

def puzzle_instructions(year, day)
  self.class.get(puzzle_path(year, day), @options)
end

#submit_answer(year, day, level, answer) ⇒ Object



20
21
22
23
# File 'lib/aoc_rb/aoc_api.rb', line 20

def submit_answer(year, day, level, answer)
  options_with_answer = @options.merge({ body: { level: level.to_s, answer: answer.to_s } })
  self.class.post(answer_path(year, day), options_with_answer)
end