Class: IpLocationService::IpLocationService

Inherits:
AuthenticatedService show all
Defined in:
lib/ip_location_service/ip_location_service.rb

Overview

Client to access the developer garden ip location service.

See also:

Constant Summary collapse

@@IP_LOCATION_SCHEMA =
'http://iplocation.developer.telekom.com/schema/'
@@IP_LOCATION_SERVICE_ENDPOINT =
{
        :uri => "https://gateway.developer.telekom.com/p3gw-mod-odg-iplocation/services/IPLocation",
        :version => 1
}

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AuthenticatedService

#initialize, #invoke_authenticated

Methods inherited from BasicService

#initialize, #on_create_document, #on_response_document

Constructor Details

This class inherits a constructor from AuthenticatedService

Class Method Details

.IP_LOCATON_SCHEMAObject

Static Methods



65
66
67
# File 'lib/ip_location_service/ip_location_service.rb', line 65

def self.IP_LOCATON_SCHEMA
  return @@IP_LOCATON_SCHEMA
end

.xpath_query(doc, query_string, global_search = true) ⇒ Object

Performs a xpath query in the ip location namespace for the given document and query string.

Parameters

doc

XmlQueryFront document.

query_string

Element to look for

global_search

Searches within all levels using “//” if global_search = true.



75
76
77
# File 'lib/ip_location_service/ip_location_service.rb', line 75

def self.xpath_query(doc, query_string, global_search = true)
  self.xpath_query_for_schema(@@IP_LOCATION_SCHEMA, doc, query_string, global_search)
end

Instance Method Details

#locate_ip(ip_addresses, environment = ServiceEnvironment.MOCK, account = nil) ⇒ Object

Retrieves spatial information about the given ip address.

Parameters

ip_address

IpAddress-object or array of IpAddress-objects for which to perform an ip location. Can be a single ip address or an array. of ip addresses.

environment

Service environment as defined in ServiceLevel.

account

IP address for which to perform an ip location.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/ip_location_service/ip_location_service.rb', line 36

def locate_ip(ip_addresses, environment = ServiceEnvironment.MOCK,  = nil)
  ip_location_response = nil

  response = invoke_authenticated("locateIP") do |request, doc|
    request.add('environment', environment)

    # If only a single ip has been passed create an array from it to have a more uniform processing afterwards.
    ip_addresses = [ip_addresses] unless ip_addresses.is_a?(Array)

    ip_addresses.each do |ip_address|

      # If there are string ips convert them to IpAddress objects.
      ip_address = IpAddress.new(ip_address) if ip_address.is_a?(String)

      request.add('address') do |address|
        address.add('ipType', ip_address.ip_type)
        address.add('ipAddress', ip_address.ip_address)
      end
    end
    request.add('account', ) if ( && !.empty?)
  end

  ip_location_response = IpLocationResponse.new(response)

  return ip_location_response
end