gds-api-adapters 91.1.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: b228bbfeb3c6670abced9b88f27ff26a2ac8f202c65b4815e7e7bf095bb2f357
4
- data.tar.gz: dc1d051288ca8e31105dbb25c19f1c822c438b7b15c10a789f4f663fc8d39fa8
3
+ metadata.gz: fa430c81b388aeac9ba84ad16f9749119037eb12a189c80004c7c789f813f158
4
+ data.tar.gz: e01b6cd9c760f72f8c542206de12770e44b75bc18252480b10d84fb046d5ac0d
5
5
  SHA512:
6
- metadata.gz: ea46e87d73ad2440115c91e91d73c8aeeb018eca04b0c430bd9c2c5dba7e2041fcc18b62efc0b17631fd8b39cbc9b29098722e8e8404945cf584baef463a0368
7
- data.tar.gz: caf48a8612c247ac0f6c6e77d0bcf480f77aa74e15fe8ca63316411f818c5a66b36cddc15eb894068e5dfefbe4376b8d9023ae06e0a5b8a5aba5e7a10a623747
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.
@@ -31,14 +31,9 @@ module GdsApi
31
31
  .to_return(body: "Some file content", status: 200)
32
32
  end
33
33
 
34
- def stub_asset_manager_has_a_whitehall_asset(legacy_url_path, atts)
35
- response = atts.merge("_response_info" => { "status" => "ok" })
36
-
37
- stub_request(:get, "#{ASSET_MANAGER_ENDPOINT}/whitehall_assets/#{legacy_url_path}")
38
- .to_return(body: response.to_json, status: 200)
39
-
34
+ def stub_asset_manager_has_a_whitehall_media_asset(legacy_url_path, content)
40
35
  stub_request(:get, "#{ASSET_MANAGER_ENDPOINT}/#{legacy_url_path}")
41
- .to_return(body: "Some file content", status: 200)
36
+ .to_return(body: content, status: 200)
42
37
  end
43
38
 
44
39
  def stub_asset_manager_does_not_have_an_asset(id)
@@ -50,15 +45,6 @@ module GdsApi
50
45
  .to_return(body: response.to_json, status: 404)
51
46
  end
52
47
 
53
- def stub_asset_manager_does_not_have_a_whitehall_asset(legacy_url_path)
54
- response = {
55
- "_response_info" => { "status" => "not found" },
56
- }
57
-
58
- stub_request(:get, "#{ASSET_MANAGER_ENDPOINT}/whitehall_assets/#{legacy_url_path}")
59
- .to_return(body: response.to_json, status: 404)
60
- end
61
-
62
48
  # This can take a string of an exact url or a hash of options
63
49
  #
64
50
  # with a string:
@@ -1,3 +1,3 @@
1
1
  module GdsApi
2
- VERSION = "91.1.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.1.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-14 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