gds-api-adapters 31.1.0 → 31.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: 3958ad60a4dd784913638e24174ec1cbaa6bf5bf
4
- data.tar.gz: 472556864dd1a993b30ac799f92d00f103323929
3
+ metadata.gz: c42cb1e42bd86839f165b478625dd26da0565661
4
+ data.tar.gz: 001a349f35443aba6650d824d4302295bbb485cf
5
5
  SHA512:
6
- metadata.gz: d7fe0d40e473efb738e009106cb05bf5fba2b93661c32696ad7ec5ee53840c92a45acf43e2ecc05d104088d5ab6eee0cf2da06ef6241316fb4b29dc7e63c1529
7
- data.tar.gz: 67310a8f8a8b02a4779d372d9dc8b7416de404af60c66411c217149899051b6bc036592ff6eb6ff34982244fa00aab3f9f6c17ee5c3cce13788b99b5352e4af8
6
+ metadata.gz: 85c6c6760862684095f99dd1e4e1496852c408f0e9158cf4794cd5ca2394bed546d783c05043ed540a5b810a44c1946c32a41ea0028ca2bf91020846c1d859fa
7
+ data.tar.gz: 97e59749dbd70fc76ea10682ba87a863d460a9c3664044c3afc4dd889f95a3018c10b67e99e6e4d969e3bd53180813c164af26ec789f31ba6e227071bfe592c5
@@ -3,42 +3,88 @@ require_relative 'exceptions'
3
3
 
4
4
  class GdsApi::AssetManager < GdsApi::Base
5
5
 
6
- # Creates an asset given attributes
6
+ # Creates an asset given a hash with one +file+ attribute
7
7
  #
8
- # Makes a `POST` request to the asset manager api to create an asset. The api accepts
9
- # the following attributes:
8
+ # Makes a +POST+ request to the asset manager api to create an asset.
10
9
  #
11
- # * `file` - a File object
10
+ # The asset must be provided as a +Hash+ with a single +file+ attribute that
11
+ # behaves like a +File+ object. The +content-type+ that the asset manager will
12
+ # subsequently serve will be based *only* on the file's extension (derived
13
+ # from +#path+). If you supply a +content-type+ via, for example
14
+ # +ActionDispatch::Http::UploadedFile+ or another multipart wrapper, it will
15
+ # be ignored.
12
16
  #
13
- # @param asset [Hash] The attributes for the asset to send to the api.
14
- # @return [Net::HTTPResponse] The raw http response from the api.
17
+ # @param asset [Hash] The attributes for the asset to send to the api. Must
18
+ # contain +file+, which behaves like a +File+. All other attributes will be
19
+ # ignored.
20
+ # @return [GdsApi::Response] The wrapped http response from the api. Behaves
21
+ # both as a +Hash+ and an +OpenStruct+, and responds to the following:
22
+ # :id the URL of the asset
23
+ # :name the filename of the asset that will be served
24
+ # :content_type the content_type of the asset
25
+ # :file_url the URL from which the asset will be served when it has
26
+ # passed a virus scan
27
+ # :state One of 'unscanned', 'clean', or 'infected'. Unless the state is
28
+ # 'clean' the asset at the :file_url will 404
15
29
  #
16
30
  # @raise [HTTPErrorResponse] if the request returns an error
31
+ #
32
+ # @example Upload a file from disk
33
+ # response = asset_manager.create_asset(file: File.new('image.jpg', 'r'))
34
+ # response.id #=> "http://asset-manager.dev.gov.uk/assets/576bbc52759b74196b000012"
35
+ # response.content_type #=> "image/jpeg"
36
+ # @example Upload a file from a Rails param, (typically a multipart wrapper)
37
+ # params[:file] #=> #<ActionDispatch::Http::UploadedFile:0x007fc60b43c5c8
38
+ # # @content_type="application/foofle",
39
+ # # @original_filename="cma_case_image.jpg",
40
+ # # @tempfile="spec/support/images/cma_case_image.jpg">
41
+ #
42
+ # # Though we sent a file with a +content_type+ of 'application/foofle',
43
+ # # this was ignored
44
+ # response = asset_manager.create_asset(file: params[:file])
45
+ # response.content_type #=> "image/jpeg"
17
46
  def create_asset(asset)
18
47
  post_multipart("#{base_url}/assets", { :asset => asset })
19
48
  end
20
49
 
21
- # Updates an asset given attributes
50
+ # Updates an asset given a hash with one +file+ attribute
22
51
  #
23
- # Makes a `PUT` request to the asset manager api to update an asset.
24
- # The api accepts the following attributes:
52
+ # Makes a +PUT+ request to the asset manager api to update an asset.
25
53
  #
26
- # * `file` - a File object
54
+ # The asset must be provided as a +Hash+ with a single +file+ attribute that
55
+ # behaves like a +File+ object. The +content-type+ that the asset manager will
56
+ # subsequently serve will be based *only* on the file's extension (derived
57
+ # from +#path+). If you supply a +content-type+ via, for example
58
+ # +ActionDispatch::Http::UploadedFile+ or another multipart wrapper, it will
59
+ # be ignored.
27
60
  #
