-
-
Save xcobar/1ae0d7b6f48d172560251249892ccc1a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:008 > Kovid.country "poland" | |
Traceback (most recent call last): | |
2: from (irb):7 | |
1: from (irb):8:in `rescue in irb_binding' | |
ArgumentError (wrong number of arguments (given 1, expected 2)) | |
:009 > Kovid.country "poland", "" | |
Traceback (most recent call last): | |
2: from (irb):8 | |
1: from (irb):9:in `rescue in irb_binding' | |
ArgumentError (wrong number of arguments (given 2, expected 1)) | |
:010 > |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# kovid.rb | |
def country(name) | |
Kovid::Request.by_country(name) | |
end | |
# request.rb | |
class << self | |
def by_country(country_name, response_type = "") | |
response = fetch_country(country_name) | |
return response if response_type == 'json' | |
begin | |
if response.values.first.include?('not found') | |
not_found(country_name) | |
else | |
Kovid::Tablelize.country_table(response) | |
end | |
rescue JSON::ParserError | |
puts SERVER_DOWN | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment