class AocRb::AocApi

Public Class Methods

new(session) click to toggle source
# File lib/aoc_rb/aoc_api.rb, line 8
def initialize(session)
  @options = { headers: { 'Cookie' => "session=#{session}" }, follow_redirects: false }
end

Public Instance Methods

puzzle_input(year, day) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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

Private Instance Methods

answer_path(year, day) click to toggle source
# File lib/aoc_rb/aoc_api.rb, line 34
def answer_path(year, day)
  puzzle_path(year, day) + "/answer"
end
input_path(year, day) click to toggle source
# File lib/aoc_rb/aoc_api.rb, line 30
def input_path(year, day)
  puzzle_path(year, day) + "/input"
end
puzzle_path(year, day) click to toggle source
# File lib/aoc_rb/aoc_api.rb, line 26
def puzzle_path(year, day)
  "/#{year}/day/#{day}"
end