Class: YahooCountriesAndProvinces::YahooProvinceList

Inherits:
Object
  • Object
show all
Defined in:
lib/yahoo_countries_and_provinces/yahoo_province_list.rb

Instance Method Summary collapse

Constructor Details

#initializeYahooProvinceList

Returns a new instance of YahooProvinceList.



6
7
8
# File 'lib/yahoo_countries_and_provinces/yahoo_province_list.rb', line 6

def initialize()
  @states_array = []
end

Instance Method Details

#provinces(country, 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_province_list.rb', line 10

def provinces(country, language = "en")
  set_url(country, language)

  @states_array.clear if @states_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 { |state|
    @states_array << state['name']
  }

  @states_array
end