Class: GdsApi::PublishingApiV2
- Defined in:
- lib/gds_api/publishing_api_v2.rb
Overview
Adapter for the Publishing API.
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 = {}) ⇒ GdsApi::Response
Return a content item.
- #get_content! ⇒ Object
-
#get_content_items(params) ⇒ Object
Get a list of content items from the Publishing API.
-
#get_expanded_links(content_id) ⇒ Object
Get expanded links.
-
#get_linkables(document_type: nil) ⇒ Object
FIXME: Add documentation.
-
#get_linked_items(content_id, params = {}) ⇒ Object
FIXME: Add documentation.
-
#get_links(content_id) ⇒ GdsApi::Response
Get the link set for the given content_id.
-
#import(content_id, locale, content_items) ⇒ Object
Import content into the publishing API.
-
#lookup_content_id(base_path:) ⇒ UUID
Find the content_id for a base_path.
-
#lookup_content_ids(base_paths:) ⇒ 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, update_type, options = {}) ⇒ Object
Publish a content item.
-
#put_content(content_id, payload) ⇒ Object
Put a content item.
-
#unpublish(content_id, type:, explanation: nil, alternative_path: nil, discard_drafts: false, allow_draft: false, previous_version: nil, locale: nil, unpublished_at: nil, redirects: nil) ⇒ Object
Unpublish a content item.
Methods inherited from Base
#client, #create_client, #get_list, #initialize, #url_for_slug
Constructor Details
This class inherits a constructor from GdsApi::Base
Instance Method Details
#discard_draft(content_id, options = {}) ⇒ Object
Discard a draft
Deletes the draft content item.
161 162 163 164 165 166 167 168 169 170 |
# File 'lib/gds_api/publishing_api_v2.rb', line 161 def discard_draft(content_id, = {}) optional_keys = [ :locale, :previous_version, ] params = merge_optional_keys({}, , optional_keys) post_json(discard_url(content_id), params) end |
#get_content(content_id, params = {}) ⇒ GdsApi::Response
Return a content item
Raises exception if the item doesn’t exist.
32 33 34 |
# File 'lib/gds_api/publishing_api_v2.rb', line 32 def get_content(content_id, params = {}) get_json(content_url(content_id, params)) end |
#get_content! ⇒ Object
37 38 39 |
# File 'lib/gds_api/publishing_api_v2.rb', line 37 def get_content!(*) raise "`PublishingApiV2#delete_content!` is deprecated. Use `PublishingApiV2#delete_content`" 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.
277 278 279 280 |
# File 'lib/gds_api/publishing_api_v2.rb', line 277 def get_content_items(params) query = query_string(params) get_json("#{endpoint}/v2/content#{query}") end |
#get_expanded_links(content_id) ⇒ Object
Get expanded links
Return the expanded links of the item.
221 222 223 224 225 |
# File 'lib/gds_api/publishing_api_v2.rb', line 221 def (content_id) validate_content_id(content_id) url = "#{endpoint}/v2/expanded-links/#{content_id}" get_json(url) end |
#get_linkables(document_type: nil) ⇒ Object
FIXME: Add documentation
285 286 287 288 289 290 291 |
# File 'lib/gds_api/publishing_api_v2.rb', line 285 def get_linkables(document_type: nil) if document_type.nil? raise ArgumentError.new("Please provide a `document_type`") end get_json("#{endpoint}/v2/linkables?document_type=#{document_type}") end |
#get_linked_items(content_id, params = {}) ⇒ Object
FIXME: Add documentation
296 297 298 299 300 |
# File 'lib/gds_api/publishing_api_v2.rb', line 296 def get_linked_items(content_id, params = {}) query = query_string(params) validate_content_id(content_id) get_json("#{endpoint}/v2/linked/#{content_id}#{query}") end |
#get_links(content_id) ⇒ GdsApi::Response
Get the link set for the given content_id.
Given a Content ID, it fetchs the existing link set and their version.
193 194 195 |
# File 'lib/gds_api/publishing_api_v2.rb', line 193 def get_links(content_id) get_json(links_url(content_id)) end |
#import(content_id, locale, content_items) ⇒ Object
Import content into the publishing API
The publishing-api will delete any content which has the content id provided, and then import the data given.
111 112 113 114 115 116 117 |
# File 'lib/gds_api/publishing_api_v2.rb', line 111 def import(content_id, locale, content_items) params = { history: content_items, } post_json("#{endpoint}/v2/content/#{content_id}/import?locale=#{locale}", params) end |
#lookup_content_id(base_path:) ⇒ 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.
71 72 73 74 |
# File 'lib/gds_api/publishing_api_v2.rb', line 71 def lookup_content_id(base_path:) lookups = lookup_content_ids(base_paths: [base_path]) lookups[base_path] end |
#lookup_content_ids(base_paths:) ⇒ Hash
Find the content_ids for a list of base_paths.
51 52 53 54 |
# File 'lib/gds_api/publishing_api_v2.rb', line 51 def lookup_content_ids(base_paths:) response = post_json("#{endpoint}/lookup-by-base-path", base_paths: base_paths) response.to_hash end |
#patch_links(content_id, params) ⇒ Object
Patch the links of a content item
247 248 249 250 251 252 253 254 255 |
# File 'lib/gds_api/publishing_api_v2.rb', line 247 def patch_links(content_id, params) payload = { links: params.fetch(:links) } payload = merge_optional_keys(payload, params, [:previous_version, :bulk_publishing]) patch_json(links_url(content_id), payload) end |
#publish(content_id, update_type, options = {}) ⇒ Object
Publish a content item
The publishing-api will “publish” a draft item, so that it will be visible on the public site.
87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/gds_api/publishing_api_v2.rb', line 87 def publish(content_id, update_type, = {}) params = { update_type: update_type } optional_keys = [ :locale, :previous_version, ] params = merge_optional_keys(params, , optional_keys) post_json(publish_url(content_id), params) end |
#put_content(content_id, payload) ⇒ Object
Put a content item
16 17 18 |
# File 'lib/gds_api/publishing_api_v2.rb', line 16 def put_content(content_id, payload) put_json(content_url(content_id), payload) end |
#unpublish(content_id, type:, explanation: nil, alternative_path: nil, discard_drafts: false, allow_draft: false, previous_version: nil, locale: 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.
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/gds_api/publishing_api_v2.rb', line 135 def unpublish(content_id, type:, explanation: nil, alternative_path: nil, discard_drafts: false, allow_draft: false, previous_version: nil, locale: nil, unpublished_at: nil, redirects: nil) params = { type: 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[:locale] = locale if locale params[:unpublished_at] = unpublished_at.utc.iso8601 if unpublished_at params[:redirects] = redirects if redirects post_json(unpublish_url(content_id), params) end |