Module: HolidApi
- Includes:
- HTTParty
- Defined in:
- lib/holidapi.rb,
lib/holidapi/version.rb
Defined Under Namespace
Classes: BadRequest, ClientError, NotFound, ServerError, Unauthorized, Unavailable
Constant Summary collapse
- VERSION =
"0.0.1"
Class Method Summary collapse
-
.get(params = {}) ⇒ Object
Get the holidays from the API.
-
.handle_response(response) ⇒ Object
Handle the response from the API.
Class Method Details
.get(params = {}) ⇒ Object
Get the holidays from the API. Default country: “US” Default year: Time.now.year
38 39 40 41 42 |
# File 'lib/holidapi.rb', line 38 def get(params = {}) opts = { country: 'us', year: Time.now.year } query = URI.encode_www_form(opts.merge(params)) handle_response super('/holidays', query: query) end |
.handle_response(response) ⇒ Object
Handle the response from the API
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/holidapi.rb', line 48 def handle_response(response) case response.code.to_i when 200 JSON.parse(response)['holidays'] when 400 raise BadRequest.new response.parsed_response when 401 raise Unauthorized.new when 404 raise NotFound.new when 400...500 raise ClientError.new response.parsed_response when 500...600 raise ServerError.new else response end end |