gds-api-adapters 100.0.0 → 101.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a97f28eec3d867d6b785d0f21be19bee59e5f554bdd8e8e8f560144c44adb3de
4
- data.tar.gz: 7159ed4dcbe4373a8ff071ccfce1c48a49b701925a06b0842a8f6333529e5b4f
3
+ metadata.gz: 960d745ee91c73b2d8a54b7bc73f8280b6961b83cefb6137703935c95b8df485
4
+ data.tar.gz: '091cd209020f815a8cbe3ae6b01bd4c70b17e524cee8b1da1f156f1facc8cc14'
5
5
  SHA512:
6
- metadata.gz: 25ce95b7d3dfc469b4bb27442648e4cd38287a0ab9e8e56b202f4ffb0b99e26236f6dcef3d908a462e4d0f9d4e8a3c338fa2d4e8efba3338ae250422bfca19e2
7
- data.tar.gz: 7c5cfb799ee20f8c632ebd508e31b28cd5a7c05233bcc661a7677b3c212741362c9607b0ae10b9f148fe16458276994d38afbfaa9c53e4f6e4e2b626e8784649
6
+ metadata.gz: c89a594778ea1704d8c0a41a348bc7fbd5e9bb7e3c79cfd74cbf3d6bc49a33414f81e2335463edf4c215f64392b2259ee165f3f9c216134f3084a517b35c7d91
7
+ data.tar.gz: d6e8d6d1f8eb154164bb76657caf359b4a674faa5490292dd5bba0543cb020f111ae9b1322e28c446eb9f9e76e8456b349709b9adce6da29599bad0845130b9e
@@ -8,8 +8,6 @@ require_relative "exceptions"
8
8
  # @see https://github.com/alphagov/publishing-api/blob/main/docs/model.md
9
9
  # @api documented
10
10
  class GdsApi::PublishingApi < GdsApi::Base
11
- class NoLiveVersion < GdsApi::BaseError; end
12
-
13
11
  # Put a content item
14
12
  #
15
13
  # @param content_id [UUID]
@@ -45,18 +43,10 @@ class GdsApi::PublishingApi < GdsApi::Base
45
43
  #
46
44
  # @return [GdsApi::Response] a content item
47
45
  #
48
- # @raise [NoLiveVersion] when the content item is not found
46
+ # @raise [HTTPNotFound] when the content item is not found
49
47
  # @see https://github.com/alphagov/publishing-api/blob/main/docs/api.md#get-v2contentcontent_id
50
48
  def get_live_content(content_id, locale = "en")
51
- content_item = get_content(content_id, locale:)
52
-
53
- live_states = %w[published unpublished]
54
- return content_item if live_states.include?(content_item.to_h["publication_state"])
55
-
56
- live_version_number = content_item["state_history"].find { |_, v| live_states.include?(v) }&.first
57
- raise NoLiveVersion, "No live version exists for content_id: #{content_id}" unless live_version_number
58
-
59
- get_content(content_id, locale:, version: live_version_number)
49
+ get_content(content_id, locale:, content_store: :live)
60
50
  end
61
51
 
62
52
  # Find the content_ids for a list of base_paths.
@@ -605,37 +595,6 @@ class GdsApi::PublishingApi < GdsApi::Base
605
595
  post_json("#{endpoint}/graphql", query:)
606
596
  end
607
597
 
608
- # Make a GraphQL query and return the response in the same format as a Content Store content item
609
- #
610
- # @param query [String]
611
- #
612
- # @return [GdsApi::Response] A response with the result of the GraphQL query formatted like a Content Store content item.
613
- def graphql_content_item(query)
614
- create_response = proc do |r|
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
-
628
- updated_response = RestClient::Response.create(
629
- updated_body.to_json,
630
- r.net_http_res,
631
- r.request,
632
- )
633
- GdsApi::Response.new(updated_response)
634
- end
635
-
636
- post_json("#{endpoint}/graphql", query:, &create_response)
637
- end
638
-
639
598
  # Get the live content item using GraphQL
640
599
  #
641
600
  # @return [GdsApi::Response] A response with the result of the GraphQL query formatted like a Content Store content item.
@@ -201,19 +201,6 @@ module GdsApi
201
201
  stub_request(:post, url).with(body: { query: }).to_return(response)
202
202
  end
203
203
 
204
- # Stub a POST /graphql content item request
205
- #
206
- # @param query [String]
207
- def stub_publishing_api_graphql_content_item(query, response_hash = {})
208
- url = "#{PUBLISHING_API_ENDPOINT}/graphql"
209
- response = {
210
- status: 200,
211
- body: response_hash.to_json,
212
- headers: { "Content-Type" => "application/json; charset=utf-8" },
213
- }
214
- stub_request(:post, url).with(body: { query: }).to_return(response)
215
- end
216
-
217
204
  # Stub a GET /graphql/content/:base_path request
218
205
  def stub_publishing_api_graphql_has_item(base_path, body = content_item_for_base_path(base_path), options = {})
219
206
  max_age = options.fetch(:max_age, 900)
@@ -1,3 +1,3 @@
1
1
  module GdsApi
2
- VERSION = "100.0.0".freeze
2
+ VERSION = "101.1.0".freeze
3
3
  end
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: 100.0.0
4
+ version: 101.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GOV.UK Dev
@@ -169,14 +169,14 @@ dependencies:
169
169
  requirements:
170
170
  - - "~>"
171
171
  - !ruby/object:Gem::Version
172
- version: '2.1'
172
+ version: '3.0'
173
173
  type: :development
174
174
  prerelease: false
175
175
  version_requirements: !ruby/object:Gem::Requirement
176
176
  requirements:
177
177
  - - "~>"
178
178
  - !ruby/object:Gem::Version
179
- version: '2.1'
179
+ version: '3.0'
180
180
  - !ruby/object:Gem::Dependency
181
181
  name: pact
182
182
  requirement: !ruby/object:Gem::Requirement
@@ -267,14 +267,14 @@ dependencies:
267
267
  requirements:
268
268
  - - '='
269
269
  - !ruby/object:Gem::Version
270
- version: 5.1.19
270
+ version: 5.1.20
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.19
277
+ version: 5.1.20
278
278
  - !ruby/object:Gem::Dependency
279
279
  name: simplecov
280
280
  requirement: !ruby/object:Gem::Requirement
@@ -398,7 +398,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
398
398
  - !ruby/object:Gem::Version
399
399
  version: '0'
400
400
  requirements: []
401
- rubygems_version: 3.7.1
401
+ rubygems_version: 4.0.2
402
402
  specification_version: 4
403
403
  summary: Adapters to work with GDS APIs
404
404
  test_files: []