gds-api-adapters 2.8.1 → 2.9.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -21,6 +21,12 @@ class GdsApi::Imminence < GdsApi::Base
21
21
  def places_kml(type)
22
22
  get_raw("#{@endpoint}/places/#{type}.kml")
23
23
  end
24
+
25
+ def business_support_schemes(facets_hash)
26
+ query = facets_hash.keys.sort.map { |k| "#{k.to_s}=#{facets_hash[k]}" }.join("&")
27
+ query = "?#{query}" unless query.empty?
28
+ get_json!("#{@endpoint}/business_support_schemes.json#{query}")
29
+ end
24
30
 
25
31
  private
26
32
  def self.extract_location_hash(location)
@@ -3,15 +3,43 @@ require 'gds_api/test_helpers/json_client_helper'
3
3
  module GdsApi
4
4
  module TestHelpers
5
5
  module Imminence
6
+ IMMINENCE_API_HOST = "imminence.test.alphagov.co.uk"
6
7
  def imminence_has_places(latitude, longitude, details)
7
8
  response = JSON.dump(details['details'])
8
9
 
9
10
  ["http", "https"].each do |protocol|
10
- stub_request(:get, "#{protocol}://imminence.test.alphagov.co.uk/places/#{details['slug']}.json").
11
+ stub_request(:get, "#{protocol}://#{IMMINENCE_API_HOST}/places/#{details['slug']}.json").
11
12
  with(:query => {"lat" => latitude, "lng" => longitude, "limit" => "5"}).
12
13
  to_return(:status => 200, :body => response, :headers => {})
13
14
  end
14
15
  end
16
+
17
+ def imminence_has_business_support_schemes(facets_hash, schemes)
18
+ results = {
19
+ "_response_info" => {"status" => "ok"},
20
+ "description" => "Business Support Schemes!",
21
+ "total" => schemes.size, "startIndex" => 1, "pageSize" => schemes.size, "currentPage" => 1, "pages" => 1,
22
+ "results" => schemes
23
+ }
24
+
25
+ stub_request(:get, "https://#{IMMINENCE_API_HOST}/business_support_schemes.json").
26
+ with(query: facets_hash).
27
+ to_return(status: 200, body: results.to_json, headers: {})
28
+ end
29
+
30
+ # Stubs out all bussiness_support_schemes requests to return an ampty set of results.
31
+ # Requests stubbed with the above method will take precedence over this.
32
+ def stub_imminence_default_business_support_schemes
33
+ empty_results = {
34
+ "_response_info" => {"status" => "ok"},
35
+ "description" => "Business Support Schemes!",
36
+ "total" => 0, "startIndex" => 1, "pageSize" => 0, "currentPage" => 1, "pages" => 1,
37
+ "results" => []
38
+ }
39
+
40
+ stub_request(:get, %r{\Ahttps://#{IMMINENCE_API_HOST}/business_support_schemes\.json}).
41
+ to_return(:body => empty_results.to_json)
42
+ end
15
43
  end
16
44
  end
17
45
  end
@@ -1,3 +1,3 @@
1
1
  module GdsApi
2
- VERSION = '2.8.1'
2
+ VERSION = '2.9.0'
3
3
  end
@@ -97,4 +97,23 @@ class ImminenceApiTest < MiniTest::Unit::TestCase
97
97
  assert_equal LATITUDE, place["latitude"]
98
98
  assert_equal LONGITUDE, place["longitude"]
99
99
  end
100
+
101
+ def test_business_support_schemes
102
+ dummy_schemes = [
103
+ { "business_support_identifier" => "bar-business-award", "title" => "Bar business award." },
104
+ { "business_support_identifier" => "bar-small-business-loan", "title" => "Bar small business loan." },
105
+ { "business_support_identifier" => "foo-small-business-loan", "title" => "Foo small business loan." }
106
+ ]
107
+ c = api_client
108
+ url = "#{ROOT}/business_support_schemes.json?business_types=private-company&" +
109
+ "sectors=agriculture,healthcare,manufacturing&stages=grow-and-sustain&types=award,loan"
110
+ c.expects(:get_json!).with(url).returns(dummy_schemes)
111
+
112
+ schemes = c.business_support_schemes(sectors: "agriculture,healthcare,manufacturing",
113
+ business_types: "private-company", stages: "grow-and-sustain", types: "award,loan")
114
+
115
+ assert_equal 3, schemes.size
116
+ assert_equal "bar-business-award", schemes.first["business_support_identifier"]
117
+ assert_equal "Foo small business loan.", schemes.last["title"]
118
+ end
100
119
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: gds-api-adapters
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 2.8.1
5
+ version: 2.9.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - James Stewart
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-09-26 00:00:00 Z
13
+ date: 2012-09-27 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: plek
@@ -205,7 +205,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
205
205
  requirements:
206
206
  - - ">="
207
207
  - !ruby/object:Gem::Version
208
- hash: -3426939918744885980
208
+ hash: 3131893873068674307
209
209
  segments:
210
210
  - 0
211
211
  version: "0"
@@ -214,7 +214,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
214
214
  requirements:
215
215
  - - ">="
216
216
  - !ruby/object:Gem::Version
217
- hash: -3426939918744885980
217
+ hash: 3131893873068674307
218
218
  segments:
219
219
  - 0
220
220
  version: "0"