publishing_platform_api_adapters 0.11.0 → 0.13.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: 54dea58b3d1bcd3fe96e91cb75249bb29a240ba5ab41bba121292b695b8d160b
4
- data.tar.gz: f345c52fbb488893dc130248ad994e80df33df0bd80d193cd757f05adaea9493
3
+ metadata.gz: c489cc0c17611c94c8d182dc12064cfeec8a77e6aef3d61e70c2e83ee06a9218
4
+ data.tar.gz: c08de2b92e99185097aa3eb834196aa5289b023dbe8b3170d58b848c50d46aa8
5
5
  SHA512:
6
- metadata.gz: b0e418637bbe6e824c3e31e4334d69862e37c1eaddfaa56fc6e1c9caa4c57d7cf0f464878fbce80901664b9d563300156e1a0e268be14ab75d650046d164a4aa
7
- data.tar.gz: 3133b2aa1676a494fe27c5593acdb1b0bc10d1b4933638cbbc4b14262cced73f4651149f1f7bd12151e8618ec7e2f7ffc856f953e663f82c5c64300f95d0f9ff
6
+ metadata.gz: afebcbc50bb0d165f63c13f1c01517f1065ea6db1c068ff2c3377d26ede37572276d78fc96a0015228ba4032dc81cebd8dd904e3d1adb816f0a097719e6b0b17
7
+ data.tar.gz: ae01a6fc51589ad66d1500f43f4ce3a84edaa8caa49f25a3bb3146c529535bfc4c7fe95fcf0717fcdfcf2c5c63bfc8ca965119498d3c5a262e2f4b588acf79b5
@@ -29,6 +29,52 @@ class PublishingPlatformApi::PublishingApi < PublishingPlatformApi::Base
29
29
  get_json(content_url(content_id, params))
30
30
  end
31
31
 
32
+ # Find the content_ids for a list of base_paths.
33
+ #
34
+ # @param base_paths [Array]
35
+ # @param exclude_document_types [Array] (optional)
36
+ # @param exclude_unpublishing_types [Array] (optional)
37
+ # @param with_drafts [Boolean] (optional)
38
+ # @return [Hash] a hash, keyed by `base_path` with `content_id` as value
39
+ # @example
40
+ #
41
+ # publishing_api.lookup_content_ids(base_paths: ['/foo', '/bar'])
42
+ # # => { "/foo" => "51ac4247-fd92-470a-a207-6b852a97f2db", "/bar" => "261bd281-f16c-48d5-82d2-9544019ad9ca" }
43
+ def lookup_content_ids(base_paths:, exclude_document_types: nil, exclude_unpublishing_types: nil, with_drafts: false)
44
+ options = { base_paths: }
45
+ options[:exclude_document_types] = exclude_document_types if exclude_document_types
46
+ options[:exclude_unpublishing_types] = exclude_unpublishing_types if exclude_unpublishing_types
47
+ options[:with_drafts] = with_drafts if with_drafts
48
+ response = post_json("#{endpoint}/lookup-by-base-path", options)
49
+ response.to_hash
50
+ end
51
+
52
+ # Find the content_id for a base_path.
53
+ #
54
+ # Convenience method if you only need to look up one content_id for a
55
+ # base_path. For multiple base_paths, use {PublishingPlatformApi::PublishingApi#lookup_content_ids}.
56
+ #
57
+ # @param base_path [String]
58
+ # @param exclude_document_types [Array] (optional)
59
+ # @param exclude_unpublishing_types [Array] (optional)
60
+ # @param with_drafts [Boolean] (optional)
61
+ #
62
+ # @return [UUID] the `content_id` for the `base_path`
63
+ #
64
+ # @example
65
+ #
66
+ # publishing_api.lookup_content_id(base_path: '/foo')
67
+ # # => "51ac4247-fd92-470a-a207-6b852a97f2db"
68
+ def lookup_content_id(base_path:, exclude_document_types: nil, exclude_unpublishing_types: nil, with_drafts: false)
69
+ lookups = lookup_content_ids(
70
+ base_paths: [base_path],
71
+ exclude_document_types:,
72
+ exclude_unpublishing_types:,
73
+ with_drafts:,
74
+ )
75
+ lookups[base_path]
76
+ end
77
+
32
78
  # Publish a content item
