gds-api-adapters 7.1.0 → 7.2.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.
- data/lib/gds_api/fact_cave.rb +12 -0
- data/lib/gds_api/helpers.rb +5 -0
- data/lib/gds_api/test_helpers/fact_cave.rb +44 -0
- data/lib/gds_api/version.rb +1 -1
- data/test/fact_cave_test.rb +39 -0
- metadata +8 -4
data/lib/gds_api/helpers.rb
CHANGED
@@ -5,6 +5,7 @@ require 'gds_api/content_api'
|
|
5
5
|
require 'gds_api/licence_application'
|
6
6
|
require 'gds_api/asset_manager'
|
7
7
|
require 'gds_api/worldwide'
|
8
|
+
require 'gds_api/fact_cave'
|
8
9
|
|
9
10
|
module GdsApi
|
10
11
|
module Helpers
|
@@ -16,6 +17,10 @@ module GdsApi
|
|
16
17
|
@content_api ||= GdsApi::ContentApi.new(Plek.current.find("contentapi"), options)
|
17
18
|
end
|
18
19
|
|
20
|
+
def fact_cave_api(options = {})
|
21
|
+
@fact_cave_api ||= GdsApi::FactCave.new(Plek.current.find("fact-cave"), options)
|
22
|
+
end
|
23
|
+
|
19
24
|
def publisher_api(options = {})
|
20
25
|
@api ||= GdsApi::Publisher.new(Plek.current.find("publisher"), options)
|
21
26
|
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'gds_api/test_helpers/json_client_helper'
|
2
|
+
require 'gds_api/test_helpers/common_responses'
|
3
|
+
|
4
|
+
module GdsApi
|
5
|
+
module TestHelpers
|
6
|
+
module FactCave
|
7
|
+
include GdsApi::TestHelpers::CommonResponses
|
8
|
+
|
9
|
+
FACT_CAVE_ENDPOINT = Plek.current.find('fact-cave')
|
10
|
+
|
11
|
+
def fact_cave_has_a_fact(slug, value, extra_attrs={})
|
12
|
+
response = fact_for_slug(slug, value).merge(extra_attrs)
|
13
|
+
|
14
|
+
stub_request(:get, "#{FACT_CAVE_ENDPOINT}/facts/#{slug}")
|
15
|
+
.to_return(:body => response.to_json, :status => 200)
|
16
|
+
stub_request(:get, "#{FACT_CAVE_ENDPOINT}/facts/#{slug}.json")
|
17
|
+
.to_return(:body => response.to_json, :status => 200)
|
18
|
+
end
|
19
|
+
|
20
|
+
def fact_cave_does_not_have_a_fact(slug)
|
21
|
+
response = {
|
22
|
+
"_response_info" => { "status" => "not found" }
|
23
|
+
}
|
24
|
+
|
25
|
+
stub_request(:get, "#{FACT_CAVE_ENDPOINT}/facts/#{slug}")
|
26
|
+
.to_return(:body => response.to_json, :status => 404)
|
27
|
+
stub_request(:get, "#{FACT_CAVE_ENDPOINT}/facts/#{slug}.json")
|
28
|
+
.to_return(:body => response.to_json, :status => 404)
|
29
|
+
end
|
30
|
+
|
31
|
+
def fact_for_slug(slug, value = "Sample Value")
|
32
|
+
singular_response_base.merge({
|
33
|
+
"id" => "#{FACT_CAVE_ENDPOINT}/facts/#{slug}",
|
34
|
+
"details" => {
|
35
|
+
"description" => "",
|
36
|
+
"value" => value,
|
37
|
+
},
|
38
|
+
"name" => titleize_slug(slug),
|
39
|
+
"updated_at" => Time.now.utc.xmlschema,
|
40
|
+
})
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/lib/gds_api/version.rb
CHANGED
@@ -0,0 +1,39 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
require "gds_api/fact_cave"
|
3
|
+
|
4
|
+
describe GdsApi::FactCave do
|
5
|
+
it "should raise an exception if the service at the fact cave URI returns a 500" do
|
6
|
+
stub_request(:get, /example.com\/facts/).to_return(status: [500, "Internal Server Error"])
|
7
|
+
assert_raises(GdsApi::HTTPErrorResponse) do
|
8
|
+
GdsApi::FactCave.new("http://example.com").fact("foo")
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should return nil if the service at the fact cave URI returns a 404" do
|
13
|
+
stub_request(:get, /example.com\/facts/).to_return(status: [404, "Not Found"])
|
14
|
+
assert_nil GdsApi::FactCave.new("http://example.com").fact("bar")
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should raise an exception if the service at the fact cave URI times out" do
|
18
|
+
stub_request(:get, /example.com\/facts/).to_timeout
|
19
|
+
assert_raises(GdsApi::TimedOutException) do
|
20
|
+
GdsApi::FactCave.new("http://example.com").fact("meh")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should return the fact deserialized from json" do
|
25
|
+
fact_cave_result = {"id" => "vat-rate", "title" => "VAT rate", "details" => {
|
26
|
+
"value" => "20%", "description" => "Value Added Tax rate" }}
|
27
|
+
stub_request(:get, "http://example.com/facts/vat-rate").to_return(body: fact_cave_result.to_json)
|
28
|
+
result = GdsApi::FactCave.new("http://example.com").fact("vat-rate")
|
29
|
+
|
30
|
+
assert_equal fact_cave_result, result.to_hash
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should return an empty result without making request if slug is empty" do
|
34
|
+
result = GdsApi::FactCave.new("http://example.com").fact("")
|
35
|
+
|
36
|
+
assert_nil result
|
37
|
+
assert_not_requested :get, /example.com/
|
38
|
+
end
|
39
|
+
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.
|
5
|
+
version: 7.2.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-
|
13
|
+
date: 2013-06-12 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: plek
|
@@ -200,6 +200,7 @@ files:
|
|
200
200
|
- lib/gds_api/mapit.rb
|
201
201
|
- lib/gds_api/exceptions.rb
|
202
202
|
- lib/gds_api/list_response.rb
|
203
|
+
- lib/gds_api/fact_cave.rb
|
203
204
|
- lib/gds_api/json_client.rb
|
204
205
|
- lib/gds_api/core-ext/openstruct.rb
|
205
206
|
- lib/gds_api/response.rb
|
@@ -210,6 +211,7 @@ files:
|
|
210
211
|
- lib/gds_api/test_helpers/imminence.rb
|
211
212
|
- lib/gds_api/test_helpers/content_api.rb
|
212
213
|
- lib/gds_api/test_helpers/mapit.rb
|
214
|
+
- lib/gds_api/test_helpers/fact_cave.rb
|
213
215
|
- lib/gds_api/test_helpers/content_api/artefact_stub.rb
|
214
216
|
- lib/gds_api/test_helpers/publisher.rb
|
215
217
|
- lib/gds_api/test_helpers/asset_manager.rb
|
@@ -234,6 +236,7 @@ files:
|
|
234
236
|
- test/test_helper.rb
|
235
237
|
- test/list_response_test.rb
|
236
238
|
- test/worldwide_api_test.rb
|
239
|
+
- test/fact_cave_test.rb
|
237
240
|
- test/fixtures/world_organisations_australia.json
|
238
241
|
- test/fixtures/hello.txt
|
239
242
|
- test/response_test.rb
|
@@ -254,7 +257,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
254
257
|
requirements:
|
255
258
|
- - ">="
|
256
259
|
- !ruby/object:Gem::Version
|
257
|
-
hash:
|
260
|
+
hash: 2886790745514714453
|
258
261
|
segments:
|
259
262
|
- 0
|
260
263
|
version: "0"
|
@@ -263,7 +266,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
263
266
|
requirements:
|
264
267
|
- - ">="
|
265
268
|
- !ruby/object:Gem::Version
|
266
|
-
hash:
|
269
|
+
hash: 2886790745514714453
|
267
270
|
segments:
|
268
271
|
- 0
|
269
272
|
version: "0"
|
@@ -286,6 +289,7 @@ test_files:
|
|
286
289
|
- test/test_helper.rb
|
287
290
|
- test/list_response_test.rb
|
288
291
|
- test/worldwide_api_test.rb
|
292
|
+
- test/fact_cave_test.rb
|
289
293
|
- test/fixtures/world_organisations_australia.json
|
290
294
|
- test/fixtures/hello.txt
|
291
295
|
- test/response_test.rb
|