source: subversion/sites/rails_port/lib/quova.rb @ 19899

Last change on this file since 19899 was 18788, checked in by tomhughes, 11 years ago

Add support for GeoIP lookups using Quova.

File size: 1.3 KB
Line 
1##
2# Load required libraries
3require 'soap/wsdlDriver'
4
5##
6# Monkey patch WSDL parser to stop it moaning
7module WSDL
8  class Parser
9    def warn(msg)
10    end
11  end
12end
13
14##
15# Provide interface to Quova geolocation service
16module Quova
17  ##
18  # Access details for WSDL description
19  WSDL_URL="https://webservices.quova.com/OnDemand/GeoPoint/v1/default.asmx?WSDL"
20  WSDL_USER = APP_CONFIG['quova_username']
21  WSDL_PASS = APP_CONFIG['quova_password']
22
23  ##
24  # Status codes
25  Success = 0
26  IPV6NoSupport = 1
27  InvalidCredentials = 2
28  NotMapped = 3
29  InvalidIPFormat = 4
30  IPAddressNull = 5
31  AccessDenied = 6
32  QueryLimit = 7
33  OutOfService = 10
34
35  ##
36  # Create SOAP endpoint
37  @@soap = SOAP::WSDLDriverFactory.new(WSDL_URL).create_rpc_driver
38  @@soap.options["protocol.http.basic_auth"] << [WSDL_URL, WSDL_USER, WSDL_PASS]
39
40  ##
41  # Accessor for SOAP endpoint
42  def self.soap
43    @@soap
44  end
45
46  ##
47  # Class representing geolocation details for an IP address
48  class IpInfo
49    def initialize(ip_address)
50      @ipinfo = Quova::soap.GetIpInfo(:ipAddress => ip_address)
51    end
52
53    def status
54      @ipinfo["GetIpInfoResult"]["Response"]["Status"].to_i
55    end
56 
57    def country_code
58      @ipinfo["GetIpInfoResult"]["Location"]["Country"]["Name"]
59    end
60
61    def country_confidence
62      @ipinfo["GetIpInfoResult"]["Location"]["Country"]["Confidence"]
63    end
64  end
65end
66
Note: See TracBrowser for help on using the repository browser.