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!(content_id, params = {}) ⇒ GdsApi::Response
Return a content item.
-
#get_content_items(params) ⇒ Object
FIXME: Add documentation.
-
#get_linkables(document_type: nil, format: nil) ⇒ Object
FIXME: Add documentation.
-
#get_linked_items(content_id, params = {}) ⇒ Object
FIXME: Add documentation.
-
#get_links(content_id) ⇒ Object
FIXME: Add documentation.
-
#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, payload) ⇒ 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.
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.
119 120 121 122 123 124 125 126 127 128 |
# File 'lib/gds_api/publishing_api_v2.rb', line 119 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
Returns nil if the content item doesn’t exist.
29 30 31 |
# File 'lib/gds_api/publishing_api_v2.rb', line 29 def get_content(content_id, params = {}) get_json(content_url(content_id, params)) end |
#get_content!(content_id, params = {}) ⇒ GdsApi::Response
Return a content item
Raises exception if the item doesn’t exist.
45 46 47 |
# File 'lib/gds_api/publishing_api_v2.rb', line 45 def get_content!(content_id, params = {}) get_json!(content_url(content_id, params)) end |
#get_content_items(params) ⇒ Object
FIXME: Add documentation
165 166 167 168 |
# File 'lib/gds_api/publishing_api_v2.rb', line 165 def get_content_items(params) query = query_string(params) get_json("#{endpoint}/v2/content#{query}") end |
#get_linkables(document_type: nil, format: nil) ⇒ Object
FIXME: Add documentation
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/gds_api/publishing_api_v2.rb', line 173 def get_linkables(document_type: nil, format: nil) if document_type.nil? if format.nil? raise ArgumentError.new("Please provide a `document_type`") else self.class.logger.warn( "Providing `format` to the `get_linkables` method is deprecated and will be removed in a " + "future release. Please use `document_type` instead." ) document_type = format end end get_json("#{endpoint}/v2/linkables?document_type=#{document_type}") end |
#get_linked_items(content_id, params = {}) ⇒ Object
FIXME: Add documentation
192 193 194 195 196 |
# File 'lib/gds_api/publishing_api_v2.rb', line 192 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) ⇒ Object
FIXME: Add documentation
133 134 135 |
# File 'lib/gds_api/publishing_api_v2.rb', line 133 def get_links(content_id) get_json(links_url(content_id)) 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.
79 80 81 82 |
# File 'lib/gds_api/publishing_api_v2.rb', line 79 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.
59 60 61 62 |
# File 'lib/gds_api/publishing_api_v2.rb', line 59 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, payload) ⇒ Object
Patch the links of a content item
152 153 154 155 156 157 158 159 160 |
# File 'lib/gds_api/publishing_api_v2.rb', line 152 def patch_links(content_id, payload) params = { links: payload.fetch(:links) } params = merge_optional_keys(params, payload, [:previous_version]) patch_json!(links_url(content_id), params) 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.
95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/gds_api/publishing_api_v2.rb', line 95 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
15 16 17 |
# File 'lib/gds_api/publishing_api_v2.rb', line 15 def put_content(content_id, payload) put_json!(content_url(content_id), payload) end |