gds-api-adapters 38.0.0 → 38.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +5 -5
- data/lib/gds_api/asset_manager.rb +7 -7
- data/lib/gds_api/base.rb +13 -11
- data/lib/gds_api/business_support_api.rb +3 -4
- data/lib/gds_api/content_api.rb +31 -44
- data/lib/gds_api/content_store.rb +2 -3
- data/lib/gds_api/email_alert_api.rb +6 -7
- data/lib/gds_api/exceptions.rb +4 -1
- data/lib/gds_api/gov_uk_delivery.rb +9 -8
- data/lib/gds_api/govuk_headers.rb +1 -1
- data/lib/gds_api/imminence.rb +9 -10
- data/lib/gds_api/json_client.rb +21 -34
- data/lib/gds_api/licence_application.rb +2 -2
- data/lib/gds_api/list_response.rb +7 -10
- data/lib/gds_api/local_links_manager.rb +1 -1
- data/lib/gds_api/mapit.rb +5 -6
- data/lib/gds_api/middleware/govuk_header_sniffer.rb +1 -1
- data/lib/gds_api/need_api.rb +7 -8
- data/lib/gds_api/null_cache.rb +2 -2
- data/lib/gds_api/organisations.rb +2 -2
- data/lib/gds_api/panopticon.rb +11 -11
- data/lib/gds_api/performance_platform/data_in.rb +4 -4
- data/lib/gds_api/performance_platform/data_out.rb +1 -1
- data/lib/gds_api/publishing_api.rb +4 -5
- data/lib/gds_api/publishing_api/special_route_publisher.rb +5 -3
- data/lib/gds_api/publishing_api_v2.rb +8 -16
- data/lib/gds_api/response.rb +2 -5
- data/lib/gds_api/router.rb +18 -9
- data/lib/gds_api/rummager.rb +6 -7
- data/lib/gds_api/support.rb +7 -6
- data/lib/gds_api/support_api.rb +14 -14
- data/lib/gds_api/test_helpers/asset_manager.rb +3 -6
- data/lib/gds_api/test_helpers/business_support_api.rb +4 -4
- data/lib/gds_api/test_helpers/business_support_helper.rb +9 -8
- data/lib/gds_api/test_helpers/common_responses.rb +10 -12
- data/lib/gds_api/test_helpers/content_api.rb +23 -23
- data/lib/gds_api/test_helpers/content_api/artefact_stub.rb +13 -12
- data/lib/gds_api/test_helpers/content_item_helpers.rb +4 -4
- data/lib/gds_api/test_helpers/content_store.rb +3 -3
- data/lib/gds_api/test_helpers/email_alert_api.rb +8 -10
- data/lib/gds_api/test_helpers/gov_uk_delivery.rb +0 -1
- data/lib/gds_api/test_helpers/imminence.rb +4 -4
- data/lib/gds_api/test_helpers/intent_helpers.rb +0 -2
- data/lib/gds_api/test_helpers/local_links_manager.rb +12 -13
- data/lib/gds_api/test_helpers/mapit.rb +14 -15
- data/lib/gds_api/test_helpers/need_api.rb +4 -4
- data/lib/gds_api/test_helpers/organisations.rb +13 -15
- data/lib/gds_api/test_helpers/panopticon.rb +6 -6
- data/lib/gds_api/test_helpers/performance_platform/data_in.rb +8 -8
- data/lib/gds_api/test_helpers/publishing_api.rb +19 -20
- data/lib/gds_api/test_helpers/publishing_api_v2.rb +13 -13
- data/lib/gds_api/test_helpers/router.rb +5 -5
- data/lib/gds_api/test_helpers/rummager.rb +5 -4
- data/lib/gds_api/test_helpers/support.rb +11 -11
- data/lib/gds_api/test_helpers/support_api.rb +14 -14
- data/lib/gds_api/test_helpers/whitehall_admin_api.rb +1 -1
- data/lib/gds_api/test_helpers/worldwide.rb +16 -19
- data/lib/gds_api/version.rb +1 -1
- data/lib/gds_api/worldwide.rb +4 -4
- data/test/asset_manager_test.rb +6 -6
- data/test/business_support_api_test.rb +9 -10
- data/test/content_api_test.rb +81 -83
- data/test/email_alert_api_test.rb +3 -5
- data/test/gds_api_base_test.rb +9 -10
- data/test/gov_uk_delivery_test.rb +4 -6
- data/test/imminence_api_test.rb +7 -9
- data/test/json_client_test.rb +71 -64
- data/test/licence_application_api_test.rb +5 -7
- data/test/list_response_test.rb +27 -32
- data/test/mapit_test.rb +7 -9
- data/test/middleware/govuk_header_sniffer_test.rb +1 -1
- data/test/need_api_test.rb +8 -8
- data/test/organisations_api_test.rb +2 -2
- data/test/panopticon_registerer_test.rb +10 -10
- data/test/panopticon_test.rb +5 -5
- data/test/pp_data_in_test.rb +3 -3
- data/test/publishing_api_test.rb +2 -6
- data/test/publishing_api_v2_test.rb +40 -50
- data/test/response_test.rb +21 -22
- data/test/router_test.rb +78 -80
- data/test/rummager_test.rb +14 -14
- data/test/support_api_test.rb +13 -13
- data/test/support_test.rb +15 -16
- data/test/test_helper.rb +1 -1
- data/test/test_helpers/email_alert_api_test.rb +3 -3
- data/test/test_helpers/pact_helper.rb +1 -1
- data/test/test_helpers/panopticon_test.rb +1 -1
- data/test/test_helpers/publishing_api_test.rb +7 -7
- data/test/test_helpers/publishing_api_v2_test.rb +5 -9
- data/test/worldwide_api_test.rb +3 -3
- metadata +2 -3
- data/lib/gds_api/core-ext/openstruct.rb +0 -5
@@ -35,7 +35,7 @@ module GdsApi
|
|
35
35
|
response = {
|
36
36
|
status: 200,
|
37
37
|
body: '{}',
|
38
|
-
headers: {"Content-Type" => "application/json; charset=utf-8"}
|
38
|
+
headers: { "Content-Type" => "application/json; charset=utf-8" }
|
39
39
|
}.merge(response_hash)
|
40
40
|
stub_request(:post, url).with(body: body).to_return(response)
|
41
41
|
end
|
@@ -45,14 +45,14 @@ module GdsApi
|
|
45
45
|
response = {
|
46
46
|
status: 200,
|
47
47
|
body: '{}',
|
48
|
-
headers: {"Content-Type" => "application/json; charset=utf-8"}
|
48
|
+
headers: { "Content-Type" => "application/json; charset=utf-8" }
|
49
49
|
}.merge(response_hash)
|
50
50
|
stub_request(:post, url).with(params).to_return(response)
|
51
51
|
end
|
52
52
|
|
53
53
|
def stub_publishing_api_discard_draft(content_id)
|
54
54
|
url = PUBLISHING_API_V2_ENDPOINT + "/content/#{content_id}/discard-draft"
|
55
|
-
stub_request(:post, url).to_return(status: 200, headers: {"Content-Type" => "application/json; charset=utf-8"})
|
55
|
+
stub_request(:post, url).to_return(status: 200, headers: { "Content-Type" => "application/json; charset=utf-8" })
|
56
56
|
end
|
57
57
|
|
58
58
|
def stub_publishing_api_put_content_links_and_publish(body, content_id = nil, publish_body = nil)
|
@@ -94,7 +94,7 @@ module GdsApi
|
|
94
94
|
|
95
95
|
def stub_any_publishing_api_call_to_return_not_found
|
96
96
|
stub_request(:any, %r{\A#{PUBLISHING_API_V2_ENDPOINT}})
|
97
|
-
.to_return(status: 404, headers: {"Content-Type" => "application/json; charset=utf-8"})
|
97
|
+
.to_return(status: 404, headers: { "Content-Type" => "application/json; charset=utf-8" })
|
98
98
|
end
|
99
99
|
|
100
100
|
def publishing_api_isnt_available
|
@@ -186,7 +186,7 @@ module GdsApi
|
|
186
186
|
page = 1
|
187
187
|
end
|
188
188
|
|
189
|
-
start_position = (page-1) * per_page
|
189
|
+
start_position = (page - 1) * per_page
|
190
190
|
page_items = items.slice(start_position, per_page) || []
|
191
191
|
|
192
192
|
number_of_pages =
|
@@ -210,7 +210,7 @@ module GdsApi
|
|
210
210
|
|
211
211
|
# This method has been refactored into publishing_api_has_content (above)
|
212
212
|
# publishing_api_has_content allows for flexible passing in of arguments, please use instead
|
213
|
-
def publishing_api_has_fields_for_document(
|
213
|
+
def publishing_api_has_fields_for_document(document_type, items, fields)
|
214
214
|
body = Array(items).map { |item|
|
215
215
|
item.with_indifferent_access.slice(*fields)
|
216
216
|
}
|
@@ -219,14 +219,14 @@ module GdsApi
|
|
219
219
|
"&fields%5B%5D=#{f}"
|
220
220
|
}
|
221
221
|
|
222
|
-
url = PUBLISHING_API_V2_ENDPOINT + "/content?document_type=#{
|
222
|
+
url = PUBLISHING_API_V2_ENDPOINT + "/content?document_type=#{document_type}#{query_params.join('')}"
|
223
223
|
|
224
|
-
stub_request(:get, url).to_return(:
|
224
|
+
stub_request(:get, url).to_return(status: 200, body: { results: body }.to_json, headers: {})
|
225
225
|
end
|
226
226
|
|
227
227
|
def publishing_api_has_linkables(linkables, document_type:)
|
228
228
|
url = PUBLISHING_API_V2_ENDPOINT + "/linkables?document_type=#{document_type}"
|
229
|
-
stub_request(:get, url).to_return(:
|
229
|
+
stub_request(:get, url).to_return(status: 200, body: linkables.to_json, headers: {})
|
230
230
|
end
|
231
231
|
|
232
232
|
def publishing_api_has_item(item)
|
@@ -240,7 +240,7 @@ module GdsApi
|
|
240
240
|
url = PUBLISHING_API_V2_ENDPOINT + "/content/" + content_id
|
241
241
|
calls = -1
|
242
242
|
|
243
|
-
stub_request(:get, url).to_return do |
|
243
|
+
stub_request(:get, url).to_return do |_request|
|
244
244
|
calls += 1
|
245
245
|
item = items[calls] || items.last
|
246
246
|
|
@@ -414,7 +414,7 @@ module GdsApi
|
|
414
414
|
end
|
415
415
|
|
416
416
|
def stub_publishing_api_postlike_call(method, content_id, body, resource_path, override_response_hash = {})
|
417
|
-
response_hash = {status: 200, body: '{}', headers: {"Content-Type" => "application/json; charset=utf-8"}}
|
417
|
+
response_hash = { status: 200, body: '{}', headers: { "Content-Type" => "application/json; charset=utf-8" } }
|
418
418
|
response_hash.merge!(override_response_hash)
|
419
419
|
response_hash[:body] = response_hash[:body].to_json if response_hash[:body].is_a?(Hash)
|
420
420
|
url = PUBLISHING_API_V2_ENDPOINT + resource_path + "/" + content_id
|
@@ -422,7 +422,7 @@ module GdsApi
|
|
422
422
|
end
|
423
423
|
|
424
424
|
def deep_stringify_keys(hash)
|
425
|
-
deep_transform_keys(hash
|
425
|
+
deep_transform_keys(hash, &:to_s)
|
426
426
|
end
|
427
427
|
|
428
428
|
def deep_transform_keys(object, &block)
|
@@ -432,7 +432,7 @@ module GdsApi
|
|
432
432
|
result[yield(key)] = deep_transform_keys(value, &block)
|
433
433
|
end
|
434
434
|
when Array
|
435
|
-
object.map{ |item| deep_transform_keys(item, &block) }
|
435
|
+
object.map { |item| deep_transform_keys(item, &block) }
|
436
436
|
else
|
437
437
|
object
|
438
438
|
end
|
@@ -12,10 +12,10 @@ module GdsApi
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def stub_router_backend_registration(backend_id, backend_url)
|
15
|
-
backend = { "backend" => { "backend_url" => backend_url }}
|
15
|
+
backend = { "backend" => { "backend_url" => backend_url } }
|
16
16
|
stub_http_request(:put, "#{ROUTER_API_ENDPOINT}/backends/#{backend_id}")
|
17
|
-
.with(:
|
18
|
-
.to_return(:
|
17
|
+
.with(body: backend.to_json)
|
18
|
+
.to_return(status: 201)
|
19
19
|
end
|
20
20
|
|
21
21
|
def stub_route_registration(path, type, backend_id)
|
@@ -66,8 +66,8 @@ module GdsApi
|
|
66
66
|
|
67
67
|
def stub_route_put(route)
|
68
68
|
stub_http_request(:put, "#{ROUTER_API_ENDPOINT}/routes")
|
69
|
-
.with(:
|
70
|
-
.to_return(:
|
69
|
+
.with(body: route.to_json)
|
70
|
+
.to_return(status: 201)
|
71
71
|
end
|
72
72
|
end
|
73
73
|
end
|
@@ -100,7 +100,7 @@ module GdsApi
|
|
100
100
|
run_example_query
|
101
101
|
end
|
102
102
|
|
103
|
-
def rummager_has_specialist_sector_organisations(
|
103
|
+
def rummager_has_specialist_sector_organisations(_sub_sector)
|
104
104
|
stub_request_for(sub_sector_organisations_results)
|
105
105
|
run_example_query
|
106
106
|
end
|
@@ -111,9 +111,9 @@ module GdsApi
|
|
111
111
|
end
|
112
112
|
|
113
113
|
def rummager_has_policies_for_every_type(options = {})
|
114
|
-
if
|
115
|
-
stub_request(:get, %r{/search.json.*count=#{count}.*})
|
116
|
-
.to_return(body: first_n_results(new_policies_results, n: count))
|
114
|
+
if options[:count]
|
115
|
+
stub_request(:get, %r{/search.json.*count=#{options[:count]}.*})
|
116
|
+
.to_return(body: first_n_results(new_policies_results, n: options[:count]))
|
117
117
|
else
|
118
118
|
stub_request(:get, %r{/search.json})
|
119
119
|
.to_return(body: new_policies_results)
|
@@ -121,6 +121,7 @@ module GdsApi
|
|
121
121
|
end
|
122
122
|
|
123
123
|
private
|
124
|
+
|
124
125
|
def stub_request_for(result_set)
|
125
126
|
stub_request(:get, /example.com\/search/).to_return(body: result_set)
|
126
127
|
end
|
@@ -5,36 +5,36 @@ module GdsApi
|
|
5
5
|
|
6
6
|
def stub_support_foi_request_creation(request_details = nil)
|
7
7
|
post_stub = stub_http_request(:post, "#{SUPPORT_ENDPOINT}/foi_requests")
|
8
|
-
post_stub.with(:
|
9
|
-
post_stub.to_return(:
|
8
|
+
post_stub.with(body: { "foi_request" => request_details }) unless request_details.nil?
|
9
|
+
post_stub.to_return(status: 201)
|
10
10
|
end
|
11
11
|
|
12
12
|
def stub_support_problem_report_creation(request_details = nil)
|
13
13
|
post_stub = stub_http_request(:post, "#{SUPPORT_ENDPOINT}/anonymous_feedback/problem_reports")
|
14
|
-
post_stub.with(:
|
15
|
-
post_stub.to_return(:
|
14
|
+
post_stub.with(body: { problem_report: request_details }) unless request_details.nil?
|
15
|
+
post_stub.to_return(status: 201)
|
16
16
|
end
|
17
17
|
|
18
18
|
def stub_support_named_contact_creation(request_details = nil)
|
19
19
|
post_stub = stub_http_request(:post, "#{SUPPORT_ENDPOINT}/named_contacts")
|
20
|
-
post_stub.with(:
|
21
|
-
post_stub.to_return(:
|
20
|
+
post_stub.with(body: { named_contact: request_details }) unless request_details.nil?
|
21
|
+
post_stub.to_return(status: 201)
|
22
22
|
end
|
23
23
|
|
24
24
|
def stub_support_long_form_anonymous_contact_creation(request_details = nil)
|
25
25
|
post_stub = stub_http_request(:post, "#{SUPPORT_ENDPOINT}/anonymous_feedback/long_form_contacts")
|
26
|
-
post_stub.with(:
|
27
|
-
post_stub.to_return(:
|
26
|
+
post_stub.with(body: { long_form_contact: request_details }) unless request_details.nil?
|
27
|
+
post_stub.to_return(status: 201)
|
28
28
|
end
|
29
29
|
|
30
30
|
def stub_support_service_feedback_creation(feedback_details = nil)
|
31
31
|
post_stub = stub_http_request(:post, "#{SUPPORT_ENDPOINT}/anonymous_feedback/service_feedback")
|
32
|
-
post_stub.with(:
|
33
|
-
post_stub.to_return(:
|
32
|
+
post_stub.with(body: { service_feedback: feedback_details }) unless feedback_details.nil?
|
33
|
+
post_stub.to_return(status: 201)
|
34
34
|
end
|
35
35
|
|
36
36
|
def support_isnt_available
|
37
|
-
stub_request(:post, /#{SUPPORT_ENDPOINT}\/.*/).to_return(:
|
37
|
+
stub_request(:post, /#{SUPPORT_ENDPOINT}\/.*/).to_return(status: 503)
|
38
38
|
end
|
39
39
|
end
|
40
40
|
end
|
@@ -8,38 +8,38 @@ module GdsApi
|
|
8
8
|
|
9
9
|
def stub_support_api_problem_report_creation(request_details = nil)
|
10
10
|
post_stub = stub_http_request(:post, "#{SUPPORT_API_ENDPOINT}/anonymous-feedback/problem-reports")
|
11
|
-
post_stub.with(:
|
12
|
-
post_stub.to_return(:
|
11
|
+
post_stub.with(body: { problem_report: request_details }) unless request_details.nil?
|
12
|
+
post_stub.to_return(status: 202)
|
13
13
|
end
|
14
14
|
|
15
15
|
def stub_support_api_service_feedback_creation(feedback_details = nil)
|
16
16
|
post_stub = stub_http_request(:post, "#{SUPPORT_API_ENDPOINT}/anonymous-feedback/service-feedback")
|
17
|
-
post_stub.with(:
|
18
|
-
post_stub.to_return(:
|
17
|
+
post_stub.with(body: { service_feedback: feedback_details }) unless feedback_details.nil?
|
18
|
+
post_stub.to_return(status: 201)
|
19
19
|
end
|
20
20
|
|
21
21
|
def stub_support_long_form_anonymous_contact_creation(request_details = nil)
|
22
22
|
post_stub = stub_http_request(:post, "#{SUPPORT_API_ENDPOINT}/anonymous-feedback/long-form-contacts")
|
23
|
-
post_stub.with(:
|
24
|
-
post_stub.to_return(:
|
23
|
+
post_stub.with(body: { long_form_contact: request_details }) unless request_details.nil?
|
24
|
+
post_stub.to_return(status: 202)
|
25
25
|
end
|
26
26
|
|
27
27
|
def stub_support_feedback_export_request_creation(request_details = nil)
|
28
28
|
post_stub = stub_http_request(:post, "#{SUPPORT_API_ENDPOINT}/anonymous-feedback/export-requests")
|
29
|
-
post_stub.with(:
|
30
|
-
post_stub.to_return(:
|
29
|
+
post_stub.with(body: { export_request: request_details }) unless request_details.nil?
|
30
|
+
post_stub.to_return(status: 202)
|
31
31
|
end
|
32
32
|
|
33
33
|
def stub_support_global_export_request_creation(request_details = nil)
|
34
34
|
post_stub = stub_http_request(:post, "#{SUPPORT_API_ENDPOINT}/anonymous-feedback/global-export-requests")
|
35
|
-
post_stub.with(:
|
36
|
-
post_stub.to_return(:
|
35
|
+
post_stub.with(body: { global_export_request: request_details }) unless request_details.nil?
|
36
|
+
post_stub.to_return(status: 202)
|
37
37
|
end
|
38
38
|
|
39
39
|
def stub_create_page_improvement(params)
|
40
40
|
post_stub = stub_http_request(:post, "#{SUPPORT_API_ENDPOINT}/page-improvements")
|
41
|
-
post_stub.with(:
|
42
|
-
post_stub.to_return(:
|
41
|
+
post_stub.with(body: params)
|
42
|
+
post_stub.to_return(status: 201)
|
43
43
|
end
|
44
44
|
|
45
45
|
def stub_problem_report_daily_totals_for(date, expected_results = nil)
|
@@ -58,12 +58,12 @@ module GdsApi
|
|
58
58
|
|
59
59
|
def stub_support_mark_reviewed_for_spam(request_details = nil, response_body = {})
|
60
60
|
post_stub = stub_http_request(:put, "#{SUPPORT_API_ENDPOINT}/anonymous-feedback/problem-reports/mark-reviewed-for-spam")
|
61
|
-
post_stub.with(:
|
61
|
+
post_stub.with(body: { reviewed_problem_report_ids: request_details }) unless request_details.nil?
|
62
62
|
post_stub.to_return(status: 200, body: response_body.to_json)
|
63
63
|
end
|
64
64
|
|
65
65
|
def support_api_isnt_available
|
66
|
-
stub_request(:post, /#{SUPPORT_API_ENDPOINT}\/.*/).to_return(:
|
66
|
+
stub_request(:post, /#{SUPPORT_API_ENDPOINT}\/.*/).to_return(status: 503)
|
67
67
|
end
|
68
68
|
|
69
69
|
def stub_anonymous_feedback(params, response_body = {})
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module GdsApi
|
2
2
|
module TestHelpers
|
3
3
|
module WhitehallAdminApi
|
4
|
-
WHITEHALL_ADMIN_API_ENDPOINT = "#{Plek.current.find(
|
4
|
+
WHITEHALL_ADMIN_API_ENDPOINT = "#{Plek.current.find('whitehall-admin')}/government/admin/api".freeze
|
5
5
|
|
6
6
|
def stub_all_whitehall_admin_api_requests
|
7
7
|
stub_request(:any, %r|^#{WHITEHALL_ADMIN_API_ENDPOINT}|)
|
@@ -14,38 +14,36 @@ module GdsApi
|
|
14
14
|
# This also sets up the individual endpoints for each slug
|
15
15
|
# by calling worldwide_api_has_location below
|
16
16
|
def worldwide_api_has_locations(location_slugs)
|
17
|
-
location_slugs.each {|s| worldwide_api_has_location(s) }
|
17
|
+
location_slugs.each { |s| worldwide_api_has_location(s) }
|
18
18
|
pages = []
|
19
19
|
location_slugs.each_slice(20) do |slugs|
|
20
|
-
pages << slugs.map {|s| world_location_details_for_slug(s) }
|
20
|
+
pages << slugs.map { |s| world_location_details_for_slug(s) }
|
21
21
|
end
|
22
22
|
|
23
23
|
pages.each_with_index do |page, i|
|
24
|
-
page_details = plural_response_base.merge(
|
25
|
-
"results" => page,
|
24
|
+
page_details = plural_response_base.merge("results" => page,
|
26
25
|
"total" => location_slugs.size,
|
27
26
|
"pages" => pages.size,
|
28
27
|
"current_page" => i + 1,
|
29
28
|
"page_size" => 20,
|
30
|
-
"start_index" => i * 20 + 1
|
31
|
-
})
|
29
|
+
"start_index" => i * 20 + 1)
|
32
30
|
|
33
|
-
links = {:
|
34
|
-
links[:next] = "#{WORLDWIDE_API_ENDPOINT}/api/world-locations?page=#{i + 2}" if pages[i+1]
|
31
|
+
links = { self: "#{WORLDWIDE_API_ENDPOINT}/api/world-locations?page=#{i + 1}" }
|
32
|
+
links[:next] = "#{WORLDWIDE_API_ENDPOINT}/api/world-locations?page=#{i + 2}" if pages[i + 1]
|
35
33
|
links[:previous] = "#{WORLDWIDE_API_ENDPOINT}/api/world-locations?page=#{i}" unless i == 0
|
36
34
|
page_details["_response_info"]["links"] = []
|
37
35
|
link_headers = []
|
38
36
|
links.each do |rel, href|
|
39
|
-
page_details["_response_info"]["links"] << {"rel" => rel, "href" => href}
|
37
|
+
page_details["_response_info"]["links"] << { "rel" => rel, "href" => href }
|
40
38
|
link_headers << "<#{href}>; rel=\"#{rel}\""
|
41
39
|
end
|
42
40
|
|
43
41
|
stub_request(:get, links[:self]).
|
44
|
-
to_return(:
|
42
|
+
to_return(status: 200, body: page_details.to_json, headers: { "Link" => link_headers.join(", ") })
|
45
43
|
if i == 0
|
46
44
|
# First page exists at URL with and without page param
|
47
45
|
stub_request(:get, links[:self].sub(/\?page=1/, '')).
|
48
|
-
to_return(:
|
46
|
+
to_return(status: 200, body: page_details.to_json, headers: { "Link" => link_headers.join(", ") })
|
49
47
|
end
|
50
48
|
end
|
51
49
|
end
|
@@ -61,28 +59,28 @@ module GdsApi
|
|
61
59
|
)
|
62
60
|
end
|
63
61
|
|
64
|
-
def worldwide_api_has_location(location_slug, details=nil)
|
62
|
+
def worldwide_api_has_location(location_slug, details = nil)
|
65
63
|
details ||= world_location_for_slug(location_slug)
|
66
64
|
stub_request(:get, "#{WORLDWIDE_API_ENDPOINT}/api/world-locations/#{location_slug}").
|
67
|
-
to_return(:
|
65
|
+
to_return(status: 200, body: details.to_json)
|
68
66
|
end
|
69
67
|
|
70
68
|
def worldwide_api_does_not_have_location(location_slug)
|
71
|
-
stub_request(:get, "#{WORLDWIDE_API_ENDPOINT}/api/world-locations/#{location_slug}").to_return(:
|
69
|
+
stub_request(:get, "#{WORLDWIDE_API_ENDPOINT}/api/world-locations/#{location_slug}").to_return(status: 404)
|
72
70
|
end
|
73
71
|
|
74
72
|
def worldwide_api_has_organisations_for_location(location_slug, json_or_hash)
|
75
73
|
json = json_or_hash.is_a?(Hash) ? json_or_hash.to_json : json_or_hash
|
76
74
|
url = "#{WORLDWIDE_API_ENDPOINT}/api/world-locations/#{location_slug}/organisations"
|
77
75
|
stub_request(:get, url).
|
78
|
-
to_return(:
|
76
|
+
to_return(status: 200, body: json, headers: { "Link" => "<#{url}; rel\"self\"" })
|
79
77
|
end
|
80
78
|
|
81
79
|
def worldwide_api_has_no_organisations_for_location(location_slug)
|
82
|
-
details = {"results" => [], "total" => 0, "_response_info" => { "status" => "ok" } }
|
80
|
+
details = { "results" => [], "total" => 0, "_response_info" => { "status" => "ok" } }
|
83
81
|
url = "#{WORLDWIDE_API_ENDPOINT}/api/world-locations/#{location_slug}/organisations"
|
84
82
|
stub_request(:get, url).
|
85
|
-
to_return(:
|
83
|
+
to_return(status: 200, body: details.to_json, headers: { "Link" => "<#{url}; rel\"self\"" })
|
86
84
|
end
|
87
85
|
|
88
86
|
def world_location_for_slug(slug)
|
@@ -96,7 +94,7 @@ module GdsApi
|
|
96
94
|
def world_location_details_for_slug(slug)
|
97
95
|
{
|
98
96
|
"id" => "https://www.gov.uk/api/world-locations/#{slug}",
|
99
|
-
"title" => titleize_slug(slug, :
|
97
|
+
"title" => titleize_slug(slug, title_case: true),
|
100
98
|
"format" => (slug =~ /(delegation|mission)/ ? "International delegation" : "World location"),
|
101
99
|
"updated_at" => "2013-03-25T13:06:42+00:00",
|
102
100
|
"web_url" => "https://www.gov.uk/government/world/#{slug}",
|
@@ -110,7 +108,6 @@ module GdsApi
|
|
110
108
|
},
|
111
109
|
}
|
112
110
|
end
|
113
|
-
|
114
111
|
end
|
115
112
|
end
|
116
113
|
end
|
data/lib/gds_api/version.rb
CHANGED
data/lib/gds_api/worldwide.rb
CHANGED
@@ -1,20 +1,20 @@
|
|
1
1
|
require_relative 'base'
|
2
2
|
|
3
3
|
class GdsApi::Worldwide < GdsApi::Base
|
4
|
-
|
5
4
|
def world_locations
|
6
|
-
get_list
|
5
|
+
get_list("#{base_url}/world-locations")
|
7
6
|
end
|
8
7
|
|
9
8
|
def world_location(location_slug)
|
10
|
-
get_json
|
9
|
+
get_json("#{base_url}/world-locations/#{location_slug}")
|
11
10
|
end
|
12
11
|
|
13
12
|
def organisations_for_world_location(location_slug)
|
14
|
-
get_list
|
13
|
+
get_list("#{base_url}/world-locations/#{location_slug}/organisations")
|
15
14
|
end
|
16
15
|
|
17
16
|
private
|
17
|
+
|
18
18
|
def base_url
|
19
19
|
"#{endpoint}/api"
|
20
20
|
end
|
data/test/asset_manager_test.rb
CHANGED
@@ -24,10 +24,10 @@ describe GdsApi::AssetManager do
|
|
24
24
|
|
25
25
|
it "creates an asset with a file" do
|
26
26
|
req = stub_request(:post, "#{base_api_url}/assets").
|
27
|
-
with(:
|
28
|
-
to_return(:
|
27
|
+
with(body: %r{Content\-Disposition: form\-data; name="asset\[file\]"; filename="hello\.txt"\r\nContent\-Type: text/plain}).
|
28
|
+
to_return(body: JSON.dump(asset_manager_response), status: 201)
|
29
29
|
|
30
|
-
response = api.create_asset(:
|
30
|
+
response = api.create_asset(file: file_fixture)
|
31
31
|
|
32
32
|
assert_equal asset_url, response['asset']['id']
|
33
33
|
assert_requested(req)
|
@@ -55,9 +55,9 @@ describe GdsApi::AssetManager do
|
|
55
55
|
|
56
56
|
it "updates an asset with a file" do
|
57
57
|
req = stub_request(:put, "#{base_api_url}/assets/test-id").
|
58
|
-
to_return(:
|
58
|
+
to_return(body: JSON.dump(asset_manager_response), status: 200)
|
59
59
|
|
60
|
-
response = api.update_asset(asset_id, :
|
60
|
+
response = api.update_asset(asset_id, file: file_fixture)
|
61
61
|
|
62
62
|
assert_equal "#{base_api_url}/assets/#{asset_id}", response['asset']['id']
|
63
63
|
assert_requested(req)
|
@@ -74,7 +74,7 @@ describe GdsApi::AssetManager do
|
|
74
74
|
|
75
75
|
it "deletes an asset for the given id" do
|
76
76
|
req = stub_request(:delete, "#{base_api_url}/assets/#{asset_id}").
|
77
|
-
to_return(:
|
77
|
+
to_return(body: JSON.dump(asset_manager_response), status: 200)
|
78
78
|
|
79
79
|
response = api.delete_asset(asset_id)
|
80
80
|
|