gds-api-adapters 49.1.0 → 49.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/gds_api/asset_manager.rb +70 -0
- data/lib/gds_api/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 004eb0ac42b4214aa361b0f6c67c305a2501f96d
|
4
|
+
data.tar.gz: 404379041f33115af011520407c01947a7142f8b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 38791a6ff09cb11db3237b038cd4a66ed682e8657fa6c9dcd99ab217a92dc817ce2e74c5c4e26904ec574aabfc6549295dea4f4ffde12e892d2eb2bcb3af1f4d
|
7
|
+
data.tar.gz: 696ec0fb37e345ef8f779c312a9610fb4c0c9bd4f1f15796b064949429b4847378f57ff6411215aaa24e228a0348669aaa7bbd3f616372d3f9cf819aaebf5424
|
@@ -47,6 +47,76 @@ class GdsApi::AssetManager < GdsApi::Base
|
|
47
47
|
post_multipart("#{base_url}/assets", asset: asset)
|
48
48
|
end
|
49
49
|
|
50
|
+
# Creates a Whitehall asset given a hash with +file+ & +legacy_url_path+
|
51
|
+
# attributes
|
52
|
+
#
|
53
|
+
# Makes a +POST+ request to the asset manager api to create a Whitehall asset.
|
54
|
+
#
|
55
|
+
# The asset must be provided as a +Hash+ with a +file+ attribute that behaves
|
56
|
+
# like a +File+ object and a +legacy_url_path+ attribute. The +content-type+
|
57
|
+
# that the asset manager will subsequently serve will be based *only* on the
|
58
|
+
# file's extension (derived from +#path+). If you supply a +content-type+ via,
|
59
|
+
# for example +ActionDispatch::Http::UploadedFile+ or another multipart
|
60
|
+
# wrapper, it will be ignored.
|
61
|
+
#
|
62
|
+
# The +legacy_url_path+ attribute is used to specify the public URL path at
|
63
|
+
# which the asset should be served by the Asset Manager. This differs from
|
64
|
+
# `#create_asset` where Asset Manager itself determines the public URL path to
|
65
|
+
# be used and returns that to the publishing app in the response. This
|
66
|
+
# endpoint is intended to be an interim measure which will help us migrate
|
67
|
+
# assets from Whitehall into Asset Manager without needing to change the URLs.
|
68
|
+
# The end goal is for Asset Manager to determine the public URL path for all
|
69
|
+
# assets including Whitehall assets. At that point this endpoint will become
|
70
|
+
# redundant and should be removed.
|
71
|
+
#
|
72
|
+
# There may be restrictions on the format of the `legacy_url_path`. If the
|
73
|
+
# supplied path is not valid, a `GdsApi::HTTPUnprocessableEntity` exception
|
74
|
+
# will be raised.
|
75
|
+
#
|
76
|
+
# Note: this endpoint should only be used by the Whitehall Admin app and not
|
77
|
+
# by any other publishing apps.
|
78
|
+
#
|
79
|
+
# @param asset [Hash] The attributes for the asset to send to the api. Must
|
80
|
+
# contain +file+, which behaves like a +File+, and +legacy_url_path+, a
|
81
|
+
# +String+. All other attributes will be ignored.
|
82
|
+
#
|
83
|
+
# @return [GdsApi::Response] The wrapped http response from the api. Behaves
|
84
|
+
# both as a +Hash+ and an +OpenStruct+, and responds to the following:
|
85
|
+
# :id the URL of the asset
|
86
|
+
# :name the filename of the asset that will be served
|
87
|
+
# :content_type the content_type of the asset
|
88
|
+
# :file_url the URL from which the asset will be served when it has
|
89
|
+
# passed a virus scan
|
90
|
+
# :state One of 'unscanned', 'clean', or 'infected'. Unless the state is
|
91
|
+
# 'clean' the asset at the :file_url will redirect to a
|
92
|
+
# placeholder
|
93
|
+
#
|
94
|
+
# @raise [HTTPErrorResponse] if the request returns an error
|
95
|
+
#
|
96
|
+
# @example Upload a file from disk
|
97
|
+
# response = asset_manager.create_asset(
|
98
|
+
# file: File.new('image.jpg', 'r'),
|
99
|
+
# legacy_url_path: '/government/uploads/path/to/image.jpg'
|
100
|
+
# )
|
101
|
+
# response['id'] #=> "http://asset-manager.dev.gov.uk/assets/576bbc52759b74196b000012"
|
102
|
+
# response['content_type'] #=> "image/jpeg"
|
103
|
+
# @example Upload a file from a Rails param, (typically a multipart wrapper)
|
104
|
+
# params[:file] #=> #<ActionDispatch::Http::UploadedFile:0x007fc60b43c5c8
|
105
|
+
# # @content_type="application/foofle",
|
106
|
+
# # @original_filename="cma_case_image.jpg",
|
107
|
+
# # @tempfile="spec/support/images/cma_case_image.jpg">
|
108
|
+
#
|
109
|
+
# # Though we sent a file with a +content_type+ of 'application/foofle',
|
110
|
+
# # this was ignored
|
111
|
+
# response = asset_manager.create_asset(
|
112
|
+
# file: params[:file]
|
113
|
+
# legacy_url_path: '/government/uploads/path/to/cma_case_image.jpg'
|
114
|
+
# )
|
115
|
+
# response['content_type'] #=> "image/jpeg"
|
116
|
+
def create_whitehall_asset(asset)
|
117
|
+
post_multipart("#{base_url}/whitehall_assets", asset: asset)
|
118
|
+
end
|
119
|
+
|
50
120
|
# Updates an asset given a hash with one +file+ attribute
|
51
121
|
#
|
52
122
|
# Makes a +PUT+ request to the asset manager api to update an asset.
|
data/lib/gds_api/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gds-api-adapters
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 49.
|
4
|
+
version: 49.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Stewart
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-09-
|
11
|
+
date: 2017-09-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: plek
|