Class: NamedayApi
- Inherits:
-
Object
- Object
- NamedayApi
- Defined in:
- lib/nameday_api.rb,
lib/nameday_api/version.rb
Overview
Class: NamedayApi
Constant Summary collapse
- BASE_URL =
'https://nameday.abalin.net/api/V1'
- VERSION =
'2.0.0'
Class Method Summary collapse
- .fetch_and_parse(url) ⇒ Object
- .fetch_data(endpoint, options = {}) ⇒ Object
- .search_by_name(name, country_code) ⇒ Object
- .specific_day(day, month, country_code = nil) ⇒ Object
- .today(country_code = nil, time_zone = nil) ⇒ Object
- .tomorrow(country_code = nil, time_zone = nil) ⇒ Object
- .yesterday(country_code = nil, time_zone = nil) ⇒ Object
Class Method Details
.fetch_and_parse(url) ⇒ Object
32 33 34 35 36 |
# File 'lib/nameday_api.rb', line 32 def self.fetch_and_parse(url) uri = URI(url) response = Net::HTTP.get(uri) JSON.parse(response) end |
.fetch_data(endpoint, options = {}) ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/nameday_api.rb', line 38 def self.fetch_data(endpoint, = {}) url = "#{BASE_URL}/#{endpoint}" query_params = .map { |key, value| "#{key}=#{value}" if value }.compact url += "?#{query_params.join('&')}" unless query_params.empty? fetch_and_parse(url) end |
.search_by_name(name, country_code) ⇒ Object
27 28 29 30 |
# File 'lib/nameday_api.rb', line 27 def self.search_by_name(name, country_code) = { name: name, country: country_code } fetch_data('getname', ) end |
.specific_day(day, month, country_code = nil) ⇒ Object
22 23 24 25 |
# File 'lib/nameday_api.rb', line 22 def self.specific_day(day, month, country_code = nil) = { day: day, month: month, country: country_code } fetch_data('getdate', ) end |
.today(country_code = nil, time_zone = nil) ⇒ Object
10 11 12 |
# File 'lib/nameday_api.rb', line 10 def self.today(country_code = nil, time_zone = nil) fetch_data('today', country: country_code, timezone: time_zone) end |
.tomorrow(country_code = nil, time_zone = nil) ⇒ Object
14 15 16 |
# File 'lib/nameday_api.rb', line 14 def self.tomorrow(country_code = nil, time_zone = nil) fetch_data('tomorrow', country: country_code, timezone: time_zone) end |
.yesterday(country_code = nil, time_zone = nil) ⇒ Object
18 19 20 |
# File 'lib/nameday_api.rb', line 18 def self.yesterday(country_code = nil, time_zone = nil) fetch_data('yesterday', country: country_code, timezone: time_zone) end |