Class: IpLocationService::IpLocationResponse
- Inherits:
-
BasicResponse
- Object
- BasicResponse
- IpLocationService::IpLocationResponse
- Defined in:
- lib/ip_location_service/ip_location_response.rb
Instance Attribute Summary collapse
-
#ip_address_locations ⇒ Object
Returns the value of attribute ip_address_locations.
Attributes inherited from BasicResponse
Instance Method Summary collapse
-
#initialize(response_xml, raise_exception_on_error = true) ⇒ IpLocationResponse
constructor
Constructor.
-
#ip_address_location ⇒ Object
Alias for accessing the first element of the ip_address_location array.
-
#ip_address_location=(location) ⇒ Object
Alias for accessing the first element of the ip_address_location array.
- #to_s ⇒ Object
Methods inherited from BasicResponse
Constructor Details
#initialize(response_xml, raise_exception_on_error = true) ⇒ IpLocationResponse
Constructor.
Parameters
response_xml
-
Xml as returned by a
ip_location
-method call. raise_exception_on_error
-
Raise an exception if an error occurs or not?
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/ip_location_service/ip_location_response.rb', line 11 def initialize(response_xml, raise_exception_on_error = true) doc = response_xml.document @error_code = IpLocationService.xpath_query(doc, "statusCode").to_s @error_message = IpLocationService.xpath_query(doc, "statusMessage").to_s @ip_address_locations = [] ip_address_location_doc = IpLocationService.xpath_query(doc, "ipAddressLocation") ip_address_location_doc.each do |ip_address_location| @ip_address_locations << IpAddressLocation.build_from_xml(ip_address_location) end raise_on_error(response_xml) if raise_exception_on_error end |
Instance Attribute Details
#ip_address_locations ⇒ Object
Returns the value of attribute ip_address_locations.
5 6 7 |
# File 'lib/ip_location_service/ip_location_response.rb', line 5 def ip_address_locations @ip_address_locations end |
Instance Method Details
#ip_address_location ⇒ Object
Alias for accessing the first element of the ip_address_location array.
29 30 31 |
# File 'lib/ip_location_service/ip_location_response.rb', line 29 def ip_address_location @ip_address_locations.first end |
#ip_address_location=(location) ⇒ Object
Alias for accessing the first element of the ip_address_location array.
34 35 36 |
# File 'lib/ip_location_service/ip_location_response.rb', line 34 def ip_address_location=(location) @ip_address_locations[0] = location end |
#to_s ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/ip_location_service/ip_location_response.rb', line 38 def to_s ret = "Status: #{@error_code}, Message: #{@error_message}\nLocations:\n" @ip_address_locations.each do |ipl| ret += "\t#{ipl}\n" end ret end |