gds-api-adapters 4.1.0 → 4.1.1

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.
data/lib/gds_api/base.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require_relative 'json_client'
2
2
  require 'cgi'
3
3
  require 'null_logger'
4
+ require 'plek'
4
5
 
5
6
  class GdsApi::Base
6
7
  class InvalidAPIURL < StandardError
@@ -5,7 +5,9 @@ require_relative 'content_api/artefact_stub'
5
5
  module GdsApi
6
6
  module TestHelpers
7
7
  module ContentApi
8
- CONTENT_API_ENDPOINT = 'https://contentapi.test.alphagov.co.uk'
8
+ # Generally true. If you are initializing the client differently,
9
+ # you could redefine/override the constant or stub directly.
10
+ CONTENT_API_ENDPOINT = Plek.current.find('contentapi')
9
11
 
10
12
  # Takes an array of slugs, or hashes with section details (including a slug).
11
13
  # Will stub out content_api calls for tags of type section to return these sections
@@ -3,7 +3,10 @@ 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
+ # Generally true. If you are initializing the client differently,
7
+ # you could redefine/override the constant or stub directly.
8
+ IMMINENCE_API_HOST = URI.parse(Plek.current.find('imminence')).host
9
+
7
10
  def imminence_has_places(latitude, longitude, details)
8
11
  response = JSON.dump(details['details'])
9
12
 
@@ -3,7 +3,9 @@ require 'gds_api/test_helpers/json_client_helper'
3
3
  module GdsApi
4
4
  module TestHelpers
5
5
  module LicenceApplication
6
- LICENCE_APPLICATION_ENDPOINT = "https://licensify.test.alphagov.co.uk"
6
+ # Generally true. If you are initializing the client differently,
7
+ # you could redefine/override the constant or stub directly.
8
+ LICENCE_APPLICATION_ENDPOINT = Plek.current.find("licensify")
7
9
 
8
10
  def licence_exists(identifier, licence)
9
11
  licence = licence.to_json unless licence.is_a?(String)
@@ -3,7 +3,9 @@ require 'gds_api/test_helpers/json_client_helper'
3
3
  module GdsApi
4
4
  module TestHelpers
5
5
  module Panopticon
6
- PANOPTICON_ENDPOINT = 'https://panopticon.test.alphagov.co.uk'
6
+ # Generally true. If you are initializing the client differently,
7
+ # you could redefine/override the constant or stub directly.
8
+ PANOPTICON_ENDPOINT = Plek.current.find('panopticon')
7
9
 
8
10
  def stringify_hash_keys(input_hash)
9
11
  input_hash.inject({}) do |options, (key, value)|
@@ -3,7 +3,9 @@ require 'gds_api/test_helpers/json_client_helper'
3
3
  module GdsApi
4
4
  module TestHelpers
5
5
  module Publisher
6
- PUBLISHER_ENDPOINT = "https://publisher.test.alphagov.co.uk"
6
+ # Generally true. If you are initializing the client differently,
7
+ # you could redefine/override the constant or stub directly.
8
+ PUBLISHER_ENDPOINT = Plek.current.find("publisher")
7
9
 
8
10
  def publication_exists(details, options = {})
9
11
  json = JSON.dump(details)
@@ -1,3 +1,3 @@
1
1
  module GdsApi
2
- VERSION = '4.1.0'
2
+ VERSION = '4.1.1'
3
3
  end
@@ -6,7 +6,7 @@ describe GdsApi::ContentApi do
6
6
  include GdsApi::TestHelpers::ContentApi
7
7
 
8
8
  before do
9
- @base_api_url = "https://contentapi.test.alphagov.co.uk"
9
+ @base_api_url = Plek.current.find("contentapi")
10
10
  @api = GdsApi::ContentApi.new(@base_api_url)
11
11
  end
12
12
 
@@ -15,7 +15,7 @@ describe GdsApi::ContentApi do
15
15
  content_api_has_root_sections(["crime"])
16
16
  response = @api.sections
17
17
  first_section = response["results"][0]