28
- # @param id [String] The asset identifier
29
- # @param asset [Hash] The attributes for the asset to send to the api.
30
- # @return [Net::HTTPResponse] The raw http response from the api.
61
+ # @param id [String] The asset identifier (a UUID).
62
+ # @param asset [Hash] The attributes for the asset to send to the api. Must
63
+ # contain +file+, which behaves like a +File+. All other attributes will be
64
+ # ignored.
65
+ # @return [GdsApi::Response] The wrapped http response from the api. Behaves
66
+ # both as a +Hash+ and an +OpenStruct+, and responds to the following:
67
+ # :id the URL of the asset
68
+ # :name the filename of the asset that will be served
69
+ # :content_type the content_type of the asset
70
+ # :file_url the URL from which the asset will be served when it has
71
+ # passed a virus scan
72
+ # :state One of 'unscanned', 'clean', or 'infected'. Unless the state is
73
+ # 'clean' the asset at the :file_url will 404
31
74
  #
32
75
  # @raise [HTTPErrorResponse] if the request returns an error
76
+ # @example Update a file from disk
77
+ # uuid = '594602dd-75b3-4e6f-b5d1-cacf8c4d4164'
78
+ # asset_manager.update_asset(uuid, file: File.new('image.jpg', 'r'))
33
79
  def update_asset(id, asset)
34
80
  put_multipart("#{base_url}/assets/#{id}", { :asset => asset })
35
81
  end
36
82
 
37
83
  # Fetches an asset given the id
38
84
  #
39
- # @param id [String] The asset identifier
40
- # @return [Response, nil] A response object containing the parsed JSON response. If
41
- # the asset cannot be found, nil wil be returned.
85
+ # @param id [String] The asset identifier (a UUID).
86
+ # @return [GdsApi::Response, nil] A response object containing the parsed JSON response. If
87
+ # the asset cannot be found, +nil+ wil be returned.
42
88
  #
43
89
  # @raise [HTTPErrorResponse] if the request returns an error
44
90
  def asset(id)
data/lib/gds_api/mapit.rb CHANGED
@@ -12,6 +12,10 @@ class GdsApi::Mapit < GdsApi::Base
12
12
  get_json("#{base_url}/areas/#{type}.json")
13
13
  end
14
14
 
15
+ def area_for_code(code_type, code)
16
+ get_json("#{base_url}/code/#{code_type}/#{code}.json")
17
+ end
18
+
15
19
  class Location
16
20
  attr_reader :response
17
21
 
