geocoder-sensis 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3ee86bd708259c0c624d03ebd1623a4de4a65b16
4
- data.tar.gz: e4746d5443ffe168b4dc680f70f5aef401c11f2c
3
+ metadata.gz: 29daad5f5ef3f4435d7367d5b9788c2656193039
4
+ data.tar.gz: 541861a9642e1368528214631a2b09a845204890
5
5
  SHA512:
6
- metadata.gz: b4319a758539ec3aef97e2475266f25cb132e8b06b649989929d61aa83b88e9c2eb1077849b2b6bc6b3e776de04ad138b658e1eaf64572b8b7e1e4a5d39695a4
7
- data.tar.gz: 42f229bda8568a4f737a754987e942be1fc3cad05365f6fa0de1808109e482e5fbacb961ab0ab744f307bfb2ccd10ed04c99824ca3180d64567d71829ebbf757
6
+ metadata.gz: 48e759a781a1b0f1e7f9cdd8f7ac4e020aaa314ec446bc19b061a0d813329ecae7ce1fcf1c5b05096b4d71870dc23093df19073cc0e25ebf8a32b13ea3ab0f05
7
+ data.tar.gz: a532bb5ba3e27e6c1dede487195e5bfd1ac9bee33137b73c1699d958977781f2f523163ab7fe4b4defa540b10db5b5b8b43ba03b7ac46a168965e6e2faf87ba8
@@ -1,5 +1,5 @@
1
1
  module Geocoder
2
2
  module Sensis
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
@@ -30,6 +30,10 @@ module Geocoder
30
30
  "https"
31
31
  end
32
32
 
33
+ def cache_key(query)
34
+ query.to_s
35
+ end
36
+
33
37
  def results(query)
34
38
  doc = fetch_data(query)
35
39
  return [] unless doc
@@ -42,7 +46,7 @@ module Geocoder
42
46
  # TODO: Raise PR upstream to allow other request methods.
43
47
  #
44
48
  def make_api_request(query)
45
- timeout(configuration.timeout) do
49
+ response = timeout(configuration.timeout) do
46
50
  uri = URI.parse(query_url(query))
47
51
  http_client.start(uri.host, uri.port, :use_ssl => true) do |client|
48
52
  req = Net::HTTP::Post.new(uri.request_uri, configuration.http_headers)
@@ -54,6 +58,15 @@ module Geocoder
54
58
  client.request(req)
55
59
  end
56
60
  end
61
+ case response.code.to_i
62
+ when 200
63
+ return response
64
+ when 400
65
+ raise_error ::Geocoder::InvalidRequest.new("Bad Request: #{response.body}")
66
+ else
67
+ raise_error ::Geocoder::Error.new("Unable to access Sensis API: #{response.code}. Body:\n#{response.body}")
68
+ end
69
+ response
57
70
  end
58
71
 
59
72
  def result_class
@@ -94,6 +107,7 @@ module Geocoder
94
107
  end
95
108
 
96
109
  class SensisStructured < SensisBase
110
+
97
111
  def name
98
112
  :sensis_structured
99
113
  end
@@ -35,36 +35,59 @@ describe Geocoder::Sensis do
35
35
  end
36
36
 
37
37
  describe "Geocoding an address via structured api" do
38
+
38
39
  before do
39
40
  Geocoder.configure(
40
41
  :lookup => :sensis_structured,
41
42
  :api_key => [sensis_api_token, sensis_api_password],
42
43
  :use_https => true,
43
- :timeout => 30000
44
+ :timeout => 30000,
45
+ :always_raise => :all,
44
46
  )
45
- mock_sensis_api :request_type => :structured,
46
- :address => '12 Powlett Street, East Melbourne',
47
- :latitude => 44.66,
48
- :longitude => 55.66
49
47
  end
50
48
 
51
- it "returns the geocode from sensis" do
52
- coords = Geocoder.coordinates(
53
- "state" => "Vic",
54
- "suburb" => "Richmond",
55
- "postcode" => "3121",
56
- "number" => "9",
57
- "street" => {
58
- "name" => "Victoria",
59
- "type" => "Street",
60
- "suffix" => ""
61
- })
49
+ describe "with an invalid address (returning http 400)" do
50
+ it "throws an ::Geocoder::InvalidRequest" do
51
+ mock_sensis_api :request_type => :structured, :response_code => 400
52
+ expect {
53
+ Geocoder.coordinates({})
54
+ }.to raise_error(::Geocoder::InvalidRequest)
55
+ end
56
+ end
62
57
 
63
- expect(coords).to eq [44.66, 55.66]
58
+ describe "when sensis is down (returning http 500)" do
59
+ it "throws an ::Geocoder::Error" do
60
+ mock_sensis_api :request_type => :structured, :response_code => 500
61
+ expect {
62
+ Geocoder.coordinates({})
63
+ }.to raise_error(::Geocoder::Error)
64
+ end
64
65
  end
65
66
 
66
- end
67
+ describe "with a valid address" do
68
+ before do
69
+ mock_sensis_api(:request_type => :structured,
70
+ :address => '12 Powlett Street, East Melbourne',
71
+ :latitude => 44.66,
72
+ :longitude => 55.66)
73
+ end
67
74
 
68
- end
75
+ it "returns the geocode from sensis" do
76
+ coords = Geocoder.coordinates(
77
+ "state" => "Vic",
78
+ "suburb" => "Richmond",
79
+ "postcode" => "3121",
80
+ "number" => "9",
81
+ "street" => {
82
+ "name" => "Victoria",
83
+ "type" => "Street",
84
+ "suffix" => ""
85
+ })
86
+
87
+ expect(coords).to eq [44.66, 55.66]
88
+ end
69
89
 
90
+ end
91
+ end
70
92
 
93
+ end
@@ -25,12 +25,11 @@ def mock_sensis_api(options = {})
25
25
  'X-Auth-Token' => sensis_api_token,
26
26
  'X-Auth-Password' => sensis_api_password
27
27
  }).
28
- to_return(:status => sensis_response.code, :body => sensis_response.raw, :headers => {})
28
+ to_return(:status => sensis_response.response_code, :body => sensis_response.raw, :headers => {})
29
29
  end
30
30
 
31
-
32
31
  class SensisResponse
33
- attr_reader :request_address, :request_type, :latitude, :longitude, :street_lat, :street_lon, :granularity, :code, :state, :suburb
32
+ attr_reader :request_address, :request_type, :latitude, :longitude, :street_lat, :street_lon, :granularity, :response_code, :state, :suburb
34
33
 
35
34
  def initialize(options = {})
36
35
  defaults.merge(options).each do |k, v|
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geocoder-sensis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Heath
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-05 00:00:00.000000000 Z
11
+ date: 2014-02-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: geocoder