publishing_platform_api_adapters 0.3.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3dc1965a7fe4e5b519636780d4a6cbd07b0475259d44b49f89128aa80ec3fd13
4
- data.tar.gz: ef68c7200b15791b97df9da45a7a7264d7b5071d112fda4370308b8ce35285f5
3
+ metadata.gz: dadc8a7f07684d3fad45a0efcfaa222a0763dbebd20fe3e0d5b7fc551196f65d
4
+ data.tar.gz: ecfbc92e940928e42f4d7e09b0a211fb2ebf5edf94dd6c86f5156c533d104a54
5
5
  SHA512:
6
- metadata.gz: 5b16bac63f4f8b91c3574789095996c39eeac770fe15e7cddc057466067d94e3bd5c07ee4b7116a63da6322a2ecb00f1149771bd6c62728deda7acbb7054566e
7
- data.tar.gz: 1f381f2e20bc0ca385d9f7fc291d8ed00924a124a35ebe272169149be4a41a95245dd4258cb501bc198637ed0c42caf841fa1535abfb671840a6cecfa50ff512
6
+ metadata.gz: 0ed8d5992d01a25a5313d0e5f7beeb21ff4b46541abca773617adc6398bd33b4847303cc89f086fed0b355b9c896c78f7098e650f77605903b09cbfa78a349f1
7
+ data.tar.gz: 907d770b9ed8568d12e861a04a6b184e20ec5eba029450d27ff40f6349ac0bb249bd465a85056853ae7a23ad44fffec144d31166514a9f26b74a18e79f4eb27a
@@ -0,0 +1,24 @@
1
+ require "publishing_platform_location"
2
+
3
+ require_relative "base"
4
+ require_relative "exceptions"
5
+
6
+ class PublishingPlatformApi::ContentStore < PublishingPlatformApi::Base
7
+ class ItemNotFound < PublishingPlatformApi::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
+ def content_item(base_path)
14
+ get_json(content_item_url(base_path))
15
+ rescue PublishingPlatformApi::HTTPNotFound => e
16
+ raise ItemNotFound.build_from(e)
17
+ end
18
+
19
+ private
20
+
21
+ def content_item_url(base_path)
22
+ "#{endpoint}/content#{base_path}"
23
+ end
24
+ end
@@ -102,6 +102,61 @@ class PublishingPlatformApi::PublishingApi < PublishingPlatformApi::Base
102
102
  post_json(discard_url(content_id), params)
103
103
  end
104
104
 
105
+ # Get the link set for the given content_id.
106
+ #
107
+ # Given a Content ID, it fetchs the existing link set and their version.
108
+ #
109
+ # @param content_id [String]
110
+ #
111
+ # @return [PublishingPlatformApi::Response] A response containing `links` and `version`.
112
+ #
113
+ # @example
114
+ #
115
+ # publishing_api.get_links("a-content-id")
116
+ # # => {
117
+ # "content_id" => "a-content-id",
118
+ # "links" => [
119
+ # "organisation" => "organisation-content-id",
120
+ # "document_collection" => "document-collection-content-id"
121
+ # ],
122
+ # "version" => 17
123
+ # }
124
+ def get_links(content_id)
125
+ get_json(links_url(content_id))
126
+ end
127
+
128
+ # Get expanded links
129
+ #
130
+ # Return the expanded links of the item.
131
+ #
132
+ # @param content_id [UUID]
133
+ # @param with_drafts [Bool] Whether links to draft-only editions are returned, defaulting to `true`.
134
+ # @param generate [Bool] Whether to require publishing-api to generate the expanded links, which may be slow. Defaults to `false`.
135
+ #
136
+ # @example
137
+ #
138
+ # publishing_api.get_expanded_links("8157589b-65e2-4df6-92ba-2c91d80006c0", with_drafts: false).to_h
139
+ #
140
+ # #=> {
141
+ # "generated" => "2017-08-01T10:42:49Z",
142
+ # "expanded_links" => {
143
+ # "organisations" => [
144
+ # {
145
+ # "content_id" => "21aa83a2-a47f-4189-a252-b02f8c322012",
146
+ # ... (and more attributes)
147
+ # }
148
+ # ]
149
+ # }
150
+ # }
151
+ def get_expanded_links(content_id, with_drafts: true, generate: false)
152
+ params = {}
153
+ params[:with_drafts] = "false" unless with_drafts
154
+ params[:generate] = "true" if generate
155
+ query = query_string(params)
156
+ validate_content_id(content_id)
157
+ get_json("#{endpoint}/expanded-links/#{content_id}#{query}")
158
+ end
159
+
105
160
  # Patch the links of a content item
106
161
  #
107
162
  # @param content_id [UUID]
@@ -152,6 +207,15 @@ class PublishingPlatformApi::PublishingApi < PublishingPlatformApi::Base
152
207
  get_json("#{endpoint}/content#{query}")
153
208
  end
154
209
 
210
+ # FIXME: Add documentation
211
+ def get_linkables(document_type: nil)
212
+ if document_type.nil?
213
+ raise ArgumentError, "Please provide a `document_type`"
214
+ end
215
+
216
+ get_json("#{endpoint}/linkables?document_type=#{document_type}")
217
+ end
218
+
155
219
  # Reserves a path for a publishing application
156
220
  #
157
221
  # Returns success or failure only.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PublishingPlatformApi
4
- VERSION = "0.3.0"
4
+ VERSION = "0.5.0"
5
5
  end
@@ -2,6 +2,7 @@ require "addressable"
2
2
  require "publishing_platform_location"
3
3
  require "time"
4
4
  require "publishing_platform_api/publishing_api"
5
+ require "publishing_platform_api/content_store"
5
6
 
6
7
  # @api documented
7
8
  module PublishingPlatformApi
@@ -17,4 +18,17 @@ module PublishingPlatformApi
17
18
  { bearer_token: ENV["PUBLISHING_API_BEARER_TOKEN"] }.merge(options),
18
19
  )
19
20
  end
21
+
22
+ # Creates a PublishingPlatformApi::ContentStore adapter
23
+ #
24
+ # This will set a bearer token if a CONTENT_STORE_BEARER_TOKEN environment
25
+ # variable is set
26
+ #
27
+ # @return [PublishingPlatformApi::ContentStore]
28
+ def self.content_store(options = {})
29
+ PublishingPlatformApi::ContentStore.new(
30
+ PublishingPlatformLocation.find("content-store"),
31
+ { bearer_token: ENV["CONTENT_STORE_BEARER_TOKEN"] }.merge(options),
32
+ )
33
+ end
20
34
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: publishing_platform_api_adapters
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Publishing Platform
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-07-18 00:00:00.000000000 Z
11
+ date: 2024-08-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -104,6 +104,7 @@ files:
104
104
  - Rakefile
105
105
  - lib/publishing_platform_api.rb
106
106
  - lib/publishing_platform_api/base.rb
107
+ - lib/publishing_platform_api/content_store.rb
107
108
  - lib/publishing_platform_api/exceptions.rb
108
109
  - lib/publishing_platform_api/json_client.rb
109
110
  - lib/publishing_platform_api/list_response.rb