gds-api-adapters 91.0.0 → 92.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 41e7999151bc881b78197b10d558183acae7e152fa24ab094fe6ffc7b1f3ba04
4
- data.tar.gz: b49490f10d7a25df53c0e9ad1794ae86f5539ec0da7439c8b2e9e0cdd49b3188
3
+ metadata.gz: fa430c81b388aeac9ba84ad16f9749119037eb12a189c80004c7c789f813f158
4
+ data.tar.gz: e01b6cd9c760f72f8c542206de12770e44b75bc18252480b10d84fb046d5ac0d
5
5
  SHA512:
6
- metadata.gz: b54654c80ed4e66aef36108340a56705d98be773f2c8f3f68c2de337fec44c9ac694c616664b3caf23a9969c92f89bffef7fd8f08ac98c32281abf4b4e25fa53
7
- data.tar.gz: 2204c601e2524af9c848fcd35faae39088c0a8f7716091b21ac59ffd7b5022455dbe39e32722204167449a583a203785b7d1046b5bfae91755057f237c4c7e1a
6
+ metadata.gz: 2cd5ab36cbac5f9b4854ce5658b6f41a8e43780d2b0a9e6ed08d59b2e1fccbf95950d259c7e344ea48b09986ff8a205cfea0caf19890ec780fcba50a25e2d472
7
+ data.tar.gz: 314e8b47ec5457681aa8e0048331340d24bef56c7c7221f6308015c75cf878579ac41615d80e855fc96350322d7b6fc03921455caffef887873ea3f11b42721b
@@ -48,98 +48,6 @@ class GdsApi::AssetManager < GdsApi::Base
48
48
  post_multipart("#{base_url}/assets", asset: asset)
49
49
  end
50
50
 
51
- # Creates a Whitehall asset given a hash with +file+ & +legacy_url_path+
52
- # (required) and +legacy_etag+ & +legacy_last_modified+ (optional) attributes
53
- #
54
- # Makes a +POST+ request to the asset manager api to create a Whitehall asset.
55
- #
56
- # The asset must be provided as a +Hash+ with a +file+ attribute that behaves
57
- # like a +File+ object and a +legacy_url_path+ attribute. The +content-type+
58
- # that the asset manager will subsequently serve will be based *only* on the
59
- # file's extension (derived from +#path+). If you supply a +content-type+ via,
60
- # for example +ActionDispatch::Http::UploadedFile+ or another multipart
61
- # wrapper, it will be ignored.
62
- #
63
- # The +legacy_url_path+ attribute is used to specify the public URL path at
64
- # which the asset should be served by the Asset Manager. This differs from
65
- # `#create_asset` where Asset Manager itself determines the public URL path to
66
- # be used and returns that to the publishing app in the response. This
67
- # endpoint is intended to be an interim measure which will help us migrate
68
- # assets from Whitehall into Asset Manager without needing to change the URLs.
69
- # The end goal is for Asset Manager to determine the public URL path for all
70
- # assets including Whitehall assets. At that point this endpoint will become
71
- # redundant and should be removed.
72
- #
73
- # There may be restrictions on the format of the `legacy_url_path`. If the
74
- # supplied path is not valid, a `GdsApi::HTTPUnprocessableEntity` exception
75
- # will be raised.
76
- #
77
- # The optional +legacy_etag+ & +legacy_last_modified+ attributes allow the
78
- # client to specify the values that should be used in the `ETag` &
79
- # `Last-Modified` response headers when the asset is requested via its public
80
- # URL. They are only intended to be used for migrating existing Whitehall
81
- # assets to Asset Manager so that we can avoid wholesale cache invalidation.
82
- # New Whitehall assets should not specify values for these attributes; Asset
83
- # Manager will generate suitable values.
84
- #
85
- # Note: this endpoint should only be used by the Whitehall Admin app and not
86
- # by any other publishing apps.
87
- #
88
- # @param asset [Hash] The attributes for the asset to send to the api. Must
89
- # contain +file+, which behaves like a +File+, and +legacy_url_path+, a
90
- # +String+. May contain +legacy_etag+, a +String+, and
91
- # +legacy_last_modified+, a +Time+ object. All other attributes will be
92
- # ignored.
93
- #
94
- # @return [GdsApi::Response] The wrapped http response from the api. Behaves
95
- # both as a +Hash+ and an +OpenStruct+, and responds to the following:
96
- # :id the URL of the asset
97
- # :name the filename of the asset that will be served
98
- # :content_type the content_type of the asset
99
- # :file_url the URL from which the asset will be served when it has
100
- # passed a virus scan
101
- # :state One of 'unscanned', 'clean', or 'infected'. Unless the state is
102
- # 'clean' the asset at the :file_url will redirect to a
103
- # placeholder
104
- #
105
- # @raise [HTTPErrorResponse] if the request returns an error
106
- #
107
- # @example Upload a file from disk
108
- # response = asset_manager.create_asset(
109
- # file: File.new('image.jpg', 'r'),
110
- # legacy_url_path: '/government/uploads/path/to/image.jpg'
111
- # )
112
- # response['id'] #=> "http://asset-manager.dev.gov.uk/assets/576bbc52759b74196b000012"
113
- # response['content_type'] #=> "image/jpeg"
114
- # @example Upload a file from a Rails param, (typically a multipart wrapper)
115
- # params[:file] #=> #<ActionDispatch::Http::UploadedFile:0x007fc60b43c5c8
116
- # # @content_type="application/foofle",
117
- # # @original_filename="cma_case_image.jpg",
118
- # # @tempfile="spec/support/images/cma_case_image.jpg">
119
- #
120
- # # Though we sent a file with a +content_type+ of 'application/foofle',
121
- # # this was ignored
122
- # response = asset_manager.create_asset(
123
- # file: params[:file]
124
- # legacy_url_path: '/government/uploads/path/to/cma_case_image.jpg'
125
- # )
126
- # response['content_type'] #=> "image/jpeg"
127
- def create_whitehall_asset(asset)
128
- post_multipart("#{base_url}/whitehall_assets", asset: asset)
129
- end
130
-
131
- # Fetches a Whitehall asset's metadata given the legacy URL path
132
- #
133
- # @param legacy_url_path [String] The Whitehall asset identifier.
134
- # @return [GdsApi::Response] A response object containing the parsed JSON
135
- # response. If the asset cannot be found, +GdsApi::HTTPNotFound+ will be
136
- # raised.
137
- #
138
- # @raise [HTTPErrorResponse] if the request returns an error
139
- def whitehall_asset(legacy_url_path)
140
- get_json("#{base_url}/whitehall_assets/#{uri_encode(legacy_url_path)}")
141
- end
142
-
143
51
  # Updates an asset given a hash with one +file+ attribute