33
79
  #
34
80
  # The publishing-api will "publish" a draft item, so that it will be visible
@@ -0,0 +1,15 @@
1
+ require_relative "base"
2
+ require "rack/utils"
3
+
4
+ module PublishingPlatformApi
5
+ # @api documented
6
+ class Search < Base
7
+ # Perform a search.
8
+ #
9
+ # @param args [Hash] A valid search query. See search-api documentation for options.
10
+ def search(args, additional_headers = {})
11
+ request_url = "#{endpoint}/search.json?#{Rack::Utils.build_nested_query(args)}"
12
+ get_json(request_url, additional_headers)
13
+ end
14
+ end
15
+ end
@@ -538,6 +538,22 @@ module PublishingPlatformApi
538
538
  stub_request(:get, url).to_return(status: 404, body: resource_not_found(content_id, "link set").to_json, headers: {})
539
539
  end
540
540
 
541
+ # Stub calls to the lookups endpoint
542
+ #
543
+ # @param lookup_hash [Hash] Hash with base_path as key, content_id as value.
544
+ #
545
+ # @example
546
+ #
547
+ # stub_publishing_api_has_lookups({
548
+ # "/foo" => "51ac4247-fd92-470a-a207-6b852a97f2db",
549
+ # "/bar" => "261bd281-f16c-48d5-82d2-9544019ad9ca"
550
+ # })
551
+ #
552
+ def stub_publishing_api_has_lookups(lookup_hash)
553
+ url = "#{PUBLISHING_API_ENDPOINT}/lookup-by-base-path"
554
+ stub_request(:post, url).to_return(body: lookup_hash.to_json)
555
+ end
556
+
541
557
  def stub_publishing_api_unreserve_path(base_path, publishing_app = /.*/)
542
558
  stub_publishing_api_unreserve_path_with_code(base_path, publishing_app, 200)
543
559
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PublishingPlatformApi
4
- VERSION = "0.11.0"
4
+ VERSION = "0.13.0"
5
5
  end
@@ -6,6 +6,7 @@ require "publishing_platform_api/content_store"
6
6
  require "publishing_platform_api/publishing_api"
7
7
  require "publishing_platform_api/organisations"
8
8
  require "publishing_platform_api/router"
9
+ require "publishing_platform_api/search"
9
10
 
10
11
  # @api documented
11
12
  module PublishingPlatformApi
@@ -72,4 +73,14 @@ module PublishingPlatformApi
72
73
  { bearer_token: ENV["ROUTER_API_BEARER_TOKEN"] }.merge(options),
73
74
  )
74
75
  end
76
+
77
+ # Creates a PublishingPlatformApi::Search adapter to access via a search.* hostname
78
+ #
79
+ # @return [PublishingPlatformApi::Search]
80
+ def self.search(options = {})
81
+ PublishingPlatformApi::Search.new(
82
+ PublishingPlatformLocation.find("search-api"),
83
+ options,
84
+ )
85
+ end
75
86
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: publishing_platform_api_adapters
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Publishing Platform
@@ -199,6 +199,7 @@ files:
199
199
  - lib/publishing_platform_api/railtie.rb
200
200
  - lib/publishing_platform_api/response.rb
201
201
  - lib/publishing_platform_api/router.rb
202
+ - lib/publishing_platform_api/search.rb
202
203
  - lib/publishing_platform_api/test_helpers/asset_manager.rb
203
204
  - lib/publishing_platform_api/test_helpers/common_responses.rb
204
205
  - lib/publishing_platform_api/test_helpers/content_item_helpers.rb
@@ -225,7 +226,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
225
226
  - !ruby/object:Gem::Version
226
227
  version: '0'
227
228
  requirements: []
228
- rubygems_version: 4.0.2
229
+ rubygems_version: 4.0.6
229
230
  specification_version: 4
230
231
  summary: Adapters to work with Publishing Platform APIs
231
232
  test_files: []