class HolidayList

MyList: Used to generate a list of upcoming holidays

Constants

VERSION

Public Class Methods

configuration() click to toggle source
# File lib/holiday_list.rb, line 21
def self.configuration
  @configuration ||= Configuration.new
end
configure() { |configuration| ... } click to toggle source
# File lib/holiday_list.rb, line 17
def self.configure
  yield configuration
end
list() click to toggle source
# File lib/holiday_list.rb, line 13
def self.list
  new.to_a
end
new() click to toggle source
# File lib/holiday_list.rb, line 25
def initialize
  @request_string = GoogleCalendarRequestString.new self.class.configuration
end

Public Instance Methods

to_a() click to toggle source
# File lib/holiday_list.rb, line 29
def to_a
  argument_error! if invalid_request?

  json_response['items'].map do |item|
    {
      summary:    item['summary'],
      start_date: Date.parse(item['start']['date']),
      etag:       item['etag']
    }
  end
end

Private Instance Methods

invalid_request?() click to toggle source

TODO: methods below are only used in to_a, and are prime candidates for an extract class refactoring

# File lib/holiday_list.rb, line 44
def invalid_request?
  return false unless response_error
  response_error['code'] == 400
end
json_response() click to toggle source
# File lib/holiday_list.rb, line 54
def json_response
  @json_response ||= JSON.parse(response.body)
end
response() click to toggle source
# File lib/holiday_list.rb, line 49
def response
  conn = Faraday.new url: GoogleCalendarRequestString.url_base
  conn.get @request_string.to_s
end
response_error() click to toggle source
# File lib/holiday_list.rb, line 58
def response_error
  json_response['error']
end