144
52
  #
145
53
  # Makes a +PUT+ request to the asset manager api to update an asset.
@@ -239,6 +147,18 @@ class GdsApi::AssetManager < GdsApi::Base
239
147
  get_raw("#{base_url}/#{uri_encode(legacy_url_path)}")
240
148
  end
241
149
 
150
+ # Fetches an asset given the id and filename
151
+ #
152
+ # @param id [String] The asset identifier.
153
+ # @param filename [String] Filename of the asset.
154
+ # @return [GdsApi::Response] A response object containing the raw asset.
155
+ # If the asset cannot be found, +GdsApi::HTTPNotFound+ will be raised.
156
+ #
157
+ # @raise [HTTPErrorResponse] if the request returns an error
158
+ def media(id, filename)
159
+ get_raw("#{base_url}/media/#{id}/#{filename}")
160
+ end
161
+
242
162
  private
243
163
 
244
164
  def base_url
@@ -21,21 +21,19 @@ module GdsApi
21
21
  .to_return(body: body.to_json, status: 200)
22
22
  end
23
23
 
24
- def stub_asset_manager_has_an_asset(id, atts)
24
+ def stub_asset_manager_has_an_asset(id, atts, filename = "")
25
25
  response = atts.merge("_response_info" => { "status" => "ok" })
26
26
 
27
27
  stub_request(:get, "#{ASSET_MANAGER_ENDPOINT}/assets/#{id}")
28
28
  .to_return(body: response.to_json, status: 200)
29
- end
30
-
31
- def stub_asset_manager_has_a_whitehall_asset(legacy_url_path, atts)
32
- response = atts.merge("_response_info" => { "status" => "ok" })
33
29
 
34
- stub_request(:get, "#{ASSET_MANAGER_ENDPOINT}/whitehall_assets/#{legacy_url_path}")
35
- .to_return(body: response.to_json, status: 200)
30
+ stub_request(:get, "#{ASSET_MANAGER_ENDPOINT}/media/#{id}/#{filename}")
31
+ .to_return(body: "Some file content", status: 200)
32
+ end
36
33
 
34
+ def stub_asset_manager_has_a_whitehall_media_asset(legacy_url_path, content)
37
35
  stub_request(:get, "#{ASSET_MANAGER_ENDPOINT}/#{legacy_url_path}")
38
- .to_return(body: "Some file content", status: 200)
36
+ .to_return(body: content, status: 200)
39
37
  end
40
38
 
41
39
  def stub_asset_manager_does_not_have_an_asset(id)
@@ -47,15 +45,6 @@ module GdsApi
47
45
  .to_return(body: response.to_json, status: 404)
48
46
  end
49
47
 
50
- def stub_asset_manager_does_not_have_a_whitehall_asset(legacy_url_path)
51
- response = {
52
- "_response_info" => { "status" => "not found" },
53
- }
54
-
55
- stub_request(:get, "#{ASSET_MANAGER_ENDPOINT}/whitehall_assets/#{legacy_url_path}")
56
- .to_return(body: response.to_json, status: 404)
57
- end
58
-
59
48
  # This can take a string of an exact url or a hash of options
60
49
  #
61
50
  # with a string:
@@ -1,3 +1,3 @@
1
1
  module GdsApi
2
- VERSION = "91.0.0".freeze
2
+ VERSION = "92.0.0".freeze
3
3
  end
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: 91.0.0
4
+ version: 92.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GOV.UK Dev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-09-11 00:00:00.000000000 Z
11
+ date: 2023-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -417,7 +417,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
417
417
  - !ruby/object:Gem::Version
418
418
  version: '0'
419
419
  requirements: []
420
- rubygems_version: 3.4.19
420
+ rubygems_version: 3.4.22
421
421
  signing_key:
422
422
  specification_version: 4
423
423
  summary: Adapters to work with GDS APIs