Class: GdsApi::AssetManager
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#asset(id) ⇒ GdsApi::Response?
Fetches an asset’s metadata given the id.
-
#create_asset(asset) ⇒ GdsApi::Response
Creates an asset given a hash with one
file
attribute. -
#create_whitehall_asset(asset) ⇒ GdsApi::Response
Creates a Whitehall asset given a hash with
file
&legacy_url_path
(required) andlegacy_etag
&legacy_last_modified
(optional) attributes. -
#delete_asset(id) ⇒ GdsApi::Response
Deletes an asset given an id.
-
#media(id, filename) ⇒ GdsApi::Response
Fetches an asset given the id and filename.
-
#restore_asset(id) ⇒ GdsApi::Response
Restores an asset given an id.
-
#update_asset(id, asset) ⇒ GdsApi::Response
Updates an asset given a hash with one
file
attribute. -
#whitehall_asset(legacy_url_path) ⇒ GdsApi::Response
Fetches a Whitehall asset’s metadata given the legacy URL path.
-
#whitehall_media(legacy_url_path) ⇒ GdsApi::Response
Fetches a Whitehall asset given the legacy URL path.
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
#asset(id) ⇒ GdsApi::Response?
Fetches an asset’s metadata given the id
181 182 183 |
# File 'lib/gds_api/asset_manager.rb', line 181 def asset(id) get_json("#{base_url}/assets/#{id}") end |
#create_asset(asset) ⇒ GdsApi::Response
Creates an asset given a hash with one file
attribute
Makes a POST
request to the asset manager api to create an asset.
The asset must be provided as a Hash
with a file
attribute that behaves like a File
object. The content-type
that the asset manager will subsequently serve will be based on the file’s extension (derived from #path
). If you supply a content-type
via, for example ActionDispatch::Http::UploadedFile
or another multipart wrapper, it will be ignored. To provide a content-type
directly you must be specify it as a content_type
attribute of the hash.
47 48 49 |
# File 'lib/gds_api/asset_manager.rb', line 47 def create_asset(asset) post_multipart("#{base_url}/assets", asset: asset) end |
#create_whitehall_asset(asset) ⇒ GdsApi::Response
Creates a Whitehall asset given a hash with file
& legacy_url_path
(required) and legacy_etag
& legacy_last_modified
(optional) attributes
Makes a POST
request to the asset manager api to create a Whitehall asset.
The asset must be provided as a Hash
with a file
attribute that behaves like a File
object and a legacy_url_path
attribute. The content-type
that the asset manager will subsequently serve will be based only on the file’s extension (derived from #path
). If you supply a content-type
via, for example ActionDispatch::Http::UploadedFile
or another multipart wrapper, it will be ignored.
The legacy_url_path
attribute is used to specify the public URL path at which the asset should be served by the Asset Manager. This differs from ‘#create_asset` where Asset Manager itself determines the public URL path to be used and returns that to the publishing app in the response. This endpoint is intended to be an interim measure which will help us migrate assets from Whitehall into Asset Manager without needing to change the URLs. The end goal is for Asset Manager to determine the public URL path for all assets including Whitehall assets. At that point this endpoint will become redundant and should be removed.
There may be restrictions on the format of the ‘legacy_url_path`. If the supplied path is not valid, a `GdsApi::HTTPUnprocessableEntity` exception will be raised.
The optional legacy_etag
& legacy_last_modified
attributes allow the client to specify the values that should be used in the ‘ETag` & `Last-Modified` response headers when the asset is requested via its public URL. They are only intended to be used for migrating existing Whitehall assets to Asset Manager so that we can avoid wholesale cache invalidation. New Whitehall assets should not specify values for these attributes; Asset Manager will generate suitable values.
Note: this endpoint should only be used by the Whitehall Admin app and not by any other publishing apps.
127 128 129 |
# File 'lib/gds_api/asset_manager.rb', line 127 def create_whitehall_asset(asset) post_multipart("#{base_url}/whitehall_assets", asset: asset) end |
#delete_asset(id) ⇒ GdsApi::Response
Deletes an asset given an id
Makes a DELETE
request to the asset manager api to delete an asset.
204 205 206 |
# File 'lib/gds_api/asset_manager.rb', line 204 def delete_asset(id) delete_json("#{base_url}/assets/#{id}") end |
#media(id, filename) ⇒ GdsApi::Response
Fetches an asset given the id and filename
250 251 252 |
# File 'lib/gds_api/asset_manager.rb', line 250 def media(id, filename) get_raw("#{base_url}/media/#{id}/#{filename}") end |
#restore_asset(id) ⇒ GdsApi::Response
Restores an asset given an id
Makes a POST
request to the asset manager api to restore an asset.
227 228 229 |
# File 'lib/gds_api/asset_manager.rb', line 227 def restore_asset(id) post_json("#{base_url}/assets/#{id}/restore") end |
#update_asset(id, asset) ⇒ GdsApi::Response
Updates an asset given a hash with one file
attribute
Makes a PUT
request to the asset manager api to update an asset.
The asset must be provided as a Hash
with a file
attribute that behaves like a File
object. The content-type
of the file will be based on the files extension unless you specify a content_type
attribute of the hash to set it.
170 171 172 |
# File 'lib/gds_api/asset_manager.rb', line 170 def update_asset(id, asset) put_multipart("#{base_url}/assets/#{id}", asset: asset) end |
#whitehall_asset(legacy_url_path) ⇒ GdsApi::Response
Fetches a Whitehall asset’s metadata given the legacy URL path
139 140 141 |
# File 'lib/gds_api/asset_manager.rb', line 139 def whitehall_asset(legacy_url_path) get_json("#{base_url}/whitehall_assets/#{uri_encode(legacy_url_path)}") end |
#whitehall_media(legacy_url_path) ⇒ GdsApi::Response
Fetches a Whitehall asset given the legacy URL path
238 239 240 |
# File 'lib/gds_api/asset_manager.rb', line 238 def whitehall_media(legacy_url_path) get_raw("#{base_url}/#{uri_encode(legacy_url_path)}") end |