gds-api-adapters 7.2.0 → 7.3.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.
@@ -10,6 +10,11 @@ module GdsApi
10
10
 
11
11
  include GdsApi::ExceptionHandling
12
12
 
13
+ # Cache TTL will be overridden for a given request/response by the Expires
14
+ # header if it is included in the response.
15
+ #
16
+ # LRUCache doesn't respect a cache size of 0, and instead effectively
17
+ # creates a cache with a size of 1.
13
18
  def self.cache(size=DEFAULT_CACHE_SIZE, ttl=DEFAULT_CACHE_TTL)
14
19
  @cache ||= LRUCache.new(max_size: size, ttl: ttl)
15
20
  end
@@ -27,7 +32,7 @@ module GdsApi
27
32
 
28
33
  @logger = options[:logger] || GdsApi::Base.logger
29
34
 
30
- if options[:disable_cache]
35
+ if options[:disable_cache] || (options[:cache_size] == 0)
31
36
  @cache = NullCache.new
32
37
  else
33
38
  cache_size = options[:cache_size] || DEFAULT_CACHE_SIZE
@@ -0,0 +1,12 @@
1
+ require_relative 'base'
2
+
3
+ class GdsApi::Support < GdsApi::Base
4
+ def create_foi_request(request_details)
5
+ post_json("#{base_url}/foi_requests", { :foi_request => request_details })
6
+ end
7
+
8
+ private
9
+ def base_url
10
+ endpoint
11
+ end
12
+ end
@@ -0,0 +1,19 @@
1
+ module GdsApi
2
+ module TestHelpers
3
+ module Support
4
+ SUPPORT_ENDPOINT = Plek.current.find('support')
5
+
6
+ def stub_support_foi_request_creation(request_details = nil)
7
+ body_expectation = {"foi_request" => request_details}.to_json
8
+
9
+ post_stub = stub_request(:post, "#{SUPPORT_ENDPOINT}/foi_requests")
10
+ post_stub.with(:body => {"foi_request" => request_details}.to_json) unless request_details.nil?
11
+ post_stub.to_return(:status => 201)
12
+ end
13
+
14
+ def support_isnt_available
15
+ stub_request(:post, /#{SUPPORT_ENDPOINT}\/.*/).to_return(:status => 503)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1,3 +1,3 @@
1
1
  module GdsApi
2
- VERSION = '7.2.0'
2
+ VERSION = '7.3.0'
3
3
  end
@@ -57,10 +57,19 @@ class GdsApiBaseTest < MiniTest::Unit::TestCase
57
57
  end
58
58
 
59
59
  def test_disabling_cache
60
+ # Ensure that there is a non-null cache by default
61
+ GdsApi::JsonClient.cache = true
60
62
  api = ConcreteApi.new("http://bar", disable_cache: true)
61
63
  assert api.client.cache.is_a? GdsApi::NullCache
62
64
  end
63
65
 
66
+ def test_disabling_cache_old_style
67
+ # Ensure that there is a non-null cache by default
68
+ GdsApi::JsonClient.cache = true
69
+ api = ConcreteApi.new("http://bar", cache_size: 0)
70
+ assert api.client.cache.is_a? GdsApi::NullCache
71
+ end
72
+
64
73
  def test_should_barf_if_not_given_valid_URL
65
74
  proc do
66
75
  ConcreteApi.new('invalid-url')
@@ -0,0 +1,21 @@
1
+ require 'test_helper'
2
+ require 'gds_api/support'
3
+
4
+ describe GdsApi::Support do
5
+ before do
6
+ @base_api_url = Plek.current.find("support")
7
+ @api = GdsApi::Support.new(@base_api_url)
8
+ end
9
+
10
+ it "can create an asset with a file" do
11
+ request_details = {"foi_request"=>{"requester"=>{"name"=>"A", "email"=>"a@b.com"}, "details"=>"abc"}}
12
+
13
+ stub_post = stub_request(:post, "#{@base_api_url}/foi_requests").
14
+ with(:body => {"foi_request" => request_details}.to_json).
15
+ to_return(:status => 201)
16
+
17
+ @api.create_foi_request(request_details)
18
+
19
+ assert_requested(stub_post)
20
+ end
21
+ 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: 7.2.0
5
+ version: 7.3.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: 2013-06-12 00:00:00 Z
13
+ date: 2013-08-12 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: plek
@@ -205,6 +205,7 @@ files:
205
205
  - lib/gds_api/core-ext/openstruct.rb
206
206
  - lib/gds_api/response.rb
207
207
  - lib/gds_api/publisher.rb
208
+ - lib/gds_api/support.rb
208
209
  - lib/gds_api/test_helpers/gov_uk_delivery.rb
209
210
  - lib/gds_api/test_helpers/licence_application.rb
210
211
  - lib/gds_api/test_helpers/common_responses.rb
@@ -214,6 +215,7 @@ files:
214
215
  - lib/gds_api/test_helpers/fact_cave.rb
215
216
  - lib/gds_api/test_helpers/content_api/artefact_stub.rb
216
217
  - lib/gds_api/test_helpers/publisher.rb
218
+ - lib/gds_api/test_helpers/support.rb
217
219
  - lib/gds_api/test_helpers/asset_manager.rb
218
220
  - lib/gds_api/test_helpers/panopticon.rb
219
221
  - lib/gds_api/test_helpers/json_client_helper.rb
@@ -237,6 +239,7 @@ files:
237
239
  - test/list_response_test.rb
238
240
  - test/worldwide_api_test.rb
239
241
  - test/fact_cave_test.rb
242
+ - test/support_api_test.rb
240
243
  - test/fixtures/world_organisations_australia.json
241
244
  - test/fixtures/hello.txt
242
245
  - test/response_test.rb
@@ -257,7 +260,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
257
260
  requirements:
258
261
  - - ">="
259
262
  - !ruby/object:Gem::Version
260
- hash: 2886790745514714453
263
+ hash: -933955563815808271
261
264
  segments:
262
265
  - 0
263
266
  version: "0"
@@ -266,7 +269,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
266
269
  requirements:
267
270
  - - ">="
268
271
  - !ruby/object:Gem::Version
269
- hash: 2886790745514714453
272
+ hash: -933955563815808271
270
273
  segments:
271
274
  - 0
272
275
  version: "0"
@@ -290,6 +293,7 @@ test_files:
290
293
  - test/list_response_test.rb
291
294
  - test/worldwide_api_test.rb
292
295
  - test/fact_cave_test.rb
296
+ - test/support_api_test.rb
293
297
  - test/fixtures/world_organisations_australia.json
294
298
  - test/fixtures/hello.txt
295
299
  - test/response_test.rb