Class: PublishingPlatformApi::PublishingApi
- Defined in:
- lib/publishing_platform_api/publishing_api.rb,
lib/publishing_platform_api/publishing_api/special_route_publisher.rb
Overview
Adapter for the Publishing API.
Defined Under Namespace
Classes: NoLiveVersion, SpecialRoutePublisher
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#discard_draft(content_id, options = {}) ⇒ Object
Discard a draft.
-
#get_content(content_id, params = {}) ⇒ PublishingPlatformApi::Response
Return a content item.
-
#get_content_items(params) ⇒ Object
Get a list of content items from the Publishing API.
-
#get_expanded_links(content_id, with_drafts: true, generate: false) ⇒ Object
Get expanded links.
-
#get_linkables(document_type: nil) ⇒ Object
FIXME: Add documentation.
-
#get_links(content_id) ⇒ PublishingPlatformApi::Response
Get the link set for the given content_id.
-
#lookup_content_id(base_path:, exclude_document_types: nil, exclude_unpublishing_types: nil, with_drafts: false) ⇒ UUID
Find the content_id for a base_path.
-
#lookup_content_ids(base_paths:, exclude_document_types: nil, exclude_unpublishing_types: nil, with_drafts: false) ⇒ Hash
Find the content_ids for a list of base_paths.
-
#patch_links(content_id, params) ⇒ Object
Patch the links of a content item.
-
#publish(content_id, options = {}) ⇒ Object
Publish a content item.
-
#put_content(content_id, payload) ⇒ Object
Put a content item.
-
#put_path(base_path, payload) ⇒ Object
Reserves a path for a publishing application.
-
#republish(content_id, options = {}) ⇒ Object
Republish a content item.
-
#unpublish(content_id, type:, explanation: nil, alternative_path: nil, discard_drafts: false, allow_draft: false, previous_version: nil, unpublished_at: nil, redirects: nil) ⇒ Object
Unpublish a content item.
- #unreserve_path(base_path, publishing_app) ⇒ Object
Methods inherited from Base
#client, #create_client, #get_list, #initialize, #url_for_slug
Constructor Details
This class inherits a constructor from PublishingPlatformApi::Base
Instance Method Details
#discard_draft(content_id, options = {}) ⇒ Object
Discard a draft
Deletes the draft content item.
143 144 145 146 147 148 149 |
# File 'lib/publishing_platform_api/publishing_api.rb', line 143 def discard_draft(content_id, = {}) optional_keys = %i[previous_version] params = merge_optional_keys({}, , optional_keys) post_json(discard_url(content_id), params) end |
#get_content(content_id, params = {}) ⇒ PublishingPlatformApi::Response
Return a content item
Raises exception if the item doesn’t exist.
28 29 30 |
# File 'lib/publishing_platform_api/publishing_api.rb', line 28 def get_content(content_id, params = {}) get_json(content_url(content_id, params)) end |
#get_content_items(params) ⇒ Object
Get a list of content items from the Publishing API.
The only required key in the params hash is ‘document_type`. These will be used to filter down the content items being returned by the API. Other allowed options can be seen from the link below.
251 252 253 254 |
# File 'lib/publishing_platform_api/publishing_api.rb', line 251 def get_content_items(params) query = query_string(params) get_json("#{endpoint}/content#{query}") end |
#get_expanded_links(content_id, with_drafts: true, generate: false) ⇒ Object
Get expanded links
Return the expanded links of the item.
197 198 199 200 201 202 203 204 |
# File 'lib/publishing_platform_api/publishing_api.rb', line 197 def (content_id, with_drafts: true, generate: false) params = {} params[:with_drafts] = "false" unless with_drafts params[:generate] = "true" if generate query = query_string(params) validate_content_id(content_id) get_json("#{endpoint}/expanded-links/#{content_id}#{query}") end |
#get_linkables(document_type: nil) ⇒ Object
FIXME: Add documentation
257 258 259 260 261 262 263 |
# File 'lib/publishing_platform_api/publishing_api.rb', line 257 def get_linkables(document_type: nil) if document_type.nil? raise ArgumentError, "Please provide a `document_type`" end get_json("#{endpoint}/linkables?document_type=#{document_type}") end |
#get_links(content_id) ⇒ PublishingPlatformApi::Response
Get the link set for the given content_id.
Given a Content ID, it fetchs the existing link set and their version.
170 171 172 |
# File 'lib/publishing_platform_api/publishing_api.rb', line 170 def get_links(content_id) get_json(links_url(content_id)) end |
#lookup_content_id(base_path:, exclude_document_types: nil, exclude_unpublishing_types: nil, with_drafts: false) ⇒ UUID
Find the content_id for a base_path.
Convenience method if you only need to look up one content_id for a base_path. For multiple base_paths, use #lookup_content_ids.
68 69 70 71 72 73 74 75 76 |
# File 'lib/publishing_platform_api/publishing_api.rb', line 68 def lookup_content_id(base_path:, exclude_document_types: nil, exclude_unpublishing_types: nil, with_drafts: false) lookups = lookup_content_ids( base_paths: [base_path], exclude_document_types:, exclude_unpublishing_types:, with_drafts:, ) lookups[base_path] end |
#lookup_content_ids(base_paths:, exclude_document_types: nil, exclude_unpublishing_types: nil, with_drafts: false) ⇒ Hash
Find the content_ids for a list of base_paths.
43 44 45 46 47 48 49 50 |
# File 'lib/publishing_platform_api/publishing_api.rb', line 43 def lookup_content_ids(base_paths:, exclude_document_types: nil, exclude_unpublishing_types: nil, with_drafts: false) = { base_paths: } [:exclude_document_types] = exclude_document_types if exclude_document_types [:exclude_unpublishing_types] = exclude_unpublishing_types if exclude_unpublishing_types [:with_drafts] = with_drafts if with_drafts response = post_json("#{endpoint}/lookup-by-base-path", ) response.to_hash end |
#patch_links(content_id, params) ⇒ Object
Patch the links of a content item
224 225 226 227 228 229 230 231 232 |
# File 'lib/publishing_platform_api/publishing_api.rb', line 224 def patch_links(content_id, params) payload = { links: params.fetch(:links), } payload = merge_optional_keys(payload, params, %i[previous_version bulk_publishing]) patch_json(links_url(content_id), payload) end |
#publish(content_id, options = {}) ⇒ Object
Publish a content item
The publishing-api will “publish” a draft item, so that it will be visible on the public site.
85 86 87 88 89 90 91 |
# File 'lib/publishing_platform_api/publishing_api.rb', line 85 def publish(content_id, = {}) optional_keys = %i[previous_version] params = merge_optional_keys({}, , optional_keys) post_json(publish_url(content_id), params) end |
#put_content(content_id, payload) ⇒ Object
Put a content item
14 15 16 |
# File 'lib/publishing_platform_api/publishing_api.rb', line 14 def put_content(content_id, payload) put_json(content_url(content_id), payload) end |
#put_path(base_path, payload) ⇒ Object
Reserves a path for a publishing application
Returns success or failure only.
271 272 273 274 |
# File 'lib/publishing_platform_api/publishing_api.rb', line 271 def put_path(base_path, payload) url = "#{endpoint}/paths#{base_path}" put_json(url, payload) end |
#republish(content_id, options = {}) ⇒ Object
Republish a content item
The publishing-api will “republish” a live edition. This can be used to remove an unpublishing or to re-send a published edition downstream
100 101 102 103 104 105 106 |
# File 'lib/publishing_platform_api/publishing_api.rb', line 100 def republish(content_id, = {}) optional_keys = %i[previous_version] params = merge_optional_keys({}, , optional_keys) post_json(republish_url(content_id), params) end |
#unpublish(content_id, type:, explanation: nil, alternative_path: nil, discard_drafts: false, allow_draft: false, previous_version: nil, unpublished_at: nil, redirects: nil) ⇒ Object
Unpublish a content item
The publishing API will “unpublish” a live item, to remove it from the public site, or update an existing unpublishing.
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/publishing_platform_api/publishing_api.rb', line 121 def unpublish(content_id, type:, explanation: nil, alternative_path: nil, discard_drafts: false, allow_draft: false, previous_version: nil, unpublished_at: nil, redirects: nil) params = { type:, } params[:explanation] = explanation if explanation params[:alternative_path] = alternative_path if alternative_path params[:previous_version] = previous_version if previous_version params[:discard_drafts] = discard_drafts if discard_drafts params[:allow_draft] = allow_draft if allow_draft params[:unpublished_at] = unpublished_at.utc.iso8601 if unpublished_at params[:redirects] = redirects if redirects post_json(unpublish_url(content_id), params) end |
#unreserve_path(base_path, publishing_app) ⇒ Object
276 277 278 279 |
# File 'lib/publishing_platform_api/publishing_api.rb', line 276 def unreserve_path(base_path, publishing_app) payload = { publishing_app: } delete_json(unreserve_url(base_path), payload) end |