gds-api-adapters 36.1.0 → 36.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bcbac32e46d147fa75d158358e3f43b858dc717f
4
- data.tar.gz: f0085c380372ea653dbe604d12b956ce47cfb6c9
3
+ metadata.gz: 159f3160e4dabd497fa880d34c3bdcf5e6cf969b
4
+ data.tar.gz: f797232c04c2cdb65463bc09ea6ac76f47ccdecb
5
5
  SHA512:
6
- metadata.gz: 777ae29ce2fd0b642452b4bf84c292a0aa2b198b1945ddccfce464841c6c119ac912e8308b228fd8dceee1ef4185e0809b7eeaf8ca6e2c155b4e8f6495724a35
7
- data.tar.gz: 5a7182ee26869c0ee8da18208538a3032a5501980109974bea46f482ee5ab40d570dacfc1f0236cbd90f877ca20faef423fed7369b51db91370a7c63d7036f0d
6
+ metadata.gz: a2c0eb54200b50436293a626f340a340f7d6d1f17374e8a2fa8c59fbd8daaff402050a8763f908acaabd7c1ef4e75549022fcdd218898380b3dd9111feb6c286
7
+ data.tar.gz: 78ed4872691ad3e45156ef2671e4839a1ac708caa76ca8a8e0b001bafd62d4a42c9d17a5489d6a2fd65ddb3fedf3dd036b5fc2a1ceaf33cdc5c00c6f675571ae
@@ -91,6 +91,29 @@ class GdsApi::AssetManager < GdsApi::Base
91
91
  get_json("#{base_url}/assets/#{id}")
92
92
  end
93
93
 
94
+ # Deletes an asset given an id
95
+ #
96
+ # Makes a +DELETE+ request to the asset manager api to delete an asset.
97
+ #
98
+ # @param id [String] The asset identifier (a UUID).
99
+ # @return [GdsApi::Response] The wrapped http response from the api. Behaves
100
+ # both as a +Hash+ and an +OpenStruct+, and responds to the following:
101
+ # :id the URL of the asset
102
+ # :name the filename of the asset that will be served
103
+ # :content_type the content_type of the asset
104
+ # :file_url the URL from which the asset will be served when it has
105
+ # passed a virus scan
106
+ # :state One of 'unscanned', 'clean', or 'infected'. Unless the state is
107
+ # 'clean' the asset at the :file_url will 404
108
+ #
109
+ # @raise [HTTPErrorResponse] if the request returns an error
110
+ # @example Delete a file from disk
111
+ # uuid = '594602dd-75b3-4e6f-b5d1-cacf8c4d4164'
112
+ # asset_manager.delete_asset(uuid)
113
+ def delete_asset(id)
114
+ delete_json("#{base_url}/assets/#{id}")
115
+ end
116
+
94
117
  private
95
118
  def base_url
96
119
  endpoint
@@ -169,8 +169,13 @@ module GdsApi
169
169
  #)
170
170
  def publishing_api_has_content(items, params = {})
171
171
  url = PUBLISHING_API_V2_ENDPOINT + "/content"
172
- per_page = params.fetch(:per_page, 50)
173
- page = params.fetch(:page, 1)
172
+ if params.respond_to? :fetch
173
+ per_page = params.fetch(:per_page, 50)
174
+ page = params.fetch(:page, 1)
175
+ else
176
+ per_page = 50
177
+ page = 1
178
+ end
174
179
  number_of_pages = items.count < per_page ? 1 : items.count / per_page
175
180
 
176
181
  body = {
@@ -1,3 +1,3 @@
1
1
  module GdsApi
2
- VERSION = '36.1.0'
2
+ VERSION = '36.2.0'
3
3
  end
@@ -22,6 +22,14 @@ describe GdsApi::AssetManager do
22
22
  }
23
23
  }
24
24
 
25
+ before do
26
+ GdsApi.config.always_raise_for_not_found = true
27
+ end
28
+
29
+ after do
30
+ GdsApi.config.always_raise_for_not_found = false
31
+ end
32
+
25
33
  it "creates an asset with a file" do
26
34
  req = stub_request(:post, "#{base_api_url}/assets").
27
35
  with(:body => %r{Content\-Disposition: form\-data; name="asset\[file\]"; filename="hello\.txt"\r\nContent\-Type: text/plain}).
@@ -33,10 +41,12 @@ describe GdsApi::AssetManager do
33
41
  assert_requested(req)
34
42
  end
35
43
 
36
- it "returns nil when an asset does not exist" do
44
+ it "returns not found when an asset does not exist" do
37
45
  asset_manager_does_not_have_an_asset("not-really-here")
38
46
 
39
- assert_nil api.asset("not-really-here")
47
+ assert_raises GdsApi::HTTPNotFound do
48
+ api.asset("not-really-here")
49
+ end
40
50
  end
41
51
 
42
52
  describe "an asset exists" do
@@ -69,4 +79,14 @@ describe GdsApi::AssetManager do
69
79
  assert_equal "http://fooey.gov.uk/media/photo.jpg", asset.file_url
70
80
  end
71
81
  end
82
+
83
+ it "deletes an asset for the given id" do
84
+ req = stub_request(:delete, "#{base_api_url}/assets/#{asset_id}").
85
+ to_return(:body => JSON.dump(asset_manager_response), :status => 200)
86
+
87
+ response = api.delete_asset(asset_id)
88
+
89
+ assert_equal "#{base_api_url}/assets/#{asset_id}", response.asset.id
90
+ assert_requested(req)
91
+ end
72
92
  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: 36.1.0
4
+ version: 36.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: 2016-09-26 00:00:00.000000000 Z
11
+ date: 2016-09-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: plek