gds-api-adapters 99.1.0 → 99.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.
- checksums.yaml +4 -4
- data/lib/gds_api/base.rb +6 -0
- data/lib/gds_api/content_store.rb +0 -6
- data/lib/gds_api/publishing_api.rb +22 -1
- data/lib/gds_api/test_helpers/publishing_api.rb +29 -0
- data/lib/gds_api/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 151ca2f0d20627efd16cc8a75b6fda8794c5eb3156fc4cbd663f337681b43663
|
4
|
+
data.tar.gz: 71e676f9970e9372f8497bdd5173b3e374455b76b4d24518d07e51fe811c7d55
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 75372afcd8ab785b65e224f1125573a8643a47b57233dc5ca369d3f62bbce12c8967260879a0adb1d2f782647f407393efaffc1060ad47184a72e8b504097385
|
7
|
+
data.tar.gz: 04f9ab32db73b2e54f25588a3262572702d4ddaadc761c7e6d28fc2be3e30e5f58531002bfa5b0fa3e5957876ce97ef6c8654b98eb5d6a39f20dbeec68a0c2be
|
data/lib/gds_api/base.rb
CHANGED
@@ -8,6 +8,12 @@ class GdsApi::Base
|
|
8
8
|
class InvalidAPIURL < StandardError
|
9
9
|
end
|
10
10
|
|
11
|
+
class ItemNotFound < GdsApi::HTTPNotFound
|
12
|
+
def self.build_from(http_error)
|
13
|
+
new(http_error.code, http_error.message, http_error.error_details)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
11
17
|
extend Forwardable
|
12
18
|
|
13
19
|
def client
|
@@ -4,12 +4,6 @@ require_relative "base"
|
|
4
4
|
require_relative "exceptions"
|
5
5
|
|
6
6
|
class GdsApi::ContentStore < GdsApi::Base
|
7
|
-
class ItemNotFound < GdsApi::HTTPNotFound
|
8
|
-
def self.build_from(http_error)
|
9
|
-
new(http_error.code, http_error.message, http_error.error_details)
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
7
|
def content_item(base_path)
|
14
8
|
get_json(content_item_url(base_path))
|
15
9
|
rescue GdsApi::HTTPNotFound => e
|
@@ -612,7 +612,19 @@ class GdsApi::PublishingApi < GdsApi::Base
|
|
612
612
|
# @return [GdsApi::Response] A response with the result of the GraphQL query formatted like a Content Store content item.
|
613
613
|
def graphql_content_item(query)
|
614
614
|
create_response = proc do |r|
|
615
|
-
|
615
|
+
parsed_body = JSON.parse(r.body)
|
616
|
+
|
617
|
+
updated_body = if parsed_body["errors"] && (unpublished_error = parsed_body["errors"].find { |error| error["message"] == "Edition has been unpublished" })
|
618
|
+
if unpublished_error.dig("extensions", "schema_name") == "gone" &&
|
619
|
+
(unpublished_error.dig("extensions", "details").nil? || unpublished_error.dig("extensions", "details").values.compact.reject(&:empty?).empty?)
|
620
|
+
raise GdsApi::HTTPGone.new(410, nil, unpublished_error["extensions"])
|
621
|
+
end
|
622
|
+
|
623
|
+
unpublished_error["extensions"]
|
624
|
+
else
|
625
|
+
parsed_body.dig("data", "edition")
|
626
|
+
end
|
627
|
+
|
616
628
|
updated_response = RestClient::Response.create(
|
617
629
|
updated_body.to_json,
|
618
630
|
r.net_http_res,
|
@@ -624,6 +636,15 @@ class GdsApi::PublishingApi < GdsApi::Base
|
|
624
636
|
post_json("#{endpoint}/graphql", query:, &create_response)
|
625
637
|
end
|
626
638
|
|
639
|
+
# Get the live content item using GraphQL
|
640
|
+
#
|
641
|
+
# @return [GdsApi::Response] A response with the result of the GraphQL query formatted like a Content Store content item.
|
642
|
+
def graphql_live_content_item(base_path)
|
643
|
+
get_json("#{endpoint}/graphql/content#{base_path}")
|
644
|
+
rescue GdsApi::HTTPNotFound => e
|
645
|
+
raise ItemNotFound.build_from(e)
|
646
|
+
end
|
647
|
+
|
627
648
|
private
|
628
649
|
|
629
650
|
def content_url(content_id, params = {})
|
@@ -214,6 +214,31 @@ module GdsApi
|
|
214
214
|
stub_request(:post, url).with(body: { query: }).to_return(response)
|
215
215
|
end
|
216
216
|
|
217
|
+
# Stub a GET /graphql/content/:base_path request
|
218
|
+
def stub_publishing_api_graphql_has_item(base_path, body = content_item_for_base_path(base_path), options = {})
|
219
|
+
max_age = options.fetch(:max_age, 900)
|
220
|
+
body = body.to_json unless body.is_a?(String)
|
221
|
+
|
222
|
+
stub_request(:get, "#{PUBLISHING_API_ENDPOINT}/graphql/content#{base_path}").to_return(
|
223
|
+
status: 200,
|
224
|
+
body:,
|
225
|
+
headers: {
|
226
|
+
cache_control: "public, max-age=#{max_age}",
|
227
|
+
date: Time.now.httpdate,
|
228
|
+
},
|
229
|
+
)
|
230
|
+
end
|
231
|
+
|
232
|
+
# Stub a GET /graphql/content/:base_path request returns 404 not found
|
233
|
+
def stub_publishing_api_graphql_does_not_have_item(base_path)
|
234
|
+
stub_request(:get, "#{PUBLISHING_API_ENDPOINT}/graphql/content#{base_path}").to_return(status: 404, headers: {})
|
235
|
+
end
|
236
|
+
|
237
|
+
# Stub a GET /graphql/content/:base_path request returns 410 gone
|
238
|
+
def stub_publishing_api_graphql_has_gone_item(base_path)
|
239
|
+
stub_request(:get, "#{PUBLISHING_API_ENDPOINT}/graphql/content#{base_path}").to_return(status: 410, headers: {})
|
240
|
+
end
|
241
|
+
|
217
242
|
# Assert that a draft was saved and published, and links were updated.
|
218
243
|
# - PUT /v2/content/:content_id
|
219
244
|
# - POST /v2/content/:content_id/publish
|
@@ -1048,6 +1073,10 @@ module GdsApi
|
|
1048
1073
|
def content_item_for_publishing_api(base_path, publishing_app = "publisher")
|
1049
1074
|
content_item_for_base_path(base_path).merge("publishing_app" => publishing_app)
|
1050
1075
|
end
|
1076
|
+
|
1077
|
+
def content_item_for_base_path(base_path)
|
1078
|
+
super.merge("base_path" => base_path)
|
1079
|
+
end
|
1051
1080
|
end
|
1052
1081
|
end
|
1053
1082
|
end
|
data/lib/gds_api/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gds-api-adapters
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 99.
|
4
|
+
version: 99.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GOV.UK Dev
|
@@ -267,14 +267,14 @@ dependencies:
|
|
267
267
|
requirements:
|
268
268
|
- - '='
|
269
269
|
- !ruby/object:Gem::Version
|
270
|
-
version: 5.1.
|
270
|
+
version: 5.1.18
|
271
271
|
type: :development
|
272
272
|
prerelease: false
|
273
273
|
version_requirements: !ruby/object:Gem::Requirement
|
274
274
|
requirements:
|
275
275
|
- - '='
|
276
276
|
- !ruby/object:Gem::Version
|
277
|
-
version: 5.1.
|
277
|
+
version: 5.1.18
|
278
278
|
- !ruby/object:Gem::Dependency
|
279
279
|
name: simplecov
|
280
280
|
requirement: !ruby/object:Gem::Requirement
|
@@ -399,7 +399,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
399
399
|
- !ruby/object:Gem::Version
|
400
400
|
version: '0'
|
401
401
|
requirements: []
|
402
|
-
rubygems_version: 3.
|
402
|
+
rubygems_version: 3.7.1
|
403
403
|
specification_version: 4
|
404
404
|
summary: Adapters to work with GDS APIs
|
405
405
|
test_files: []
|