quova 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -11,35 +11,54 @@ ruby Hash objects in response. Data-types will be cast where appropriate (e.g.
11
11
 
12
12
  ## Usage
13
13
 
14
- Currently, support is only provided for the QOD (Query on Demand) REST API.
14
+ There are two interfaces, depending on which API you want to use. You can use
15
+ either `Quova::QOD` (Quova on Demand), which is for the paid service and
16
+ includes slightly more data, or you can use `Quova::REST`, which is for the
17
+ standard service, providing slightly less data (such as anonymizer information).
15
18
 
16
- Usage is simple:
19
+ You'll need the appropriate credential for each of these. You can register for
20
+ a free account at http://developer.quova.com/.
17
21
 
18
- qod = Quova::QOD.new(:id => "your-id", :password => "your-password")
19
- info = qod.info("4.2.2.2")
22
+ ### Quova on Demand
23
+
24
+ lookup = Quova::QOD.new(:id => "your-id", :password => "your-password")
25
+ info = lookup.info("4.2.2.2")
20
26
 
21
27
  Or you can use the alternative syntax:
22
28
 
23
- info = qod["4.2.2.2"]
29
+ info = lookup["4.2.2.2"]
30
+
31
+ ### Standard REST API
24
32
 
25
- This returns a Hash with the following elements:
33
+ lookup = Quova::REST.new(:api_key => "your-key", :secret => "your-secret")
34
+ info = lookup.info("4.2.2.2")
35
+
36
+ Or you can use the alternative syntax:
37
+
38
+ info = lookup["4.2.2.2"]
39
+
40
+ Both clients return the same Result object, which acts like a Hash. How much
41
+ information you get depends on the API you're using. Anything that is not
42
+ provided, will be left as `nil`:
26
43
 
27
44
  :ip_address => String
28
45
  :ip_type => String
29
46
  :anonymizer_status => String
30
- :network_tld => String
31
- :network_sld => String
47
+ :domain_tld => String
48
+ :domain_sld => String
32
49
  :aol => Boolean
50
+ :organization => String
33
51
  :carrier => String
34
52
  :asn => String
35
- :connection => String
53
+ :connection_type => String
36
54
  :line_speed => String
37
- :routing_type => String
55
+ :ip_routing_type => String
38
56
  :continent_name => String
39
57
  :country_code => String
58
+ :country_name => String
40
59
  :country_confidence => Integer
41
60
  :region_name => String
42
- :region_confidence => Integer
61
+ :state_code => String
43
62
  :state_name => String
44
63
  :state_confidence => Integer
45
64
  :city_name => String
@@ -53,7 +72,12 @@ This returns a Hash with the following elements:
53
72
  :msa_id => Integer
54
73
 
55
74
  For any field that was returned blank, or missing, `nil` will be present in the
56
- result Hash.
75
+ result.
76
+
77
+ The Result is an object with [Virtus](https://github.com/solnic/virtus) mixed
78
+ in to ensure valid data types. As a side-effect, you may access the properties
79
+ either using a Hash (`[:key]`) syntax, or just like a regular method call.
80
+ (`result.longitude`). If you want a plain Hash, call `result.attributes`.
57
81
 
58
82
  ## Resources
59
83
 
@@ -1 +1,6 @@
1
+ require 'rest_client'
2
+ require 'nokogiri'
3
+
1
4
  require 'quova/qod'
5
+ require 'quova/rest'
6
+ require 'quova/result'
@@ -1,10 +1,6 @@
1
- require 'rest_client'
2
- require 'virtus'
3
- require 'nokogiri'
4
-
5
1
  module Quova
6
2
 
7
- # Interface to the Quova QOD (Query On Demand) service
3
+ # Interface to the Quova QOD (Quova On Demand) service
8
4
  #
9
5
  # @api public
10
6
  class QOD
@@ -31,25 +27,25 @@ module Quova
31
27
  # @param [String, IPAddr, #to_s] ip
32
28
  # The IP address to look up
33
29
  #
34
- # @return [Hash]
35
- # A Hash containing a key for each element. Provided fields:
30
+ # @return [Quova::Result<Virtus>]
31
+ # A Hash-like object containing a key for each element. Provided fields:
36
32
  #
37
33
  # :ip_address
38
34
  # :ip_type
39
35
  # :anonymizer_status
40
- # :network_tld
41
- # :network_sld
36
+ # :domain_tld
37
+ # :domain_sld
42
38
  # :aol
39
+ # :organization
43
40
  # :carrier
44
41
  # :asn
45
- # :connection
42
+ # :connection_type
46
43
  # :line_speed
47
- # :routing_type
44
+ # :ip_routing_type
48
45
  # :continent_name
49
46
  # :country_code
50
47
  # :country_confidence
51
48
  # :region_name
52
- # :region_confidence
53
49
  # :state_name
54
50
  # :state_confidence
55
51
  # :city_name
@@ -71,7 +67,7 @@ module Quova
71
67
 
72
68
  private
73
69
 
74
- # Map XML to a meaningful Hash
70
+ # Map XML to a meaningful Result
75
71
  #
76
72
  # @api private
77
73
  def parse_xml(xml)
@@ -79,19 +75,19 @@ module Quova
79
75
  :ip_address => "IPAddress",
80
76
  :ip_type => "IPType",
81
77
  :anonymizer_status => "AnonymizerStatus",
82
- :network_tld => "Domain TopLevel",
83
- :network_sld => "Domain SecondLevel",
78
+ :domain_tld => "Domain TopLevel",
79
+ :domain_sld => "Domain SecondLevel",
84
80
  :aol => "AOL",
81
+ :organization => "Organization",
85
82
  :carrier => "Carrier",
86
83
  :asn => "ASN",
87
- :connection => "Connection",
84
+ :connection_type => "Connection",
88
85
  :line_speed => "LineSpeed",
89
- :routing_type => "IPRoutingType",
86
+ :ip_routing_type => "IPRoutingType",
90
87
  :continent_name => "Continent Name",
91
88
  :country_code => "Country Name",
92
89
  :country_confidence => "Country Confidence",
93
90
  :region_name => "Region Name",
94
- :region_confidence => "Region Confidence",
95
91
  :state_name => "State Name",
96
92
  :state_confidence => "State Confidence",
97
93
  :city_name => "City Name",
@@ -109,46 +105,11 @@ module Quova
109
105
  result = Result.new
110
106
 
111
107
  paths.each_pair do |attr, selector|
112
- node = doc.at_css(selector)
113
- result.attribute_set(attr, node.text) if node && node.text != ""
108
+ next unless node = doc.at_css(selector)
109
+ result[attr] = node.text unless node.text == ""
114
110
  end
115
111
 
116
- result.attributes
117
- end
118
-
119
- # Internally maps Strings from the API to the correct types
120
- #
121
- # @api private
122
- class Result
123
- include Virtus
124
-
125
- attribute :ip_address, String
126
- attribute :ip_type, String
127
- attribute :anonymizer_status, String
128
- attribute :network_tld, String
129
- attribute :network_sld, String
130
- attribute :aol, Boolean
131
- attribute :carrier, String
132
- attribute :asn, String
133
- attribute :connection, String
134
- attribute :line_speed, String
135
- attribute :routing_type, String
136
- attribute :continent_name, String
137
- attribute :country_code, String
138
- attribute :country_confidence, Integer
139
- attribute :region_name, String
140
- attribute :region_confidence, Integer
141
- attribute :state_name, String
142
- attribute :state_confidence, Integer
143
- attribute :city_name, String
144
- attribute :city_confidence, Integer
145
- attribute :postal_code, String
146
- attribute :time_zone, String
147
- attribute :area_code, String
148
- attribute :longitude, Float
149
- attribute :latitude, Float
150
- attribute :dma_id, Integer
151
- attribute :msa_id, Integer
112
+ result
152
113
  end
153
114
  end
154
115
  end
@@ -0,0 +1,127 @@
1
+ require 'digest/md5'
2
+
3
+ module Quova
4
+
5
+ # Interface to the standard Quova REST API.
6
+ #
7
+ # @api public
8
+ class REST
9
+
10
+ # Initialize the REST client with the Quova credentials.
11
+ #
12
+ # @example Quova::REST.new(:api_key => 'your-key', :secret => 'your-secret')
13
+ #
14
+ # @api public
15
+ def initialize(options)
16
+ @options = options.dup
17
+ @resource = RestClient::Resource.new("http://api.quova.com/v1/ipinfo")
18
+ end
19
+
20
+ # Query the API for a given IP address
21
+ #
22
+ # @example
23
+ # rest.info("4.2.2.2") # => { ... }
24
+ #
25
+ # @param [String, IPAddr, #to_s] ip
26
+ # The IP address to look up
27
+ #
28
+ # @return [Quova::Result<Virtus>]
29
+ # A Hash-like object containing a key for each element. Provided fields:
30
+ #
31
+ # :ip_address
32
+ # :ip_type
33
+ # :domain_tld
34
+ # :domain_sld
35
+ # :organization
36
+ # :carrier
37
+ # :asn
38
+ # :connection_type
39
+ # :line_speed
40
+ # :ip_routing_type
41
+ # :continent_name
42
+ # :country_code
43
+ # :country_name
44
+ # :country_confidence
45
+ # :region_name
46
+ # :state_code
47
+ # :state_name
48
+ # :state_confidence
49
+ # :city_name
50
+ # :city_confidence
51
+ # :postal_code
52
+ # :time_zone
53
+ # :area_code
54
+ # :longitude
55
+ # :latitude
56
+ # :dma_id
57
+ # :msa_id
58
+ #
59
+ # @api public
60
+ def info(ip)
61
+ parse_xml(@resource[ip].get(:params => params_for_ip(ip)).body)
62
+ end
63
+
64
+ alias_method :[], :info
65
+
66
+ private
67
+
68
+ # Map XML to a meaningful Result
69
+ #
70
+ # @api private
71
+ def parse_xml(xml)
72
+ paths = {
73
+ :ip_address => "ip_address",
74
+ :ip_type => "ip_type",
75
+ :domain_tld => "Domain tld",
76
+ :domain_sld => "Domain sld",
77
+ :organization => "organization",
78
+ :carrier => "carrier",
79
+ :asn => "asn",
80
+ :connection_type => "connection_type",
81
+ :line_speed => "line_speed",
82
+ :ip_routing_type => "ip_routing_type",
83
+ :continent_name => "continent",
84
+ :country_name => "country",
85
+ :country_code => "country_code",
86
+ :country_confidence => "country_cf",
87
+ :region_name => "region",
88
+ :state_name => "state",
89
+ :state_code => "state_code",
90
+ :state_confidence => "state_cf",
91
+ :city_name => "city",
92
+ :city_confidence => "city_cf",
93
+ :postal_code => "postal_code",
94
+ :time_zone => "time_zone",
95
+ :area_code => "area_code",
96
+ :longitude => "longitude",
97
+ :latitude => "latitude",
98
+ :dma_id => "dma",
99
+ :msa_id => "msa"
100
+ }
101
+
102
+ doc = Nokogiri::XML(xml)
103
+ result = Result.new
104
+
105
+ paths.each_pair do |attr, selector|
106
+ next unless node = doc.at_css(selector)
107
+ result[attr] = node.text unless node.text == ""
108
+ end
109
+
110
+ result
111
+ end
112
+
113
+ # See http://developer.quova.com/docs#parameters
114
+ #
115
+ # @api private
116
+ def params_for_ip(ip)
117
+ { :apikey => @options[:api_key], :sig => signature }
118
+ end
119
+
120
+ # See http://developer.quova.com/docs#signing_api
121
+ #
122
+ # @api private
123
+ def signature
124
+ Digest::MD5.hexdigest(@options[:api_key].to_s + @options[:secret].to_s + Time.now.to_i.to_s)
125
+ end
126
+ end
127
+ end
@@ -0,0 +1,48 @@
1
+ require 'virtus'
2
+ require 'forwardable'
3
+
4
+ module Quova
5
+
6
+ # Provides the result data from a Quova API call.
7
+ # Acts both like a Hash and Plain Old Ruby Object.
8
+ #
9
+ # @api private
10
+ class Result
11
+ include Virtus
12
+ extend Forwardable
13
+
14
+ def_delegators :attributes, :each, :each_pair
15
+
16
+ attribute :ip_address, String
17
+ attribute :ip_type, String
18
+ attribute :anonymizer_status, String
19
+ attribute :domain_tld, String
20
+ attribute :domain_sld, String
21
+ attribute :aol, Boolean
22
+ attribute :organization, String
23
+ attribute :carrier, String
24
+ attribute :asn, String
25
+ attribute :connection_type, String
26
+ attribute :line_speed, String
27
+ attribute :ip_routing_type, String
28
+ attribute :continent_name, String
29
+ attribute :country_name, String
30
+ attribute :country_code, String
31
+ attribute :country_confidence, Integer
32
+ attribute :region_name, String
33
+ attribute :state_code, String
34
+ attribute :state_name, String
35
+ attribute :state_confidence, Integer
36
+ attribute :city_name, String
37
+ attribute :city_confidence, Integer
38
+ attribute :postal_code, String
39
+ attribute :time_zone, String
40
+ attribute :area_code, String
41
+ attribute :longitude, Float
42
+ attribute :latitude, Float
43
+ attribute :dma_id, Integer
44
+ attribute :msa_id, Integer
45
+
46
+ include Enumerable
47
+ end
48
+ end
@@ -1,3 +1,3 @@
1
1
  module Quova
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -6,16 +6,16 @@ Gem::Specification.new do |s|
6
6
  s.name = "quova"
7
7
  s.version = Quova::VERSION
8
8
  s.platform = Gem::Platform::RUBY
9
- s.authors = ["Flippa.com Pty. Ltd."]
10
- s.email = ["chris@flippa.com"]
11
- s.homepage = "http://flippa.com/"
9
+ s.authors = ["Chris Corbyn"]
10
+ s.email = ["chris@w3style.co.uk"]
11
+ s.homepage = "https://github.com/d11wtq/quova"
12
12
  s.summary = %q{Quova GeoIP Client for Ruby}
13
13
  s.description = %q{Provides a high-level client for Quova's On-Demand REST API}
14
14
 
15
15
  s.rubyforge_project = "quova"
16
16
 
17
17
  s.add_dependency "rest-client", "~> 1.6.3"
18
- s.add_dependency "virtus"
18
+ s.add_dependency "virtus", ">= 0.0.5"
19
19
  s.add_dependency "nokogiri", "~> 1.5.0"
20
20
 
21
21
  s.add_development_dependency "rspec", "~> 2.6"
@@ -30,7 +30,7 @@ describe Quova::QOD do
30
30
  @resource.should_receive(:[]).with("4.2.2.2") { @resource }
31
31
  @resource.should_receive(:get) { @response }
32
32
 
33
- @qod["4.2.2.2"].should == @qod.info("4.2.2.2")
33
+ @qod["4.2.2.2"]
34
34
  end
35
35
 
36
36
  it "maps <IPAddress/> to :ip_address" do
@@ -69,7 +69,7 @@ describe Quova::QOD do
69
69
  @qod.info("4.2.2.2")[:anonymizer_status].should == "SUSPECT"
70
70
  end
71
71
 
72
- it "maps <Network><Domain><TopLevel/></Domain></Network> to :network_tld" do
72
+ it "maps <Network><Domain><TopLevel/></Domain></Network> to :domain_tld" do
73
73
  @response.stub(:body) do
74
74
  <<-XML
75
75
  <IpInfo xmlns="https://webservices.quova.com/ipinfo" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
@@ -78,10 +78,10 @@ describe Quova::QOD do
78
78
  XML
79
79
  end
80
80
 
81
- @qod.info("4.2.2.2")[:network_tld].should == ".net.au"
81
+ @qod.info("4.2.2.2")[:domain_tld].should == ".net.au"
82
82
  end
83
83
 
84
- it "maps <Network><Domain><SecondLevel/></Domain></Network> to :network_sld" do
84
+ it "maps <Network><Domain><SecondLevel/></Domain></Network> to :domain_sld" do
85
85
  @response.stub(:body) do
86
86
  <<-XML
87
87
  <IpInfo xmlns="https://webservices.quova.com/ipinfo" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
@@ -90,7 +90,7 @@ describe Quova::QOD do
90
90
  XML
91
91
  end
92
92
 
93
- @qod.info("4.2.2.2")[:network_sld].should == "iinet"
93
+ @qod.info("4.2.2.2")[:domain_sld].should == "iinet"
94
94
  end
95
95
 
96
96
  it "maps <Network><AOL/></Network> to :aol" do
@@ -105,6 +105,18 @@ describe Quova::QOD do
105
105
  @qod.info("4.2.2.2")[:aol].should be(false)
106
106
  end
107
107
 
108
+ it "maps <Network><Organization/></Network> to :organization" do
109
+ @response.stub(:body) do
110
+ <<-XML
111
+ <IpInfo xmlns="https://webservices.quova.com/ipinfo" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
112
+ <Network><Organization>iinet limited</Organization></Network>
113
+ </IpInfo>
114
+ XML
115
+ end
116
+
117
+ @qod.info("4.2.2.2")[:organization].should == "iinet limited"
118
+ end
119
+
108
120
  it "maps <Network><Carrier/></Network> to :carrier" do
109
121
  @response.stub(:body) do
110
122
  <<-XML
@@ -129,7 +141,7 @@ describe Quova::QOD do
129
141
  @qod.info("4.2.2.2")[:asn].should == "3356"
130
142
  end
131
143
 
132
- it "maps <Network><Connection/></Network> to :connection" do
144
+ it "maps <Network><Connection/></Network> to :connection_type" do
133
145
  @response.stub(:body) do
134
146
  <<-XML
135
147
  <IpInfo xmlns="https://webservices.quova.com/ipinfo" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
@@ -138,7 +150,7 @@ describe Quova::QOD do
138
150
  XML
139
151
  end
140
152
 
141
- @qod.info("4.2.2.2")[:connection].should == "dsl"
153
+ @qod.info("4.2.2.2")[:connection_type].should == "dsl"
142
154
  end
143
155
 
144
156
  it "maps <Network><LineSpeed/></Network> to :line_speed" do
@@ -153,7 +165,7 @@ describe Quova::QOD do
153
165
  @qod.info("4.2.2.2")[:line_speed].should == "medium"
154
166
  end
155
167
 
156
- it "maps <Network><IPRoutingType/></Network> to :routing_type" do
168
+ it "maps <Network><IPRoutingType/></Network> to :ip_routing_type" do
157
169
  @response.stub(:body) do
158
170
  <<-XML
159
171
  <IpInfo xmlns="https://webservices.quova.com/ipinfo" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
@@ -162,7 +174,7 @@ describe Quova::QOD do
162
174
  XML
163
175
  end
164
176
 
165
- @qod.info("4.2.2.2")[:routing_type].should == "fixed"
177
+ @qod.info("4.2.2.2")[:ip_routing_type].should == "fixed"
166
178
  end
167
179
 
168
180
  it "maps <Location><Continent><Name/></Continent></Location> to :continent_name" do
@@ -214,18 +226,6 @@ describe Quova::QOD do
214
226
  @qod.info("4.2.2.2")[:region_name].should == "test"
215
227
  end
216
228
 
217
- it "maps <Location><Region><Confidence/></Region></Location> to :region_confidence" do
218
- @response.stub(:body) do
219
- <<-XML
220
- <IpInfo xmlns="https://webservices.quova.com/ipinfo" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
221
- <Location><Region><Confidence>43</Confidence></Region></Location>
222
- </IpInfo>
223
- XML
224
- end
225
-
226
- @qod.info("4.2.2.2")[:region_confidence].should == 43
227
- end
228
-
229
229
  it "maps <Location><State><Name/></State></Location> to :state_name" do
230
230
  @response.stub(:body) do
231
231
  <<-XML
@@ -0,0 +1,360 @@
1
+ require 'spec_helper'
2
+
3
+ describe Quova::REST do
4
+ describe "#initialize" do
5
+ it "prepares a RestClient with the base URI" do
6
+ RestClient::Resource.should_receive(:new).with("http://api.quova.com/v1/ipinfo")
7
+ Quova::REST.new(:api_key => "key", :secret => "secrit")
8
+ end
9
+ end
10
+
11
+ describe "#info" do
12
+ before(:each) do
13
+ @resource = double()
14
+ @response = double()
15
+ @resource.stub(:[]) { @resource }
16
+ @resource.stub(:get) { @response }
17
+ @response.stub(:body) { "" }
18
+ RestClient::Resource.stub(:new) { @resource }
19
+ @api = Quova::REST.new(:api_key => "key", :secret => "secrit")
20
+ end
21
+
22
+ it "queries the API for the given IP" do
23
+ @resource.should_receive(:[]).with("4.2.2.2") { @resource }
24
+ @resource.should_receive(:get) { @response }
25
+
26
+ @api.info("4.2.2.2")
27
+ end
28
+
29
+ it "is aliased by []" do
30
+ @resource.should_receive(:[]).with("4.2.2.2") { @resource }
31
+ @resource.should_receive(:get) { @response }
32
+
33
+ @api["4.2.2.2"]
34
+ end
35
+
36
+ it "maps <ip_address/> to :ip_address" do
37
+ @response.stub(:body) do
38
+ <<-XML
39
+ <ipinfo xmlns="http://data.quova.com/1" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance">
40
+ <ip_address>4.2.2.2</ip_address>
41
+ </ipinfo>
42
+ XML
43
+ end
44
+
45
+ @api.info("4.2.2.2")[:ip_address].should == "4.2.2.2"
46
+ end
47
+
48
+ it "maps <ip_type/> to :ip_type" do
49
+ @response.stub(:body) do
50
+ <<-XML
51
+ <ipinfo xmlns="http://data.quova.com/1" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance">
52
+ <ip_type>Mapped</ip_type>
53
+ </ipinfo>
54
+ XML
55
+ end
56
+
57
+ @api.info("4.2.2.2")[:ip_type].should == "Mapped"
58
+ end
59
+
60
+ it "maps <Network><Domain><tld/></Domain></Network> to :domain_tld" do
61
+ @response.stub(:body) do
62
+ <<-XML
63
+ <ipinfo xmlns="http://data.quova.com/1" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance">
64
+ <Network><Domain><tld>.net.au</tld></Domain></Network>
65
+ </ipinfo>
66
+ XML
67
+ end
68
+
69
+ @api.info("4.2.2.2")[:domain_tld].should == ".net.au"
70
+ end
71
+
72
+ it "maps <Network><Domain><sld/></Domain></Network> to :domain_sld" do
73
+ @response.stub(:body) do
74
+ <<-XML
75
+ <ipinfo xmlns="http://data.quova.com/1" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance">
76
+ <Network><Domain><sld>iinet</sld></Domain></Network>
77
+ </ipinfo>
78
+ XML
79
+ end
80
+
81
+ @api.info("4.2.2.2")[:domain_sld].should == "iinet"
82
+ end
83
+
84
+ it "maps <Network><organization/></Network> to :organization" do
85
+ @response.stub(:body) do
86
+ <<-XML
87
+ <ipinfo xmlns="http://data.quova.com/1" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance">
88
+ <Network><organization>iinet limited</organization></Network>
89
+ </ipinfo>
90
+ XML
91
+ end
92
+
93
+ @api.info("4.2.2.2")[:organization].should == "iinet limited"
94
+ end
95
+
96
+ it "maps <Network><carrier/></Network> to :carrier" do
97
+ @response.stub(:body) do
98
+ <<-XML
99
+ <ipinfo xmlns="http://data.quova.com/1" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance">
100
+ <Network><carrier>iinet limited</carrier></Network>
101
+ </ipinfo>
102
+ XML
103
+ end
104
+
105
+ @api.info("4.2.2.2")[:carrier].should == "iinet limited"
106
+ end
107
+
108
+ it "maps <Network><asn/></Network> to :asn" do
109
+ @response.stub(:body) do
110
+ <<-XML
111
+ <ipinfo xmlns="http://data.quova.com/1" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance">
112
+ <Network><asn>3356</asn></Network>
113
+ </ipinfo>
114
+ XML
115
+ end
116
+
117
+ @api.info("4.2.2.2")[:asn].should == "3356"
118
+ end
119
+
120
+ it "maps <Network><connection_type/></Network> to :connection_type" do
121
+ @response.stub(:body) do
122
+ <<-XML
123
+ <ipinfo xmlns="http://data.quova.com/1" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance">
124
+ <Network><connection_type>dsl</connection_type></Network>
125
+ </ipinfo>
126
+ XML
127
+ end
128
+
129
+ @api.info("4.2.2.2")[:connection_type].should == "dsl"
130
+ end
131
+
132
+ it "maps <Network><line_speed/></Network> to :line_speed" do
133
+ @response.stub(:body) do
134
+ <<-XML
135
+ <ipinfo xmlns="http://data.quova.com/1" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance">
136
+ <Network><line_speed>medium</line_speed></Network>
137
+ </ipinfo>
138
+ XML
139
+ end
140
+
141
+ @api.info("4.2.2.2")[:line_speed].should == "medium"
142
+ end
143
+
144
+ it "maps <Network><ip_routing_type/></Network> to :ip_routing_type" do
145
+ @response.stub(:body) do
146
+ <<-XML
147
+ <ipinfo xmlns="http://data.quova.com/1" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance">
148
+ <Network><ip_routing_type>fixed</ip_routing_type></Network>
149
+ </ipinfo>
150
+ XML
151
+ end
152
+
153
+ @api.info("4.2.2.2")[:ip_routing_type].should == "fixed"
154
+ end
155
+
156
+ it "maps <Location><continent/></Location> to :continent_name" do
157
+ @response.stub(:body) do
158
+ <<-XML
159
+ <ipinfo xmlns="http://data.quova.com/1" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance">
160
+ <Location><continent>oceania</continent></Location>
161
+ </ipinfo>
162
+ XML
163
+ end
164
+
165
+ @api.info("4.2.2.2")[:continent_name].should == "oceania"
166
+ end
167
+
168
+ it "maps <Location><CountryData><country_code/></CountryData></Location> to :country_code" do
169
+ @response.stub(:body) do
170
+ <<-XML
171
+ <ipinfo xmlns="http://data.quova.com/1" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance">
172
+ <Location><CountryData><country_code>au</country_code></CountryData></Location>
173
+ </ipinfo>
174
+ XML
175
+ end
176
+
177
+ @api.info("4.2.2.2")[:country_code].should == "au"
178
+ end
179
+
180
+ it "maps <Location><CountryData><country/></CountryData></Location> to :country_name" do
181
+ @response.stub(:body) do
182
+ <<-XML
183
+ <ipinfo xmlns="http://data.quova.com/1" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance">
184
+ <Location><CountryData><country>australia</country></CountryData></Location>
185
+ </ipinfo>
186
+ XML
187
+ end
188
+
189
+ @api.info("4.2.2.2")[:country_name].should == "australia"
190
+ end
191
+
192
+ it "maps <Location><CountryData><country_cf/></CountryData></Location> to :country_confidence" do
193
+ @response.stub(:body) do
194
+ <<-XML
195
+ <ipinfo xmlns="http://data.quova.com/1" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance">
196
+ <Location><CountryData><country_cf>94</country_cf></CountryData></Location>
197
+ </ipinfo>
198
+ XML
199
+ end
200
+
201
+ @api.info("4.2.2.2")[:country_confidence].should == 94
202
+ end
203
+
204
+ it "maps <Location><region/></Location> to :region_name" do
205
+ @response.stub(:body) do
206
+ <<-XML
207
+ <ipinfo xmlns="http://data.quova.com/1" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance">
208
+ <Location><region>test</region></Location>
209
+ </ipinfo>
210
+ XML
211
+ end
212
+
213
+ @api.info("4.2.2.2")[:region_name].should == "test"
214
+ end
215
+
216
+ it "maps <Location><StateData><state_code/></StateData></Location> to :state_code" do
217
+ @response.stub(:body) do
218
+ <<-XML
219
+ <ipinfo xmlns="http://data.quova.com/1" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance">
220
+ <Location><StateData><state_code>vic</state_code></StateData></Location>
221
+ </ipinfo>
222
+ XML
223
+ end
224
+
225
+ @api.info("4.2.2.2")[:state_code].should == "vic"
226
+ end
227
+
228
+ it "maps <Location><StateData><state/></StateData></Location> to :state_name" do
229
+ @response.stub(:body) do
230
+ <<-XML
231
+ <ipinfo xmlns="http://data.quova.com/1" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance">
232
+ <Location><StateData><state>victoria</state></StateData></Location>
233
+ </ipinfo>
234
+ XML
235
+ end
236
+
237
+ @api.info("4.2.2.2")[:state_name].should == "victoria"
238
+ end
239
+
240
+ it "maps <Location><state_cf/></Location> to :state_confidence" do
241
+ @response.stub(:body) do
242
+ <<-XML
243
+ <ipinfo xmlns="http://data.quova.com/1" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance">
244
+ <Location><state_cf>86</state_cf></Location>
245
+ </ipinfo>
246
+ XML
247
+ end
248
+
249
+ @api.info("4.2.2.2")[:state_confidence].should == 86
250
+ end
251
+
252
+ it "maps <Location><CityData><city/></CityData></Location> to :city_name" do
253
+ @response.stub(:body) do
254
+ <<-XML
255
+ <ipinfo xmlns="http://data.quova.com/1" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance">
256
+ <Location><CityData><city>melbourne</city></CityData></Location>
257
+ </ipinfo>
258
+ XML
259
+ end
260
+
261
+ @api.info("4.2.2.2")[:city_name].should == "melbourne"
262
+ end
263
+
264
+ it "maps <Location><CityData><city_cf/></CityData></Location> to :city_confidence" do
265
+ @response.stub(:body) do
266
+ <<-XML
267
+ <ipinfo xmlns="http://data.quova.com/1" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance">
268
+ <Location><CityData><city_cf>51</city_cf></CityData></Location>
269
+ </ipinfo>
270
+ XML
271
+ end
272
+
273
+ @api.info("4.2.2.2")[:city_confidence].should == 51
274
+ end
275
+
276
+ it "maps <Location><CityData><postal_code/></CityData></Location> to :postal_code" do
277
+ @response.stub(:body) do
278
+ <<-XML
279
+ <ipinfo xmlns="http://data.quova.com/1" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance">
280
+ <Location><CityData><postal_code>3000</postal_code></CityData></Location>
281
+ </ipinfo>
282
+ XML
283
+ end
284
+
285
+ @api.info("4.2.2.2")[:postal_code].should == "3000"
286
+ end
287
+
288
+ it "maps <Location><CityData><time_zone/></CityData></Location> to :time_zone" do
289
+ @response.stub(:body) do
290
+ <<-XML
291
+ <ipinfo xmlns="http://data.quova.com/1" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance">
292
+ <Location><CityData><time_zone>10</time_zone></CityData></Location>
293
+ </ipinfo>
294
+ XML
295
+ end
296
+
297
+ @api.info("4.2.2.2")[:time_zone].should == "10"
298
+ end
299
+
300
+ it "maps <Location><CityData><area_code/></CityData></Location> to :area_code" do
301
+ @response.stub(:body) do
302
+ <<-XML
303
+ <ipinfo xmlns="http://data.quova.com/1" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance">
304
+ <Location><CityData><area_code>03</area_code></CityData></Location>
305
+ </ipinfo>
306
+ XML
307
+ end
308
+
309
+ @api.info("4.2.2.2")[:area_code].should == "03"
310
+ end
311
+
312
+ it "maps <Location><longitude/></Location> to :longitude" do
313
+ @response.stub(:body) do
314
+ <<-XML
315
+ <ipinfo xmlns="http://data.quova.com/1" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance">
316
+ <Location><longitude>145.031113</longitude></Location>
317
+ </ipinfo>
318
+ XML
319
+ end
320
+
321
+ @api.info("4.2.2.2")[:longitude].should == 145.031113
322
+ end
323
+
324
+ it "maps <Location><latitude/></Location> to :latitude" do
325
+ @response.stub(:body) do
326
+ <<-XML
327
+ <ipinfo xmlns="http://data.quova.com/1" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance">
328
+ <Location><latitude>-37.8808327</latitude></Location>
329
+ </ipinfo>
330
+ XML
331
+ end
332
+
333
+ @api.info("4.2.2.2")[:latitude].should == -37.8808327
334
+ end
335
+
336
+ it "maps <Location><dma/></Location> to :dma_id" do
337
+ @response.stub(:body) do
338
+ <<-XML
339
+ <ipinfo xmlns="http://data.quova.com/1" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance">
340
+ <Location><dma>1234</dma></Location>
341
+ </ipinfo>
342
+ XML
343
+ end
344
+
345
+ @api.info("4.2.2.2")[:dma_id].should == 1234
346
+ end
347
+
348
+ it "maps <Location><msa/></Location> to :msa_id" do
349
+ @response.stub(:body) do
350
+ <<-XML
351
+ <ipinfo xmlns="http://data.quova.com/1" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance">
352
+ <Location><msa>1234</msa></Location>
353
+ </ipinfo>
354
+ XML
355
+ end
356
+
357
+ @api.info("4.2.2.2")[:msa_id].should == 1234
358
+ end
359
+ end
360
+ end
metadata CHANGED
@@ -1,11 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quova
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
- - Flippa.com Pty. Ltd.
8
+ - Chris Corbyn
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
@@ -13,7 +13,7 @@ date: 2011-07-10 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client
16
- requirement: &14962280 !ruby/object:Gem::Requirement
16
+ requirement: &16674100 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,21 +21,21 @@ dependencies:
21
21
  version: 1.6.3
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *14962280
24
+ version_requirements: *16674100
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: virtus
27
- requirement: &14961780 !ruby/object:Gem::Requirement
27
+ requirement: &16673560 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
31
31
  - !ruby/object:Gem::Version
32
- version: '0'
32
+ version: 0.0.5
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *14961780
35
+ version_requirements: *16673560
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: nokogiri
38
- requirement: &14961200 !ruby/object:Gem::Requirement
38
+ requirement: &16673100 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 1.5.0
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *14961200
46
+ version_requirements: *16673100
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec
49
- requirement: &14960620 !ruby/object:Gem::Requirement
49
+ requirement: &16672640 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '2.6'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *14960620
57
+ version_requirements: *16672640
58
58
  description: Provides a high-level client for Quova's On-Demand REST API
59
59
  email:
60
- - chris@flippa.com
60
+ - chris@w3style.co.uk
61
61
  executables: []
62
62
  extensions: []
63
63
  extra_rdoc_files: []
@@ -69,11 +69,14 @@ files:
69
69
  - Rakefile
70
70
  - lib/quova.rb
71
71
  - lib/quova/qod.rb
72
+ - lib/quova/rest.rb
73
+ - lib/quova/result.rb
72
74
  - lib/quova/version.rb
73
75
  - quova.gemspec
74
76
  - spec/qod_spec.rb
77
+ - spec/rest_spec.rb
75
78
  - spec/spec_helper.rb
76
- homepage: http://flippa.com/
79
+ homepage: https://github.com/d11wtq/quova
77
80
  licenses: []
78
81
  post_install_message:
79
82
  rdoc_options: []