Class: HolidaysRest::Client
- Inherits:
-
Object
- Object
- HolidaysRest::Client
- Defined in:
- lib/holidays_rest/client.rb
Constant Summary collapse
- BASE_URL =
"https://api.holidays.rest/v1"
Instance Method Summary collapse
-
#countries ⇒ Array<Country>
Return all supported countries.
-
#country(country_code) ⇒ Country
Return details for one country, including subdivision codes.
-
#holidays(country:, year:, month: nil, day: nil, type: nil, religion: nil, region: nil, lang: nil, response: nil) ⇒ Array<Holiday>
Fetch public holidays.
-
#initialize(api_key:, base_url: BASE_URL, open_timeout: 5, read_timeout: 15) ⇒ Client
constructor
A new instance of Client.
-
#languages ⇒ Array<Language>
Return all supported language codes.
Constructor Details
#initialize(api_key:, base_url: BASE_URL, open_timeout: 5, read_timeout: 15) ⇒ Client
Returns a new instance of Client.
13 14 15 16 17 18 19 20 |
# File 'lib/holidays_rest/client.rb', line 13 def initialize(api_key:, base_url: BASE_URL, open_timeout: 5, read_timeout: 15) raise ArgumentError, "api_key must not be empty" if api_key.nil? || api_key.empty? @api_key = api_key @base_url = base_url.chomp("/") @open_timeout = open_timeout @read_timeout = read_timeout end |
Instance Method Details
#countries ⇒ Array<Country>
Return all supported countries.
52 53 54 |
# File 'lib/holidays_rest/client.rb', line 52 def countries get("/countries", {}).map { Country.from_hash(_1) } end |
#country(country_code) ⇒ Country
Return details for one country, including subdivision codes.
59 60 61 62 63 |
# File 'lib/holidays_rest/client.rb', line 59 def country(country_code) raise ArgumentError, "country_code must not be empty" if country_code.nil? || country_code.empty? Country.from_hash(get("/country/#{URI.encode_uri_component(country_code)}", {})) end |
#holidays(country:, year:, month: nil, day: nil, type: nil, religion: nil, region: nil, lang: nil, response: nil) ⇒ Array<Holiday>
Fetch public holidays.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/holidays_rest/client.rb', line 34 def holidays(country:, year:, month: nil, day: nil, type: nil, religion: nil, region: nil, lang: nil, response: nil) params = build_params( country: country, year: year, month: month, day: day, type: type, religion: religion, region: region, lang: lang, response: response ) get("/holidays", params).map { Holiday.from_hash(_1) } end |