gds-api-adapters 10.12.0 → 10.13.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,7 +2,6 @@ require_relative 'base'
2
2
  require_relative 'exceptions'
3
3
 
4
4
  class GdsApi::AssetManager < GdsApi::Base
5
- include GdsApi::ExceptionHandling
6
5
 
7
6
  # Creates an asset given attributes
8
7
  #
@@ -3,7 +3,6 @@ require_relative 'exceptions'
3
3
  require_relative 'list_response'
4
4
 
5
5
  class GdsApi::BusinessSupportApi < GdsApi::Base
6
- include GdsApi::ExceptionHandling
7
6
 
8
7
  def schemes(options = {})
9
8
  get_list!(url_for_slug('business-support-schemes', options))
@@ -3,7 +3,6 @@ require_relative 'exceptions'
3
3
  require_relative 'list_response'
4
4
 
5
5
  class GdsApi::ContentApi < GdsApi::Base
6
- include GdsApi::ExceptionHandling
7
6
 
8
7
  def initialize(endpoint_url, options = {})
9
8
  # If the `web_urls_relative_to` option is given, the adapter will convert
@@ -2,7 +2,6 @@ require_relative 'base'
2
2
  require_relative 'exceptions'
3
3
 
4
4
  class GdsApi::ContentStore < GdsApi::ContentApi
5
- include GdsApi::ExceptionHandling
6
5
 
7
6
  def content_item(base_path)
8
7
  get_json(content_item_url(base_path))
@@ -3,7 +3,6 @@ require_relative 'exceptions'
3
3
  require 'json'
4
4
 
5
5
  class GdsApi::GovUkDelivery < GdsApi::Base
6
- include GdsApi::ExceptionHandling
7
6
 
8
7
  def initialize(endpoint_url, options={})
9
8
  super(endpoint_url, options.merge({timeout: 10}))
data/lib/gds_api/mapit.rb CHANGED
@@ -2,7 +2,6 @@ require_relative 'base'
2
2
  require_relative 'exceptions'
3
3
 
4
4
  class GdsApi::Mapit < GdsApi::Base
5
- include GdsApi::ExceptionHandling
6
5
 
7
6
  def location_for_postcode(postcode)
8
7
  response = get_json("#{base_url}/postcode/#{CGI.escape postcode}.json")
@@ -12,6 +11,10 @@ class GdsApi::Mapit < GdsApi::Base
12
11
  raise GdsApi::HTTPErrorResponse.new(e.code) unless e.code == 400
13
12
  end
14
13
 
14
+ def areas_for_type(type)
15
+ get_json("#{base_url}/areas/#{type}.json")
16
+ end
17
+
15
18
  class Location
16
19
  attr_reader :response
17
20
 
@@ -40,4 +43,5 @@ class GdsApi::Mapit < GdsApi::Base
40
43
  def base_url
41
44
  endpoint
42
45
  end
46
+
43
47
  end
@@ -51,6 +51,15 @@ module GdsApi
51
51
  .to_return(:body => { "code" => 400, "error" => "Postcode '#{postcode}' is not valid." }.to_json, :status => 400)
52
52
  end
53
53
 
54
+ def mapit_has_areas(area_type, areas)
55
+ stub_request(:get, "#{MAPIT_ENDPOINT}/areas/" + area_type + ".json")
56
+ .to_return(:body => areas.to_json, :status => 200)
57
+ end
58
+
59
+ def mapit_does_not_have_areas(area_type)
60
+ stub_request(:get, "#{MAPIT_ENDPOINT}/areas/" + area_type + ".json")
61
+ .to_return(:body => [].to_json, :status => 200)
62
+ end
54
63
  end
55
64
  end
56
65
  end
@@ -1,3 +1,3 @@
1
1
  module GdsApi
2
- VERSION = '10.12.0'
2
+ VERSION = '10.13.0'
3
3
  end
data/test/mapit_test.rb CHANGED
@@ -57,4 +57,30 @@ describe GdsApi::Mapit do
57
57
  assert_nil @api.location_for_postcode("B4DP05TC0D3")
58
58
  end
59
59
  end
60
+ describe "areas_for_type" do
61
+ before do
62
+ mapit_has_areas('EUR', {
63
+ "123" => { "name" => "Eastern", "id" => "123", "country_name" => "England" },
64
+ "234" => { "name" => "North West", "id" => "234", "country_name" => "England" },
65
+ "345" => { "name" => "Scotland", "id" => "345", "country_name" => "Scotland" }
66
+ })
67
+ mapit_does_not_have_areas('FOO')
68
+ end
69
+ it "should return areas of a type" do
70
+ areas = @api.areas_for_type('EUR').to_hash
71
+
72
+ assert_equal 3, areas.size
73
+ assert_equal "Eastern", areas["123"]["name"]
74
+ assert_equal "England", areas["123"]["country_name"]
75
+ assert_equal "North West", areas["234"]["name"]
76
+ assert_equal "England", areas["234"]["country_name"]
77
+ assert_equal "Scotland", areas["345"]["name"]
78
+ assert_equal "Scotland", areas["345"]["country_name"]
79
+ end
80
+ it "should return and empty result for an unknown area type" do
81
+ response = @api.areas_for_type('FOO')
82
+
83
+ assert_empty response
84
+ end
85
+ end
60
86
  end
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.12.0
4
+ version: 10.13.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -382,7 +382,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
382
382
  version: '0'
383
383
  segments:
384
384
  - 0
385
- hash: 331538465080981317
385
+ hash: 4445085740245273405
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: 331538465080981317
394
+ hash: 4445085740245273405
395
395
  requirements: []
396
396
  rubyforge_project:
397
397
  rubygems_version: 1.8.23