gds-api-adapters 30.5.0 → 30.6.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.
- checksums.yaml +4 -4
- data/lib/gds_api/base.rb +2 -1
- data/lib/gds_api/json_client.rb +2 -1
- data/lib/gds_api/publishing_api/special_route_publisher.rb +2 -1
- data/lib/gds_api/publishing_api_v2.rb +30 -0
- data/lib/gds_api/test_helpers/publishing_api_v2.rb +5 -0
- data/lib/gds_api/version.rb +1 -1
- data/test/gds_api_base_test.rb +21 -0
- data/test/json_client_test.rb +11 -0
- data/test/publishing_api/special_route_publisher_test.rb +2 -1
- data/test/publishing_api_v2/get_expanded_links_test.rb +85 -0
- data/test/publishing_api_v2/get_links_test.rb +85 -0
- data/test/publishing_api_v2_test.rb +0 -73
- data/test/test_helpers/publishing_api_v2_test.rb +25 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a4e28b623478c809c5e960c46012dc514ff8205e
|
4
|
+
data.tar.gz: 7945f3261866b017b6765f057dca650585761f81
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7226bc20099596193ef8e9b3c414a4a075fc45f28d8464ec15b4ab683f820d8715f117c5bb8930d34b970b62194fdb5650523cd026e11a86d8d7eec6b9fd9ad5
|
7
|
+
data.tar.gz: ceeb159b50485e441b1db84076b582bbb080a570637ced31fdb2931d1c0ffb4237257e3f22884cc5591771df7eb84aa9b4be8b7e27ab6c40607539b6fc6d5a67
|
data/lib/gds_api/base.rb
CHANGED
@@ -41,7 +41,8 @@ class GdsApi::Base
|
|
41
41
|
def initialize(endpoint_url, options={})
|
42
42
|
options[:endpoint_url] = endpoint_url
|
43
43
|
raise InvalidAPIURL unless endpoint_url =~ URI::regexp
|
44
|
-
|
44
|
+
base_options = { logger: self.class.logger }
|
45
|
+
default_options = base_options.merge(GdsApi::Base.default_options || {})
|
45
46
|
@options = default_options.merge(options)
|
46
47
|
self.endpoint = options[:endpoint_url]
|
47
48
|
end
|
data/lib/gds_api/json_client.rb
CHANGED
@@ -5,6 +5,7 @@ require_relative 'null_cache'
|
|
5
5
|
require_relative 'govuk_headers'
|
6
6
|
require 'lrucache'
|
7
7
|
require 'rest-client'
|
8
|
+
require 'null_logger'
|
8
9
|
|
9
10
|
module GdsApi
|
10
11
|
class JsonClient
|
@@ -38,7 +39,7 @@ module GdsApi
|
|
38
39
|
raise "It is no longer possible to disable the timeout."
|
39
40
|
end
|
40
41
|
|
41
|
-
@logger = options[:logger] ||
|
42
|
+
@logger = options[:logger] || NullLogger.instance
|
42
43
|
|
43
44
|
if options[:disable_cache] || (options[:cache_size] == 0)
|
44
45
|
@cache = NullCache.new
|
@@ -14,7 +14,8 @@ module GdsApi
|
|
14
14
|
|
15
15
|
put_content_response = publishing_api.put_content(options.fetch(:content_id), {
|
16
16
|
base_path: options.fetch(:base_path),
|
17
|
-
|
17
|
+
document_type: "special_route",
|
18
|
+
schema_name: "special_route",
|
18
19
|
title: options.fetch(:title),
|
19
20
|
description: options[:description] || "",
|
20
21
|
routes: [
|
@@ -162,6 +162,36 @@ class GdsApi::PublishingApiV2 < GdsApi::Base
|
|
162
162
|
get_json(links_url(content_id))
|
163
163
|
end
|
164
164
|
|
165
|
+
# Get expanded links
|
166
|
+
#
|
167
|
+
# Return the expanded links of the item.
|
168
|
+
#
|
169
|
+
# @param content_id [UUID]
|
170
|
+
#
|
171
|
+
# @example
|
172
|
+
#
|
173
|
+
# publishing_api.get_expanded_links("8157589b-65e2-4df6-92ba-2c91d80006c0").to_h
|
174
|
+
#
|
175
|
+
# #=> {
|
176
|
+
# "content_id" => "8157589b-65e2-4df6-92ba-2c91d80006c0",
|
177
|
+
# "version" => 10,
|
178
|
+
# "expanded_links" => {
|
179
|
+
# "organisations" => [
|
180
|
+
# {
|
181
|
+
# "content_id" => "21aa83a2-a47f-4189-a252-b02f8c322012",
|
182
|
+
# ... (and more attributes)
|
183
|
+
# }
|
184
|
+
# ]
|
185
|
+
# }
|
186
|
+
# }
|
187
|
+
#
|
188
|
+
# @see https://github.com/alphagov/publishing-api/blob/master/doc/publishing-api-syntactic-usage.md#get-v2expanded-linkscontent_id
|
189
|
+
def get_expanded_links(content_id)
|
190
|
+
validate_content_id(content_id)
|
191
|
+
url = "#{endpoint}/v2/expanded-links/#{content_id}"
|
192
|
+
get_json(url)
|
193
|
+
end
|
194
|
+
|
165
195
|
# Patch the links of a content item
|
166
196
|
#
|
167
197
|
# @param content_id [UUID]
|
@@ -201,6 +201,11 @@ module GdsApi
|
|
201
201
|
stub_request(:get, url).to_return(status: 200, body: links.to_json, headers: {})
|
202
202
|
end
|
203
203
|
|
204
|
+
def publishing_api_has_expanded_links(links)
|
205
|
+
url = PUBLISHING_API_V2_ENDPOINT + "/expanded-links/" + links[:content_id]
|
206
|
+
stub_request(:get, url).to_return(status: 200, body: links.to_json, headers: {})
|
207
|
+
end
|
208
|
+
|
204
209
|
def publishing_api_does_not_have_links(content_id)
|
205
210
|
url = PUBLISHING_API_V2_ENDPOINT + "/links/" + content_id
|
206
211
|
stub_request(:get, url).to_return(status: 404, body: resource_not_found(content_id, "link set").to_json, headers: {})
|
data/lib/gds_api/version.rb
CHANGED
data/test/gds_api_base_test.rb
CHANGED
@@ -15,6 +15,7 @@ class GdsApiBaseTest < Minitest::Test
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def teardown
|
18
|
+
GdsApi::Base.default_options = nil
|
18
19
|
GdsApi::JsonClient.cache = @orig_cache
|
19
20
|
end
|
20
21
|
|
@@ -87,4 +88,24 @@ class GdsApiBaseTest < Minitest::Test
|
|
87
88
|
ConcreteApi.new('invalid-url')
|
88
89
|
end.must_raise GdsApi::Base::InvalidAPIURL
|
89
90
|
end
|
91
|
+
|
92
|
+
def test_should_set_json_client_logger_to_own_logger_by_default
|
93
|
+
api = ConcreteApi.new("http://bar")
|
94
|
+
assert_same GdsApi::Base.logger, api.client.logger
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_should_set_json_client_logger_to_logger_in_default_options
|
98
|
+
custom_logger = stub('custom-logger')
|
99
|
+
GdsApi::Base.default_options = { logger: custom_logger }
|
100
|
+
api = ConcreteApi.new("http://bar")
|
101
|
+
assert_same custom_logger, api.client.logger
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_should_set_json_client_logger_to_logger_in_options
|
105
|
+
custom_logger = stub('custom-logger')
|
106
|
+
GdsApi::Base.default_options = { logger: custom_logger }
|
107
|
+
another_logger = stub('another-logger')
|
108
|
+
api = ConcreteApi.new("http://bar", logger: another_logger)
|
109
|
+
assert_same another_logger, api.client.logger
|
110
|
+
end
|
90
111
|
end
|
data/test/json_client_test.rb
CHANGED
@@ -2,6 +2,7 @@ require_relative 'test_helper'
|
|
2
2
|
require 'gds_api/base'
|
3
3
|
require 'gds_api/json_client'
|
4
4
|
require 'base64'
|
5
|
+
require 'null_logger'
|
5
6
|
|
6
7
|
class JsonClientTest < MiniTest::Spec
|
7
8
|
def setup
|
@@ -826,4 +827,14 @@ class JsonClientTest < MiniTest::Spec
|
|
826
827
|
ensure
|
827
828
|
ENV['GOVUK_APP_NAME'] = previous_govuk_app_name
|
828
829
|
end
|
830
|
+
|
831
|
+
def test_should_default_to_using_null_logger
|
832
|
+
assert_same @client.logger, NullLogger.instance
|
833
|
+
end
|
834
|
+
|
835
|
+
def test_should_use_custom_logger_specified_in_options
|
836
|
+
custom_logger = stub('custom-logger')
|
837
|
+
client = GdsApi::JsonClient.new(logger: custom_logger)
|
838
|
+
assert_same client.logger, custom_logger
|
839
|
+
end
|
829
840
|
end
|
@@ -32,7 +32,8 @@ describe GdsApi::PublishingApi::SpecialRoutePublisher do
|
|
32
32
|
|
33
33
|
expected_payload = {
|
34
34
|
base_path: special_route[:base_path],
|
35
|
-
|
35
|
+
document_type: "special_route",
|
36
|
+
schema_name: "special_route",
|
36
37
|
title: special_route[:title],
|
37
38
|
description: special_route[:description],
|
38
39
|
routes: [
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'gds_api/publishing_api_v2'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
describe GdsApi::PublishingApiV2 do
|
6
|
+
include PactTest
|
7
|
+
|
8
|
+
before do
|
9
|
+
@api_client = GdsApi::PublishingApiV2.new('http://localhost:3093')
|
10
|
+
@content_id = "bed722e6-db68-43e5-9079-063f623335a7"
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "#get_expanded_links" do
|
14
|
+
it "responds with the links when there's a links entry with links" do
|
15
|
+
publishing_api
|
16
|
+
.given("organisation links exist for content_id #{@content_id}")
|
17
|
+
.upon_receiving("a get-expanded-links request")
|
18
|
+
.with(
|
19
|
+
method: :get,
|
20
|
+
path: "/v2/expanded-links/#{@content_id}",
|
21
|
+
)
|
22
|
+
.will_respond_with(
|
23
|
+
status: 200,
|
24
|
+
body: {
|
25
|
+
expanded_links: {
|
26
|
+
organisations: [
|
27
|
+
{ content_id: "20583132-1619-4c68-af24-77583172c070" }
|
28
|
+
]
|
29
|
+
}
|
30
|
+
}
|
31
|
+
)
|
32
|
+
|
33
|
+
response = @api_client.get_expanded_links(@content_id)
|
34
|
+
|
35
|
+
expected_body = {
|
36
|
+
"expanded_links" => {
|
37
|
+
"organisations" => [
|
38
|
+
{ "content_id" => "20583132-1619-4c68-af24-77583172c070" }
|
39
|
+
]
|
40
|
+
}
|
41
|
+
}
|
42
|
+
assert_equal 200, response.code
|
43
|
+
assert_equal expected_body, response.to_h
|
44
|
+
end
|
45
|
+
|
46
|
+
it "responds with the empty thing set if there's an empty link set" do
|
47
|
+
publishing_api
|
48
|
+
.given("empty links exist for content_id #{@content_id}")
|
49
|
+
.upon_receiving("a get-expanded-links request")
|
50
|
+
.with(
|
51
|
+
method: :get,
|
52
|
+
path: "/v2/expanded-links/#{@content_id}",
|
53
|
+
)
|
54
|
+
.will_respond_with(
|
55
|
+
status: 200,
|
56
|
+
body: {
|
57
|
+
expanded_links: {
|
58
|
+
}
|
59
|
+
}
|
60
|
+
)
|
61
|
+
|
62
|
+
response = @api_client.get_expanded_links(@content_id)
|
63
|
+
|
64
|
+
assert_equal 200, response.code
|
65
|
+
assert_equal({}, response.to_h['expanded_links'])
|
66
|
+
end
|
67
|
+
|
68
|
+
it "responds with 404 if there's no link set entry" do
|
69
|
+
publishing_api
|
70
|
+
.given("no links exist for content_id #{@content_id}")
|
71
|
+
.upon_receiving("a get-expanded-links request")
|
72
|
+
.with(
|
73
|
+
method: :get,
|
74
|
+
path: "/v2/expanded-links/#{@content_id}",
|
75
|
+
)
|
76
|
+
.will_respond_with(
|
77
|
+
status: 404
|
78
|
+
)
|
79
|
+
|
80
|
+
response = @api_client.get_expanded_links(@content_id)
|
81
|
+
|
82
|
+
assert_nil response
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'gds_api/publishing_api_v2'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
describe GdsApi::PublishingApiV2 do
|
6
|
+
include PactTest
|
7
|
+
|
8
|
+
before do
|
9
|
+
@api_client = GdsApi::PublishingApiV2.new('http://localhost:3093')
|
10
|
+
@content_id = "bed722e6-db68-43e5-9079-063f623335a7"
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "#get_links" do
|
14
|
+
describe "when there's a links entry with links" do
|
15
|
+
before do
|
16
|
+
publishing_api
|
17
|
+
.given("organisation links exist for content_id #{@content_id}")
|
18
|
+
.upon_receiving("a get-links request")
|
19
|
+
.with(
|
20
|
+
method: :get,
|
21
|
+
path: "/v2/links/#{@content_id}",
|
22
|
+
)
|
23
|
+
.will_respond_with(
|
24
|
+
status: 200,
|
25
|
+
body: {
|
26
|
+
links: {
|
27
|
+
organisations: ["20583132-1619-4c68-af24-77583172c070"]
|
28
|
+
}
|
29
|
+
}
|
30
|
+
)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "responds with the links" do
|
34
|
+
response = @api_client.get_links(@content_id)
|
35
|
+
assert_equal 200, response.code
|
36
|
+
assert_equal ["20583132-1619-4c68-af24-77583172c070"], response.links.organisations
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "when there's an empty links entry" do
|
41
|
+
before do
|
42
|
+
publishing_api
|
43
|
+
.given("empty links exist for content_id #{@content_id}")
|
44
|
+
.upon_receiving("a get-links request")
|
45
|
+
.with(
|
46
|
+
method: :get,
|
47
|
+
path: "/v2/links/#{@content_id}",
|
48
|
+
)
|
49
|
+
.will_respond_with(
|
50
|
+
status: 200,
|
51
|
+
body: {
|
52
|
+
links: {
|
53
|
+
}
|
54
|
+
}
|
55
|
+
)
|
56
|
+
end
|
57
|
+
|
58
|
+
it "responds with the empty link set" do
|
59
|
+
response = @api_client.get_links(@content_id)
|
60
|
+
assert_equal 200, response.code
|
61
|
+
assert_equal OpenStruct.new({}), response.links
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "when there's no links entry" do
|
66
|
+
before do
|
67
|
+
publishing_api
|
68
|
+
.given("no links exist for content_id #{@content_id}")
|
69
|
+
.upon_receiving("a get-links request")
|
70
|
+
.with(
|
71
|
+
method: :get,
|
72
|
+
path: "/v2/links/#{@content_id}",
|
73
|
+
)
|
74
|
+
.will_respond_with(
|
75
|
+
status: 404
|
76
|
+
)
|
77
|
+
end
|
78
|
+
|
79
|
+
it "responds with 404" do
|
80
|
+
response = @api_client.get_links(@content_id)
|
81
|
+
assert_nil response
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -733,79 +733,6 @@ describe GdsApi::PublishingApiV2 do
|
|
733
733
|
end
|
734
734
|
end
|
735
735
|
|
736
|
-
describe "#get_links" do
|
737
|
-
describe "when there's a links entry with links" do
|
738
|
-
before do
|
739
|
-
publishing_api
|
740
|
-
.given("organisation links exist for content_id #{@content_id}")
|
741
|
-
.upon_receiving("a get-links request")
|
742
|
-
.with(
|
743
|
-
method: :get,
|
744
|
-
path: "/v2/links/#{@content_id}",
|
745
|
-
)
|
746
|
-
.will_respond_with(
|
747
|
-
status: 200,
|
748
|
-
body: {
|
749
|
-
links: {
|
750
|
-
organisations: ["20583132-1619-4c68-af24-77583172c070"]
|
751
|
-
}
|
752
|
-
}
|
753
|
-
)
|
754
|
-
end
|
755
|
-
|
756
|
-
it "responds with the links" do
|
757
|
-
response = @api_client.get_links(@content_id)
|
758
|
-
assert_equal 200, response.code
|
759
|
-
assert_equal ["20583132-1619-4c68-af24-77583172c070"], response.links.organisations
|
760
|
-
end
|
761
|
-
end
|
762
|
-
|
763
|
-
describe "when there's an empty links entry" do
|
764
|
-
before do
|
765
|
-
publishing_api
|
766
|
-
.given("empty links exist for content_id #{@content_id}")
|
767
|
-
.upon_receiving("a get-links request")
|
768
|
-
.with(
|
769
|
-
method: :get,
|
770
|
-
path: "/v2/links/#{@content_id}",
|
771
|
-
)
|
772
|
-
.will_respond_with(
|
773
|
-
status: 200,
|
774
|
-
body: {
|
775
|
-
links: {
|
776
|
-
}
|
777
|
-
}
|
778
|
-
)
|
779
|
-
end
|
780
|
-
|
781
|
-
it "responds with the empty link set" do
|
782
|
-
response = @api_client.get_links(@content_id)
|
783
|
-
assert_equal 200, response.code
|
784
|
-
assert_equal OpenStruct.new({}), response.links
|
785
|
-
end
|
786
|
-
end
|
787
|
-
|
788
|
-
describe "when there's no links entry" do
|
789
|
-
before do
|
790
|
-
publishing_api
|
791
|
-
.given("no links exist for content_id #{@content_id}")
|
792
|
-
.upon_receiving("a get-links request")
|
793
|
-
.with(
|
794
|
-
method: :get,
|
795
|
-
path: "/v2/links/#{@content_id}",
|
796
|
-
)
|
797
|
-
.will_respond_with(
|
798
|
-
status: 404
|
799
|
-
)
|
800
|
-
end
|
801
|
-
|
802
|
-
it "responds with 404" do
|
803
|
-
response = @api_client.get_links(@content_id)
|
804
|
-
assert_nil response
|
805
|
-
end
|
806
|
-
end
|
807
|
-
end
|
808
|
-
|
809
736
|
describe "#patch_links" do
|
810
737
|
describe "when setting links of the same type" do
|
811
738
|
before do
|
@@ -26,4 +26,29 @@ describe GdsApi::TestHelpers::PublishingApiV2 do
|
|
26
26
|
assert_equal([{ "content_id" => "2878337b-bed9-4e7f-85b6-10ed2cbcd504" }], response)
|
27
27
|
end
|
28
28
|
end
|
29
|
+
|
30
|
+
describe "#publishing_api_has_expanded_links" do
|
31
|
+
it "stubs the call to get expanded links" do
|
32
|
+
payload = {
|
33
|
+
content_id: "2e20294a-d694-4083-985e-d8bedefc2354",
|
34
|
+
organisations: [
|
35
|
+
{
|
36
|
+
content_id: ["a8a09822-1729-48a7-8a68-d08300de9d1e"]
|
37
|
+
}
|
38
|
+
]
|
39
|
+
}
|
40
|
+
|
41
|
+
publishing_api_has_expanded_links(payload)
|
42
|
+
response = publishing_api.get_expanded_links("2e20294a-d694-4083-985e-d8bedefc2354")
|
43
|
+
|
44
|
+
assert_equal({
|
45
|
+
"content_id" => "2e20294a-d694-4083-985e-d8bedefc2354",
|
46
|
+
"organisations" => [
|
47
|
+
{
|
48
|
+
"content_id" => ["a8a09822-1729-48a7-8a68-d08300de9d1e"]
|
49
|
+
}
|
50
|
+
]
|
51
|
+
}, response.to_h)
|
52
|
+
end
|
53
|
+
end
|
29
54
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gds-api-adapters
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 30.
|
4
|
+
version: 30.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Stewart
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-05-
|
11
|
+
date: 2016-05-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: plek
|
@@ -429,6 +429,8 @@ files:
|
|
429
429
|
- test/publisher_api_test.rb
|
430
430
|
- test/publishing_api/special_route_publisher_test.rb
|
431
431
|
- test/publishing_api_test.rb
|
432
|
+
- test/publishing_api_v2/get_expanded_links_test.rb
|
433
|
+
- test/publishing_api_v2/get_links_test.rb
|
432
434
|
- test/publishing_api_v2/lookup_test.rb
|
433
435
|
- test/publishing_api_v2_test.rb
|
434
436
|
- test/response_test.rb
|
@@ -473,6 +475,8 @@ test_files:
|
|
473
475
|
- test/mapit_test.rb
|
474
476
|
- test/publishing_api_test.rb
|
475
477
|
- test/publishing_api_v2/lookup_test.rb
|
478
|
+
- test/publishing_api_v2/get_links_test.rb
|
479
|
+
- test/publishing_api_v2/get_expanded_links_test.rb
|
476
480
|
- test/whitehall_admin_api_test.rb
|
477
481
|
- test/pp_data_in_test.rb
|
478
482
|
- test/publishing_api/special_route_publisher_test.rb
|