Class: AocCli::Core::Repository

Inherits:
Object
  • Object
show all
Defined in:
lib/aoc_cli/core/repository.rb

Constant Summary collapse

HOST =
"https://adventofcode.com".freeze
RESOURCES =
{
  stats: {
    url: "%{host}/%{year}",
    scope: "html/body/main/pre",
    method: :get
  },

  puzzle: {
    url: "%{host}/%{year}/day/%{day}",
    scope: "html/body/main/article",
    method: :get
  },

  input: {
    url: "%{host}/%{year}/day/%{day}/input",
    method: :get
  },

  solution: {
    url: "%{host}/%{year}/day/%{day}/answer",
    scope: "html/body/main/article",
    method: :post,
    params: %i[level answer]
  }
}.freeze

Class Method Summary collapse

Class Method Details

.get_input(year:, day:) ⇒ Object



43
44
45
# File 'lib/aoc_cli/core/repository.rb', line 43

def get_input(year:, day:)
  build_resource(:input, year:, day:).fetch
end

.get_puzzle(year:, day:) ⇒ Object



39
40
41
# File 'lib/aoc_cli/core/repository.rb', line 39

def get_puzzle(year:, day:)
  build_resource(:puzzle, year:, day:).fetch_markdown
end

.get_stats(year:) ⇒ Object



33
34
35
36
37
# File 'lib/aoc_cli/core/repository.rb', line 33

def get_stats(year:)
  html = build_resource(:stats, year:).fetch

  StatsParser.new(html).to_h
end

.post_solution(year:, day:, level:, answer:) ⇒ Object



47
48
49
50
51
52
53
# File 'lib/aoc_cli/core/repository.rb', line 47

def post_solution(year:, day:, level:, answer:)
  response = build_resource(
    :solution, year:, day:, level:, answer:
  ).fetch_markdown

  AttemptParser.new(response).to_h
end