class GlobalWeather::Country
Attributes
cities[R]
name[R]
Public Class Methods
new(name = nil, options = {})
click to toggle source
# File lib/global_weather/country.rb, line 6 def initialize(name = nil, options = {}) client = Client.connect(options) raise Errors::CountryNotProvided if name.nil? @name = name response = client.call(:get_cities_by_country) do |locals| locals.message 'CountryName' => name end if response.success? body = response.hash[:envelope] && response.hash[:envelope][:body] if body result = body[:get_cities_by_country_response] && body[:get_cities_by_country_response][:get_cities_by_country_result] create_attributes(result) end else raise Errors::RequestFailure, 'Request to SOAP service failed' end end
Private Instance Methods
create_attributes(result)
click to toggle source
Instaniates attribute 'cites' with an array of strings (cities)
# File lib/global_weather/country.rb, line 34 def create_attributes(result) hrep = Nori.new.parse(result) new_data_set = hrep && hrep['NewDataSet'] if new_data_set hash_of_cities = new_data_set && new_data_set['Table'] if hash_of_cities @cities = hash_of_cities.map{|item| item['City']} else raise Errors::InvalidResponseFormat, 'Unexpected response format' end else raise Errors::CountryInvalid, 'Returned data set is empty, probably because provided country is invalid' end end