]> git.openstreetmap.org Git - rails.git/blob - lib/quova.rb
Serve up paperclip attachments in a cache friendly way
[rails.git] / lib / quova.rb
1 ##
2 # Load required libraries
3 require 'soap/wsdlDriver'
4
5 ##
6 # Monkey patch WSDL parser to stop it moaning
7 module WSDL
8   class Parser
9     def warn(msg)
10     end
11   end
12 end
13
14 ##
15 # Provide interface to Quova geolocation service
16 module Quova
17   ##
18   # Access details for WSDL description
19   WSDL_URL="https://webservices.quova.com/OnDemand/GeoPoint/v1/default.asmx?WSDL"
20   WSDL_USER = QUOVA_USERNAME
21   WSDL_PASS = 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
65 end
66