gds-api-adapters 10.14.0 → 10.15.0

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.
@@ -2,12 +2,21 @@ require_relative 'base'
2
2
 
3
3
  class GdsApi::Imminence < GdsApi::Base
4
4
 
5
- def api_url(type, lat, lon, limit=5)
6
- "#{@endpoint}/places/#{type}.json?limit=#{limit}&lat=#{lat}&lng=#{lon}"
5
+ def api_url(type, params)
6
+ vals = [:limit, :lat, :lng, :postcode].select{ |p| params.include? p }
7
+ querystring = URI.encode_www_form vals.map { |p| [p, params[p]] }
8
+ "#{@endpoint}/places/#{type}.json?#{querystring}"
7
9
  end
8
10
 
9
11
  def places(type, lat, lon, limit=5)
10
- places = get_json(api_url(type, lat, lon, limit)) || []
12
+ url = api_url(type, lat: lat, lng: lon, limit: limit)
13
+ places = get_json(url) || []
14
+ places.map { |p| self.class.parse_place_hash(p) }
15
+ end
16
+
17
+ def places_for_postcode(type, postcode, limit=5)
18
+ url = api_url(type, postcode: postcode, limit: limit)
19
+ places = get_json(url) || []
11
20
  places.map { |p| self.class.parse_place_hash(p) }
12
21
  end
13
22
 
@@ -1,3 +1,3 @@
1
1
  module GdsApi
2
- VERSION = '10.14.0'
2
+ VERSION = '10.15.0'
3
3
  end
@@ -98,6 +98,26 @@ class ImminenceApiTest < MiniTest::Unit::TestCase
98
98
  assert_equal LONGITUDE, place["longitude"]
99
99
  end
100
100
 
101
+ def test_postcode_search
102
+ # Test behaviour when searching by postcode
103
+ c = api_client
104
+ url = "#{ROOT}/places/wibble.json?limit=5&postcode=MK42+9AA"
105
+ c.expects(:get_json).with(url).returns([dummy_place])
106
+ places = c.places_for_postcode("wibble", "MK42 9AA")
107
+
108
+ assert_equal 1, places.size
109
+ end
110
+
111
+ def test_invalid_postcode_search
112
+ # Test behaviour when searching by invalid postcode
113
+ c = api_client
114
+ url = "#{ROOT}/places/wibble.json?limit=5&postcode=MK99+9AA"
115
+ c.expects(:get_json).with(url).raises(GdsApi::HTTPErrorResponse.new(400))
116
+ assert_raises GdsApi::HTTPErrorResponse do
117
+ c.places_for_postcode("wibble", "MK99 9AA")
118
+ end
119
+ end
120
+
101
121
  def test_business_support_schemes
102
122
  dummy_schemes = [
103
123
  { "business_support_identifier" => "bar-business-award", "title" => "Bar business award." },
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gds-api-adapters
3
3
  version: !ruby/object:Gem::Version
4
- version: 10.14.0
4
+ version: 10.15.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-06-02 00:00:00.000000000 Z
12
+ date: 2014-06-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: plek
@@ -382,7 +382,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
382
382
  version: '0'
383
383
  segments:
384
384
  - 0
385
- hash: -4129704915142926265
385
+ hash: -1314510237957677542
386
386
  required_rubygems_version: !ruby/object:Gem::Requirement
387
387
  none: false
388
388
  requirements:
@@ -391,7 +391,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
391
391
  version: '0'
392
392
  segments:
393
393
  - 0
394
- hash: -4129704915142926265
394
+ hash: -1314510237957677542
395
395
  requirements: []
396
396
  rubyforge_project:
397
397
  rubygems_version: 1.8.23