gds-api-adapters 99.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 77b556dd9d3c693a4ec8e39553d52775880ac1012907ff339d8688b632d1a61f
4
- data.tar.gz: 56908ef8260c2201338640dd4f215c31a3d527f9e2e1aa4505b2f5e00ce23100
3
+ metadata.gz: 151ca2f0d20627efd16cc8a75b6fda8794c5eb3156fc4cbd663f337681b43663
4
+ data.tar.gz: 71e676f9970e9372f8497bdd5173b3e374455b76b4d24518d07e51fe811c7d55
5
5
  SHA512:
6
- metadata.gz: 0cc21fc6e390640d4cb9f302d1c5a8ba9d666770a2bfebf7ae48d20fdef7943dfa801da523d53d696acc15f08335b58f7665a51ca2de2a35f903307bd1fe3775
7
- data.tar.gz: 2cbf538c940fc4e7ae9bfbe5f7585f4d9e2e0d82788b40eb4747091ac2cc02c7e8a9ec29c27a15241a3a92fe1614d218fad27607b40a20eea1008a7e75ed5aca
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
@@ -636,6 +636,15 @@ class GdsApi::PublishingApi < GdsApi::Base
636
636
  post_json("#{endpoint}/graphql", query:, &create_response)
637
637
  end
638
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
+
639
648
  private
640
649
 
641
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
@@ -1,3 +1,3 @@
1
1
  module GdsApi
2
- VERSION = "99.2.0".freeze
2
+ VERSION = "99.3.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: 99.2.0
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.7
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.7
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.6.8
402
+ rubygems_version: 3.7.1
403
403
  specification_version: 4
404
404
  summary: Adapters to work with GDS APIs
405
405
  test_files: []