Class: YahooCountriesAndProvinces::YahooCountryList
- Inherits:
-
Object
- Object
- YahooCountriesAndProvinces::YahooCountryList
- Defined in:
- lib/yahoo_countries_and_provinces/yahoo_country_list.rb
Instance Method Summary collapse
- #countries(language = "en") ⇒ Object
-
#initialize ⇒ YahooCountryList
constructor
A new instance of YahooCountryList.
Constructor Details
#initialize ⇒ YahooCountryList
Returns a new instance of YahooCountryList.
6 7 8 |
# File 'lib/yahoo_countries_and_provinces/yahoo_country_list.rb', line 6 def initialize() @country_array = [] end |
Instance Method Details
#countries(language = "en") ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/yahoo_countries_and_provinces/yahoo_country_list.rb', line 10 def countries(language = "en") set_url(language) @country_array.clear if @country_array.any? begin resp = Net::HTTP.get_response(URI.parse(@url)) data = resp.body result = JSON.parse(data)["query"]["results"]["place"] rescue raise "Could not get the data from yahoo's servers" end result.each { |country| @country_array << country['name'] } @country_array end |