Skip to content

Instantly share code, notes, and snippets.

@xcobar
Created April 2, 2020 00:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xcobar/1ae0d7b6f48d172560251249892ccc1a to your computer and use it in GitHub Desktop.
Save xcobar/1ae0d7b6f48d172560251249892ccc1a to your computer and use it in GitHub Desktop.
: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 >
# 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