Class: IpLocationService::IpLocationResponse

Inherits:
BasicResponse show all
Defined in:
lib/ip_location_service/ip_location_response.rb

Instance Attribute Summary collapse

Attributes inherited from BasicResponse

#error_code, #error_message

Instance Method Summary collapse

Methods inherited from BasicResponse

#inizialize, #raise_on_error

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_locationsObject

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_locationObject

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_sObject



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