class AocCli::Tools::Request

Attributes

base[R]
day[R]
page[R]
ua[R]
user[R]
year[R]

Public Class Methods

new(u:Metafile.get(:user), y:Metafile.get(:year), d:Metafile.get(:day), p:) click to toggle source
# File lib/aoc_cli/tools.rb, line 6
def initialize(u:Metafile.get(:user),
                           y:Metafile.get(:year),
                           d:Metafile.get(:day), p:)
        @user = Validate.user(u)
        @year = Validate.year(y)
        @day  = d
        @page = p
        @base = "https://adventofcode.com/#{year}"
        @ua   = "github.com/apexatoll/aoc-cli"
end

Protected Instance Methods

get() click to toggle source
# File lib/aoc_cli/tools.rb, line 17
def get
        Curl.get(url) do |h| 
                h.headers['Cookie']     = cookie
                h.headers['User-Agent'] = ua
        end.body
end
post(data:) click to toggle source
# File lib/aoc_cli/tools.rb, line 23
def post(data:)
        Curl.post(url, data) do |h| 
                h.headers['Cookie']     = cookie
                h.headers['User-Agent'] = ua
        end.body
end

Private Instance Methods

url() click to toggle source
# File lib/aoc_cli/tools.rb, line 33
def url
        case page.to_sym
        when :Calendar then base 
        when :Stats    then base + "/leaderboard/self"
        when :Puzzle   then base + "/day/#{day}"
        when :Input    then base + "/day/#{day}/input"
        when :Answer   then base + "/day/#{day}/answer"
        end
end