18
- assert_equal "https://contentapi.test.alphagov.co.uk/tags/crime.json", first_section["id"]
18
+ assert_equal "#{@base_api_url}/tags/crime.json", first_section["id"]
19
19
  end
20
20
  end
21
21
 
@@ -23,14 +23,14 @@ describe GdsApi::ContentApi do
23
23
  it "should show the artefact" do
24
24
  content_api_has_an_artefact("devolution-uk")
25
25
  response = @api.artefact("devolution-uk")
26
- assert_equal "https://contentapi.test.alphagov.co.uk/devolution-uk.json", response["id"]
26
+ assert_equal "#{@base_api_url}/devolution-uk.json", response["id"]
27
27
  end
28
28
 
29
29
  it "should be able to fetch unpublished editions when authenticated" do
30
30
  api = GdsApi::ContentApi.new(@base_api_url, { bearer_token: 'MY_BEARER_TOKEN' })
31
31
  content_api_has_unpublished_artefact("devolution-uk", 3)
32
32
  response = api.artefact("devolution-uk", edition: 3)
33
- assert_equal "https://contentapi.test.alphagov.co.uk/devolution-uk.json", response["id"]
33
+ assert_equal "#{@base_api_url}/devolution-uk.json", response["id"]
34
34
  end
35
35
 
36
36
  it "should raise an exception if no bearer token is used when fetching unpublished editions" do
@@ -304,19 +304,19 @@ describe GdsApi::ContentApi do
304
304
 
305
305
  assert_requested :get, %r{\A#{@base_api_url}/business_support_schemes\.json}, :times => 2
306
306
 
307
- first_batch = ids[0..190]
307
+ first_batch = ids[0..191]
308
308
  assert_requested :get, "#{@base_api_url}/business_support_schemes.json?identifiers=#{first_batch.join(',')}"
309
- second_batch = ids[191..299]
309
+ second_batch = ids[192..299]
310
310
  assert_requested :get, "#{@base_api_url}/business_support_schemes.json?identifiers=#{second_batch.join(',')}"
311
311
  end
312
312
 
313
313
  it "should merge the responses into a single GdsApi::Response" do
314
314
  ids = (1..300).map {|n| sprintf "%09d", n } # each id is 9 chars long
315
- first_batch = ids[0..190]
315
+ first_batch = ids[0..191]
316
316
  stub_request(:get, "#{@base_api_url}/business_support_schemes.json").
317
317
  with(:query => {"identifiers" => first_batch.join(',')}).
318
318
  to_return(:status => 200, :body => api_response_for_results(first_batch).to_json) # We're stubbing response that just return the requested ids
319
- second_batch = ids[191..299]
319
+ second_batch = ids[192..299]
320
320
  stub_request(:get, "#{@base_api_url}/business_support_schemes.json").
321
321
  with(:query => {"identifiers" => second_batch.join(',')}).
322
322
  to_return(:status => 200, :body => api_response_for_results(second_batch).to_json)
data/test/test_helper.rb CHANGED
@@ -1,3 +1,8 @@
1
+ # Ensure that in tests, we get a consistent domain back from Plek < 1.0.0
2
+ # Without this, content API tests re chunking of requests with long URLs would
3
+ # pass/fail in dev/CI.
4
+ ENV['RACK_ENV'] = "test"
5
+
1
6
  require 'bundler'
2
7
  Bundler.setup :default, :development, :test
3
8
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: gds-api-adapters
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 4.1.0
5
+ version: 4.1.1
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-11-26 00:00:00 Z
13
+ date: 2012-11-27 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: plek
@@ -214,7 +214,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
214
214
  requirements:
215
215
  - - ">="
216
216
  - !ruby/object:Gem::Version
217
- hash: -316804673231244671
217
+ hash: 3713358432051665576
218
218
  segments:
219
219
  - 0
220
220
  version: "0"
@@ -223,7 +223,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
223
223
  requirements:
224
224
  - - ">="
225
225
  - !ruby/object:Gem::Version
226
- hash: -316804673231244671
226
+ hash: 3713358432051665576
227
227
  segments:
228
228
  - 0
229
229
  version: "0"