@@ -28,7 +28,8 @@ module GdsApi
28
28
  [i, {
29
29
  'codes' => {
30
30
  'ons' => area['ons'],
31
- 'gss' => area['gss']
31
+ 'gss' => area['gss'],
32
+ 'govuk_slug' => area['govuk_slug']
32
33
  },
33
34
  'name' => area['name'],
34
35
  'type' => area['type']
@@ -60,6 +61,16 @@ module GdsApi
60
61
  stub_request(:get, "#{MAPIT_ENDPOINT}/areas/" + area_type + ".json")
61
62
  .to_return(:body => [].to_json, :status => 200)
62
63
  end
64
+
65
+ def mapit_has_area_for_code(code_type, code, area)
66
+ stub_request(:get, "#{MAPIT_ENDPOINT}/code/#{code_type}/#{code}.json")
67
+ .to_return(:body => area.to_json, :status => 200)
68
+ end
69
+
70
+ def mapit_does_not_have_area_for_code(code_type, code)
71
+ stub_request(:get, "#{MAPIT_ENDPOINT}/code/#{code_type}/#{code}.json")
72
+ .to_return(:body => { "code" => 404, "error" => "No areas were found that matched code #{code_type} = #{code}." }.to_json, :status => 404)
73
+ end
63
74
  end
64
75
  end
65
76
  end
@@ -1,3 +1,3 @@
1
1
  module GdsApi
2
- VERSION = '31.1.0'
2
+ VERSION = '31.2.0'
3
3
  end
data/test/mapit_test.rb CHANGED
@@ -59,6 +59,7 @@ describe GdsApi::Mapit do
59
59
  end
60
60
  end
61
61
  end
62
+
62
63
  describe "areas_for_type" do
63
64
  before do
64
65
  mapit_has_areas('EUR', {
@@ -85,4 +86,30 @@ describe GdsApi::Mapit do
85
86
  assert_empty response
86
87
  end
87
88
  end
89
+
90
+ describe "area_for_code" do
91
+ before do
92
+ south_ribble_area = {
93
+ name: "South Ribble Borough Council",
94
+ codes: {
95
+ ons: "30UN",
96
+ gss: "E07000126",
97
+ unit_id: "4834"
98
+ },
99
+ type: "DIS"
100
+ }
101
+ mapit_has_area_for_code('ons', '30UN', south_ribble_area)
102
+ mapit_does_not_have_area_for_code('govuk_slug', 'neverland')
103
+ end
104
+
105
+ it "should return area for a code type" do
106
+ area = @api.area_for_code('ons', '30UN')
107
+
108
+ assert_equal "South Ribble Borough Council", area["name"]
109
+ end
110
+
111
+ it "should return 404 for a missing area of a certain code type" do
112
+ assert_nil @api.area_for_code('govuk_slug', 'neverland')
113
+ end
114
+ end
88
115
  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: 31.1.0
4
+ version: 31.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-06-16 00:00:00.000000000 Z
11
+ date: 2016-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: plek
@@ -471,55 +471,55 @@ signing_key:
471
471
  specification_version: 4
472
472
  summary: Adapters to work with GDS APIs
473
473
  test_files:
474
- - test/support_api_test.rb
475
- - test/mapit_test.rb
474
+ - test/content_api_test.rb
475
+ - test/json_client_test.rb
476
+ - test/content_store_test.rb
476
477
  - test/publishing_api_test.rb
477
- - test/publishing_api_v2/lookup_test.rb
478
- - test/publishing_api_v2/get_links_test.rb
479
- - test/publishing_api_v2/get_expanded_links_test.rb
478
+ - test/business_support_api_test.rb
479
+ - test/middleware/govuk_header_sniffer_test.rb
480
480
  - test/whitehall_admin_api_test.rb
481
- - test/pp_data_in_test.rb
482
- - test/publishing_api/special_route_publisher_test.rb
483
- - test/need_api_test.rb
484
- - test/publisher_api_test.rb
485
- - test/rummager_helpers_test.rb
481
+ - test/list_response_test.rb
482
+ - test/maslow_test.rb
483
+ - test/panopticon_registerer_test.rb
486
484
  - test/support_test.rb
487
- - test/test_helpers/publishing_api_test.rb
488
- - test/test_helpers/pact_helper.rb
489
- - test/test_helpers/panopticon_test.rb
490
- - test/test_helpers/email_alert_api_test.rb
491
- - test/test_helpers/publishing_api_v2_test.rb
485
+ - test/asset_manager_test.rb
486
+ - test/helpers_test.rb
492
487
  - test/licence_application_api_test.rb
493
- - test/gov_uk_delivery_test.rb
494
- - test/maslow_test.rb
488
+ - test/test_helper.rb
495
489
  - test/govuk_headers_test.rb
496
- - test/helpers_test.rb
497
- - test/panopticon_registerer_test.rb
498
- - test/panopticon_test.rb
499
- - test/middleware/govuk_header_sniffer_test.rb
500
- - test/rummager_test.rb
501
- - test/json_client_test.rb
502
- - test/email_alert_api_test.rb
503
- - test/content_api_test.rb
504
- - test/response_test.rb
490
+ - test/publisher_api_test.rb
491
+ - test/mapit_test.rb
492
+ - test/rummager_helpers_test.rb
493
+ - test/publishing_api_v2_test.rb
494
+ - test/publishing_api_v2/lookup_test.rb
495
+ - test/publishing_api_v2/get_expanded_links_test.rb
496
+ - test/publishing_api_v2/get_links_test.rb
497
+ - test/support_api_test.rb
505
498
  - test/organisations_api_test.rb
506
- - test/imminence_api_test.rb
507
- - test/content_store_test.rb
508
- - test/asset_manager_test.rb
499
+ - test/gds_api_base_test.rb
500
+ - test/router_test.rb
501
+ - test/publishing_api/special_route_publisher_test.rb
502
+ - test/external_link_tracker_test.rb
503
+ - test/need_api_test.rb
504
+ - test/panopticon_test.rb
505
+ - test/pp_data_in_test.rb
509
506
  - test/fixtures/hello.txt
510
507
  - test/fixtures/new_policies_for_dwp.json
511
- - test/fixtures/world_organisations_australia.json
512
508
  - test/fixtures/no_services_and_info_data_found_fixture.json
513
- - test/fixtures/old_policies_for_dwp.json
514
509
  - test/fixtures/services_and_info_fixture.json
510
+ - test/fixtures/old_policies_for_dwp.json
511
+ - test/fixtures/world_organisations_australia.json
515
512
  - test/fixtures/sub_sector_organisations.json
516
513
  - test/fixtures/finder_api/cma-case-schema.json
517
- - test/router_test.rb
518
- - test/list_response_test.rb
519
- - test/external_link_tracker_test.rb
520
- - test/gds_api_base_test.rb
521
514
  - test/worldwide_api_test.rb
522
- - test/test_helper.rb
523
- - test/publishing_api_v2_test.rb
524
- - test/business_support_api_test.rb
515
+ - test/test_helpers/publishing_api_test.rb
516
+ - test/test_helpers/publishing_api_v2_test.rb
517
+ - test/test_helpers/pact_helper.rb
518
+ - test/test_helpers/panopticon_test.rb
519
+ - test/test_helpers/email_alert_api_test.rb
520
+ - test/gov_uk_delivery_test.rb
521
+ - test/imminence_api_test.rb
522
+ - test/email_alert_api_test.rb
523
+ - test/response_test.rb
524
+ - test/rummager_test.rb
525
525
  has_rdoc: