gds-api-adapters 36.2.0 → 36.3.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 +4 -4
- data/lib/gds_api/publishing_api_v2.rb +14 -14
- data/lib/gds_api/support_api.rb +20 -0
- data/lib/gds_api/test_helpers/publishing_api_v2.rb +81 -0
- data/lib/gds_api/test_helpers/support_api.rb +10 -0
- data/lib/gds_api/version.rb +1 -1
- data/test/support_api_test.rb +11 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5e72a0c3c2f618e36bc65ed7b87b351f68d0a17a
|
4
|
+
data.tar.gz: b4dfb7f533bcf6d466831f1e1f64ee253a2a8a56
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d54634fa0f200ec449f86fad339489078912a81ef83ae5cf575fafb9f92f097cc3d991d5ce46db537078b0a43f7f387bf7688a8504c4b93dccbb41be817c263
|
7
|
+
data.tar.gz: 7f8ce9ff731ef650cc487df2dbfecfb7cfe8fc954ae20a16b08ac2c4ee38197a8be70dae84192ed47bd5bb5e84fbe755e07a9eadd89f2065d9cebb4bba763ba6
|
@@ -4,14 +4,14 @@ require_relative 'base'
|
|
4
4
|
#
|
5
5
|
# @see https://github.com/alphagov/publishing-api
|
6
6
|
# @see https://github.com/alphagov/publishing-api/blob/master/doc/publishing-application-examples.md
|
7
|
-
# @see https://github.com/alphagov/publishing-api/blob/master/doc/
|
7
|
+
# @see https://github.com/alphagov/publishing-api/blob/master/doc/model.md
|
8
8
|
class GdsApi::PublishingApiV2 < GdsApi::Base
|
9
9
|
# Put a content item
|
10
10
|
#
|
11
11
|
# @param content_id [UUID]
|
12
12
|
# @param payload [Hash] A valid content item
|
13
13
|
#
|
14
|
-
# @see https://github.com/alphagov/publishing-api/blob/master/doc/
|
14
|
+
# @see https://github.com/alphagov/publishing-api/blob/master/doc/api.md#put-v2contentcontent_id
|
15
15
|
def put_content(content_id, payload)
|
16
16
|
put_json!(content_url(content_id), payload)
|
17
17
|
end
|
@@ -25,7 +25,7 @@ class GdsApi::PublishingApiV2 < GdsApi::Base
|
|
25
25
|
# @option params [String] locale The language, defaults to 'en' in publishing-api.
|
26
26
|
#
|
27
27
|
# @return [GdsApi::Response] a content item
|
28
|
-
# @see https://github.com/alphagov/publishing-api/blob/master/doc/
|
28
|
+
# @see https://github.com/alphagov/publishing-api/blob/master/doc/api.md#get-v2contentcontent_id
|
29
29
|
def get_content(content_id, params = {})
|
30
30
|
get_json(content_url(content_id, params))
|
31
31
|
end
|
@@ -41,7 +41,7 @@ class GdsApi::PublishingApiV2 < GdsApi::Base
|
|
41
41
|
# @return [GdsApi::Response] a content item
|
42
42
|
#
|
43
43
|
# @raise [HTTPNotFound] when the content item is not found
|
44
|
-
# @see https://github.com/alphagov/publishing-api/blob/master/doc/
|
44
|
+
# @see https://github.com/alphagov/publishing-api/blob/master/doc/api.md#get-v2contentcontent_id
|
45
45
|
def get_content!(content_id, params = {})
|
46
46
|
get_json!(content_url(content_id, params))
|
47
47
|
end
|
@@ -55,7 +55,7 @@ class GdsApi::PublishingApiV2 < GdsApi::Base
|
|
55
55
|
# publishing_api.lookup_content_ids(base_paths: ['/foo', '/bar'])
|
56
56
|
# # => { "/foo" => "51ac4247-fd92-470a-a207-6b852a97f2db", "/bar" => "261bd281-f16c-48d5-82d2-9544019ad9ca" }
|
57
57
|
#
|
58
|
-
# @see https://github.com/alphagov/publishing-api/blob/master/doc/
|
58
|
+
# @see https://github.com/alphagov/publishing-api/blob/master/doc/api.md#post-lookup-by-base-path
|
59
59
|
def lookup_content_ids(base_paths:)
|
60
60
|
response = post_json!("#{endpoint}/lookup-by-base-path", base_paths: base_paths)
|
61
61
|
response.to_hash
|
@@ -75,7 +75,7 @@ class GdsApi::PublishingApiV2 < GdsApi::Base
|
|
75
75
|
# publishing_api.lookup_content_id(base_path: '/foo')
|
76
76
|
# # => "51ac4247-fd92-470a-a207-6b852a97f2db"
|
77
77
|
#
|
78
|
-
# @see https://github.com/alphagov/publishing-api/blob/master/doc/
|
78
|
+
# @see https://github.com/alphagov/publishing-api/blob/master/doc/api.md#post-lookup-by-base-path
|
79
79
|
def lookup_content_id(base_path:)
|
80
80
|
lookups = lookup_content_ids(base_paths: [base_path])
|
81
81
|
lookups[base_path]
|
@@ -91,7 +91,7 @@ class GdsApi::PublishingApiV2 < GdsApi::Base
|
|
91
91
|
# @param params [Hash]
|
92
92
|
# @option params [String] locale The language, defaults to 'en' in publishing-api.
|
93
93
|
#
|
94
|
-
# @see https://github.com/alphagov/publishing-api/blob/master/doc/
|
94
|
+
# @see https://github.com/alphagov/publishing-api/blob/master/doc/api.md#post-v2contentcontent_idpublish
|
95
95
|
def publish(content_id, update_type, options = {})
|
96
96
|
params = {
|
97
97
|
update_type: update_type
|
@@ -120,7 +120,7 @@ class GdsApi::PublishingApiV2 < GdsApi::Base
|
|
120
120
|
# @param previous_version [Integer] (optional) A lock version number for optimistic locking.
|
121
121
|
# @param locale [String] (optional) The content item locale.
|
122
122
|
#
|
123
|
-
# @see https://github.com/alphagov/publishing-api/blob/master/doc/
|
123
|
+
# @see https://github.com/alphagov/publishing-api/blob/master/doc/api.md#post-v2contentcontent_idunpublish
|
124
124
|
def unpublish(content_id, type:, explanation: nil, alternative_path: nil, discard_drafts: false, allow_draft: false, previous_version: nil, locale: nil)
|
125
125
|
params = {
|
126
126
|
type: type
|
@@ -144,7 +144,7 @@ class GdsApi::PublishingApiV2 < GdsApi::Base
|
|
144
144
|
# @option params [String] locale The language, defaults to 'en' in publishing-api.
|
145
145
|
# @option params [Integer] previous_version used to ensure the request is discarding the latest lock version of the draft
|
146
146
|
#
|
147
|
-
# @see https://github.com/alphagov/publishing-api/blob/master/doc/
|
147
|
+
# @see https://github.com/alphagov/publishing-api/blob/master/doc/api.md#post-v2contentcontent_iddiscard-draft
|
148
148
|
def discard_draft(content_id, options = {})
|
149
149
|
optional_keys = [
|
150
150
|
:locale,
|
@@ -204,7 +204,7 @@ class GdsApi::PublishingApiV2 < GdsApi::Base
|
|
204
204
|
# }
|
205
205
|
# }
|
206
206
|
#
|
207
|
-
# @see https://github.com/alphagov/publishing-api/blob/master/doc/
|
207
|
+
# @see https://github.com/alphagov/publishing-api/blob/master/doc/api.md#get-v2expanded-linkscontent_id
|
208
208
|
def get_expanded_links(content_id)
|
209
209
|
validate_content_id(content_id)
|
210
210
|
url = "#{endpoint}/v2/expanded-links/#{content_id}"
|
@@ -230,7 +230,7 @@ class GdsApi::PublishingApiV2 < GdsApi::Base
|
|
230
230
|
# bulk_publishing: true
|
231
231
|
# )
|
232
232
|
#
|
233
|
-
# @see https://github.com/alphagov/publishing-api/blob/master/doc/
|
233
|
+
# @see https://github.com/alphagov/publishing-api/blob/master/doc/api.md#patch-v2linkscontent_id
|
234
234
|
def patch_links(content_id, params)
|
235
235
|
payload = {
|
236
236
|
links: params.fetch(:links)
|
@@ -243,7 +243,7 @@ class GdsApi::PublishingApiV2 < GdsApi::Base
|
|
243
243
|
|
244
244
|
# FIXME: Add documentation
|
245
245
|
#
|
246
|
-
# @see https://github.com/alphagov/publishing-api/blob/master/doc/
|
246
|
+
# @see https://github.com/alphagov/publishing-api/blob/master/doc/api.md#get-v2content
|
247
247
|
def get_content_items(params)
|
248
248
|
query = query_string(params)
|
249
249
|
get_json("#{endpoint}/v2/content#{query}")
|
@@ -251,7 +251,7 @@ class GdsApi::PublishingApiV2 < GdsApi::Base
|
|
251
251
|
|
252
252
|
# FIXME: Add documentation
|
253
253
|
#
|
254
|
-
# @see https://github.com/alphagov/publishing-api/blob/master/doc/
|
254
|
+
# @see https://github.com/alphagov/publishing-api/blob/master/doc/api.md#get-v2linkables
|
255
255
|
def get_linkables(document_type: nil, format: nil)
|
256
256
|
if document_type.nil?
|
257
257
|
if format.nil?
|
@@ -270,7 +270,7 @@ class GdsApi::PublishingApiV2 < GdsApi::Base
|
|
270
270
|
|
271
271
|
# FIXME: Add documentation
|
272
272
|
#
|
273
|
-
# @see https://github.com/alphagov/publishing-api/blob/master/doc/
|
273
|
+
# @see https://github.com/alphagov/publishing-api/blob/master/doc/api.md#get-v2linkedcontent_id
|
274
274
|
def get_linked_items(content_id, params = {})
|
275
275
|
query = query_string(params)
|
276
276
|
validate_content_id(content_id)
|
data/lib/gds_api/support_api.rb
CHANGED
@@ -21,6 +21,26 @@ class GdsApi::SupportApi < GdsApi::Base
|
|
21
21
|
post_json!("#{endpoint}/anonymous-feedback/global-export-requests", global_export_request: request_details)
|
22
22
|
end
|
23
23
|
|
24
|
+
# Create a Page Improvement
|
25
|
+
#
|
26
|
+
# Makes a +POST+ request to the support api to create a Page Improvement.
|
27
|
+
#
|
28
|
+
# @param params [Hash] Any attributes that relate to a Page Improvement.
|
29
|
+
#
|
30
|
+
# @return [GdsApi::Response] The wrapped http response from the api. Responds to the following:
|
31
|
+
# :status a string that is either 'success' or 'error'
|
32
|
+
#
|
33
|
+
# @raise [HTTPErrorResponse] if the request returns an error
|
34
|
+
#
|
35
|
+
# @example
|
36
|
+
# support_api.create_page_improvement(
|
37
|
+
# description: 'The title is wrong',
|
38
|
+
# path: 'http://gov.uk/service-manual/agile'
|
39
|
+
# )
|
40
|
+
def create_page_improvement(params)
|
41
|
+
post_json!("#{endpoint}/page-improvements", params)
|
42
|
+
end
|
43
|
+
|
24
44
|
def problem_report_daily_totals_for(date)
|
25
45
|
date_string = date.strftime("%Y-%m-%d")
|
26
46
|
get_json!("#{endpoint}/anonymous-feedback/problem-reports/#{date_string}/totals")
|
@@ -235,12 +235,93 @@ module GdsApi
|
|
235
235
|
stub_request(:get, url).to_return(status: 404, body: resource_not_found(content_id, "content item").to_json, headers: {})
|
236
236
|
end
|
237
237
|
|
238
|
+
# Stubs a request to links endpoint
|
239
|
+
#
|
240
|
+
# @param [Hash] links the structure of the links hash
|
241
|
+
#
|
242
|
+
# @example
|
243
|
+
#
|
244
|
+
# publishing_api_has_links(
|
245
|
+
# {
|
246
|
+
# "content_id" => "64aadc14-9bca-40d9-abb6-4f21f9792a05",
|
247
|
+
# "links" => {
|
248
|
+
# "mainstream_browse_pages" => ["df2e7a3e-2078-45de-a75a-fd37d027427e"],
|
249
|
+
# "parent" => ["df2e7a3e-2078-45de-a75a-fd37d027427e"],
|
250
|
+
# "organisations" => ["569a9ee5-c195-4b7f-b9dc-edc17a09113f", "5c54ae52-341b-499e-a6dd-67f04633b8cf"]
|
251
|
+
# },
|
252
|
+
# "version" => 6
|
253
|
+
# }
|
254
|
+
# )
|
255
|
+
#
|
256
|
+
# Services.publishing_api.get_links("64aadc14-9bca-40d9-abb6-4f21f9792a05")
|
257
|
+
# => {
|
258
|
+
# "content_id" => "64aadc14-9bca-40d9-abb6-4f21f9792a05",
|
259
|
+
# "links" => {
|
260
|
+
# "mainstream_browse_pages" => ["df2e7a3e-2078-45de-a75a-fd37d027427e"],
|
261
|
+
# "parent" => ["df2e7a3e-2078-45de-a75a-fd37d027427e"],
|
262
|
+
# "organisations" => ["569a9ee5-c195-4b7f-b9dc-edc17a09113f", "5c54ae52-341b-499e-a6dd-67f04633b8cf"]
|
263
|
+
# },
|
264
|
+
# "version" => 6
|
265
|
+
# }
|
238
266
|
def publishing_api_has_links(links)
|
239
267
|
links = links.with_indifferent_access
|
240
268
|
url = PUBLISHING_API_V2_ENDPOINT + "/links/" + links[:content_id]
|
241
269
|
stub_request(:get, url).to_return(status: 200, body: links.to_json, headers: {})
|
242
270
|
end
|
243
271
|
|
272
|
+
# Stubs a request to expanded links endpoint
|
273
|
+
#
|
274
|
+
# @param [Hash] links the structure of the links hash
|
275
|
+
#
|
276
|
+
# @example
|
277
|
+
# publishing_api_has_expanded_links(
|
278
|
+
# {
|
279
|
+
# "content_id" => "64aadc14-9bca-40d9-abb4-4f21f9792a05",
|
280
|
+
# "expanded_links" => {
|
281
|
+
# "mainstream_browse_pages" => [
|
282
|
+
# {
|
283
|
+
# "content_id" => "df2e7a3e-2078-45de-a76a-fd37d027427a",
|
284
|
+
# "base_path" => "/a/base/path",
|
285
|
+
# "document_type" => "mainstream_browse_page",
|
286
|
+
# "locale" => "en",
|
287
|
+
# "links" => {},
|
288
|
+
# ...
|
289
|
+
# }
|
290
|
+
# ],
|
291
|
+
# "parent" => [
|
292
|
+
# {
|
293
|
+
# "content_id" => "df2e7a3e-2028-45de-a75a-fd37d027427e",
|
294
|
+
# "document_type" => "mainstream_browse_page",
|
295
|
+
# ...
|
296
|
+
# },
|
297
|
+
# ]
|
298
|
+
# }
|
299
|
+
# }
|
300
|
+
# )
|
301
|
+
#
|
302
|
+
# Services.publishing_api.expanded_links("64aadc14-9bca-40d9-abb4-4f21f9792a05")
|
303
|
+
# => {
|
304
|
+
# "content_id" => "64aadc14-9bca-40d9-abb4-4f21f9792a05",
|
305
|
+
# "expanded_links" => {
|
306
|
+
# "mainstream_browse_pages" => [
|
307
|
+
# {
|
308
|
+
# "content_id" => "df2e7a3e-2078-45de-a76a-fd37d027427a",
|
309
|
+
# "base_path" => "/a/base/path",
|
310
|
+
# "document_type" => "mainstream_browse_page",
|
311
|
+
# "locale" => "en",
|
312
|
+
# "links" => {},
|
313
|
+
# ...
|
314
|
+
# }
|
315
|
+
# ],
|
316
|
+
# "parent" => [
|
317
|
+
# {
|
318
|
+
# "content_id" => "df2e7a3e-2028-45de-a75a-fd37d027427e",
|
319
|
+
# "document_type" => "mainstream_browse_page",
|
320
|
+
# ...
|
321
|
+
# },
|
322
|
+
# ]
|
323
|
+
# }
|
324
|
+
# }
|
244
325
|
def publishing_api_has_expanded_links(links)
|
245
326
|
url = PUBLISHING_API_V2_ENDPOINT + "/expanded-links/" + links[:content_id]
|
246
327
|
stub_request(:get, url).to_return(status: 200, body: links.to_json, headers: {})
|
@@ -36,6 +36,12 @@ module GdsApi
|
|
36
36
|
post_stub.to_return(:status => 202)
|
37
37
|
end
|
38
38
|
|
39
|
+
def stub_create_page_improvement(params)
|
40
|
+
post_stub = stub_http_request(:post, "#{SUPPORT_API_ENDPOINT}/page-improvements")
|
41
|
+
post_stub.with(:body => params)
|
42
|
+
post_stub.to_return(:status => 201)
|
43
|
+
end
|
44
|
+
|
39
45
|
def stub_problem_report_daily_totals_for(date, expected_results = nil)
|
40
46
|
date_string = date.strftime("%Y-%m-%d")
|
41
47
|
get_stub = stub_http_request(:get, "#{SUPPORT_API_ENDPOINT}/anonymous-feedback/problem-reports/#{date_string}/totals")
|
@@ -108,6 +114,10 @@ module GdsApi
|
|
108
114
|
stub_http_request(:get, "#{SUPPORT_API_ENDPOINT}/anonymous-feedback/export-requests/#{id}").
|
109
115
|
to_return(status: 200, body: response_body.to_json)
|
110
116
|
end
|
117
|
+
|
118
|
+
def stub_any_support_api_call
|
119
|
+
stub_request(:any, %r{\A#{SUPPORT_API_ENDPOINT}})
|
120
|
+
end
|
111
121
|
end
|
112
122
|
end
|
113
123
|
end
|
data/lib/gds_api/version.rb
CHANGED
data/test/support_api_test.rb
CHANGED
@@ -123,6 +123,17 @@ describe GdsApi::SupportApi do
|
|
123
123
|
end
|
124
124
|
end
|
125
125
|
|
126
|
+
describe "POST /page-improvements" do
|
127
|
+
it "makes a POST request to the support API" do
|
128
|
+
params = {description: "The title could be better."}
|
129
|
+
stub_post = stub_create_page_improvement(params)
|
130
|
+
|
131
|
+
@api.create_page_improvement(params)
|
132
|
+
|
133
|
+
assert_requested(stub_post)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
126
137
|
describe "GET /anonymous-feedback/export-requests/:id" do
|
127
138
|
it "fetches the export request details from the API" do
|
128
139
|
stub_get = stub_support_feedback_export_request(123)
|
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.
|
4
|
+
version: 36.3.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-
|
11
|
+
date: 2016-09-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: plek
|