gds-api-adapters 79.1.1 → 80.0.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/locations_api.rb +2 -2
- data/lib/gds_api/publishing_api.rb +21 -38
- data/lib/gds_api/test_helpers/locations_api.rb +3 -3
- data/lib/gds_api/version.rb +1 -1
- data/lib/gds_api.rb +7 -7
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1f6921e5174a36bd20b7d8f6a446d4764778acac96e707108ed4fd581d8261e8
|
4
|
+
data.tar.gz: 00b4f87f11ee027458c97f21216c43ba42ad371faedbc1ce4e3cb5d886b32126
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 62c4ee4274480082f184e019de3307961b94b2e14840a5e7a9ddf82c1521bc35e66586414bf6a5465e1e06c0c3213194945c84ad48ea0801f8f5e430bb8b2280
|
7
|
+
data.tar.gz: 26baf319e1e5a0072692b570330bb0bb44fbf17d9f2fb43765f39ae9307ecb7c0ca25da823d30e960f5100362d645d47fce8e3717a4667f3533e4dd9615b3748
|
@@ -8,7 +8,7 @@ class GdsApi::LocationsApi < GdsApi::Base
|
|
8
8
|
#
|
9
9
|
# @return [Array] All local custodian codes for a specific postcode
|
10
10
|
def local_custodian_code_for_postcode(postcode)
|
11
|
-
response = get_json("#{endpoint}/locations?postcode=#{postcode}
|
11
|
+
response = get_json("#{endpoint}/v1/locations?postcode=#{postcode}")
|
12
12
|
|
13
13
|
return [] if response["results"].nil?
|
14
14
|
|
@@ -21,7 +21,7 @@ class GdsApi::LocationsApi < GdsApi::Base
|
|
21
21
|
#
|
22
22
|
# @return [Hash] The average coordinates (two fields, "latitude" and "longitude") for a specific postcode
|
23
23
|
def coordinates_for_postcode(postcode)
|
24
|
-
response = get_json("#{endpoint}/locations?postcode=#{postcode}
|
24
|
+
response = get_json("#{endpoint}/v1/locations?postcode=#{postcode}")
|
25
25
|
|
26
26
|
{ "latitude" => response["average_latitude"], "longitude" => response["average_longitude"] } unless response["results"].nil?
|
27
27
|
end
|
@@ -4,8 +4,8 @@ require_relative "exceptions"
|
|
4
4
|
# Adapter for the Publishing API.
|
5
5
|
#
|
6
6
|
# @see https://github.com/alphagov/publishing-api
|
7
|
-
# @see https://github.com/alphagov/publishing-api/blob/
|
8
|
-
# @see https://github.com/alphagov/publishing-api/blob/
|
7
|
+
# @see https://github.com/alphagov/publishing-api/blob/main/docs/publishing-application-examples.md
|
8
|
+
# @see https://github.com/alphagov/publishing-api/blob/main/docs/model.md
|
9
9
|
# @api documented
|
10
10
|
class GdsApi::PublishingApi < GdsApi::Base
|
11
11
|
class NoLiveVersion < GdsApi::BaseError; end
|
@@ -15,7 +15,7 @@ class GdsApi::PublishingApi < GdsApi::Base
|
|
15
15
|
# @param content_id [UUID]
|
16
16
|
# @param payload [Hash] A valid content item
|
17
17
|
#
|
18
|
-
# @see https://github.com/alphagov/publishing-api/blob/
|
18
|
+
# @see https://github.com/alphagov/publishing-api/blob/main/docs/api.md#put-v2contentcontent_id
|
19
19
|
def put_content(content_id, payload)
|
20
20
|
put_json(content_url(content_id), payload)
|
21
21
|
end
|
@@ -31,7 +31,7 @@ class GdsApi::PublishingApi < GdsApi::Base
|
|
31
31
|
# @return [GdsApi::Response] a content item
|
32
32
|
#
|
33
33
|
# @raise [HTTPNotFound] when the content item is not found
|
34
|
-
# @see https://github.com/alphagov/publishing-api/blob/
|
34
|
+
# @see https://github.com/alphagov/publishing-api/blob/main/docs/api.md#get-v2contentcontent_id
|
35
35
|
def get_content(content_id, params = {})
|
36
36
|
get_json(content_url(content_id, params))
|
37
37
|
end
|
@@ -46,7 +46,7 @@ class GdsApi::PublishingApi < GdsApi::Base
|
|
46
46
|
# @return [GdsApi::Response] a content item
|
47
47
|
#
|
48
48
|
# @raise [NoLiveVersion] when the content item is not found
|
49
|
-
# @see https://github.com/alphagov/publishing-api/blob/
|
49
|
+
# @see https://github.com/alphagov/publishing-api/blob/main/docs/api.md#get-v2contentcontent_id
|
50
50
|
def get_live_content(content_id, locale = "en")
|
51
51
|
content_item = get_content(content_id, locale: locale)
|
52
52
|
|
@@ -71,7 +71,7 @@ class GdsApi::PublishingApi < GdsApi::Base
|
|
71
71
|
# publishing_api.lookup_content_ids(base_paths: ['/foo', '/bar'])
|
72
72
|
# # => { "/foo" => "51ac4247-fd92-470a-a207-6b852a97f2db", "/bar" => "261bd281-f16c-48d5-82d2-9544019ad9ca" }
|
73
73
|
#
|
74
|
-
# @see https://github.com/alphagov/publishing-api/blob/
|
74
|
+
# @see https://github.com/alphagov/publishing-api/blob/main/docs/api.md#post-lookup-by-base-path
|
75
75
|
def lookup_content_ids(base_paths:, exclude_document_types: nil, exclude_unpublishing_types: nil, with_drafts: false)
|
76
76
|
options = { base_paths: base_paths }
|
77
77
|
options[:exclude_document_types] = exclude_document_types if exclude_document_types
|
@@ -98,7 +98,7 @@ class GdsApi::PublishingApi < GdsApi::Base
|
|
98
98
|
# publishing_api.lookup_content_id(base_path: '/foo')
|
99
99
|
# # => "51ac4247-fd92-470a-a207-6b852a97f2db"
|
100
100
|
#
|
101
|
-
# @see https://github.com/alphagov/publishing-api/blob/
|
101
|
+
# @see https://github.com/alphagov/publishing-api/blob/main/docs/api.md#post-lookup-by-base-path
|
102
102
|
def lookup_content_id(base_path:, exclude_document_types: nil, exclude_unpublishing_types: nil, with_drafts: false)
|
103
103
|
lookups = lookup_content_ids(
|
104
104
|
base_paths: [base_path],
|
@@ -119,7 +119,7 @@ class GdsApi::PublishingApi < GdsApi::Base
|
|
119
119
|
# @param options [Hash]
|
120
120
|
# @option options [String] locale The language, defaults to 'en' in publishing-api.
|
121
121
|
#
|
122
|
-
# @see https://github.com/alphagov/publishing-api/blob/
|
122
|
+
# @see https://github.com/alphagov/publishing-api/blob/main/docs/api.md#post-v2contentcontent_idpublish
|
123
123
|
def publish(content_id, update_type = nil, options = {})
|
124
124
|
params = {
|
125
125
|
update_type: update_type,
|
@@ -150,23 +150,6 @@ class GdsApi::PublishingApi < GdsApi::Base
|
|
150
150
|
post_json(republish_url(content_id), params)
|
151
151
|
end
|
152
152
|
|
153
|
-
# Import content into the publishing API
|
154
|
-
#
|
155
|
-
# The publishing-api will delete any content which has the content
|
156
|
-
# id provided, and then import the data given.
|
157
|
-
#
|
158
|
-
# @param content_id [UUID]
|
159
|
-
# @param content_items [Array]
|
160
|
-
#
|
161
|
-
# @see https://github.com/alphagov/publishing-api/blob/master/doc/api.md#post-v2contentcontent_idimport
|
162
|
-
def import(content_id, locale, content_items)
|
163
|
-
params = {
|
164
|
-
history: content_items,
|
165
|
-
}
|
166
|
-
|
167
|
-
post_json("#{endpoint}/v2/content/#{content_id}/import?locale=#{locale}", params)
|
168
|
-
end
|
169
|
-
|
170
153
|
# Unpublish a content item
|
171
154
|
#
|
172
155
|
# The publishing API will "unpublish" a live item, to remove it from the public
|
@@ -182,7 +165,7 @@ class GdsApi::PublishingApi < GdsApi::Base
|
|
182
165
|
# @param unpublished_at [Time] (optional) The time the content was withdrawn. Ignored for types other than withdrawn
|
183
166
|
# @param redirects [Array] (optional) Required if no alternative_path is given. An array of redirect values, ie: { path:, type:, destination: }
|
184
167
|
#
|
185
|
-
# @see https://github.com/alphagov/publishing-api/blob/
|
168
|
+
# @see https://github.com/alphagov/publishing-api/blob/main/docs/api.md#post-v2contentcontent_idunpublish
|
186
169
|
def unpublish(content_id, type:, explanation: nil, alternative_path: nil, discard_drafts: false, allow_draft: false, previous_version: nil, locale: nil, unpublished_at: nil, redirects: nil)
|
187
170
|
params = {
|
188
171
|
type: type,
|
@@ -208,7 +191,7 @@ class GdsApi::PublishingApi < GdsApi::Base
|
|
208
191
|
# @option options [String] locale The language, defaults to 'en' in publishing-api.
|
209
192
|
# @option options [Integer] previous_version used to ensure the request is discarding the latest lock version of the draft
|
210
193
|
#
|
211
|
-
# @see https://github.com/alphagov/publishing-api/blob/
|
194
|
+
# @see https://github.com/alphagov/publishing-api/blob/main/docs/api.md#post-v2contentcontent_iddiscard-draft
|
212
195
|
def discard_draft(content_id, options = {})
|
213
196
|
optional_keys = %i[locale previous_version]
|
214
197
|
|
@@ -237,7 +220,7 @@ class GdsApi::PublishingApi < GdsApi::Base
|
|
237
220
|
# "version" => 17
|
238
221
|
# }
|
239
222
|
#
|
240
|
-
# @see https://github.com/alphagov/publishing-api/blob/
|
223
|
+
# @see https://github.com/alphagov/publishing-api/blob/main/docs/api.md#get-v2linkscontent_id
|
241
224
|
def get_links(content_id)
|
242
225
|
get_json(links_url(content_id))
|
243
226
|
end
|
@@ -288,7 +271,7 @@ class GdsApi::PublishingApi < GdsApi::Base
|
|
288
271
|
# }
|
289
272
|
# }
|
290
273
|
#
|
291
|
-
# @see https://github.com/alphagov/publishing-api/blob/
|
274
|
+
# @see https://github.com/alphagov/publishing-api/blob/main/docs/api.md#get-v2expanded-linkscontent_id
|
292
275
|
def get_expanded_links(content_id, locale: nil, with_drafts: true, generate: false)
|
293
276
|
params = {}
|
294
277
|
params[:with_drafts] = "false" unless with_drafts
|
@@ -318,7 +301,7 @@ class GdsApi::PublishingApi < GdsApi::Base
|
|
318
301
|
# bulk_publishing: true
|
319
302
|
# )
|
320
303
|
#
|
321
|
-
# @see https://github.com/alphagov/publishing-api/blob/
|
304
|
+
# @see https://github.com/alphagov/publishing-api/blob/main/docs/api.md#patch-v2linkscontent_id
|
322
305
|
def patch_links(content_id, params)
|
323
306
|
payload = {
|
324
307
|
links: params.fetch(:links),
|
@@ -348,7 +331,7 @@ class GdsApi::PublishingApi < GdsApi::Base
|
|
348
331
|
# order: '-public_updated_at'
|
349
332
|
# )
|
350
333
|
#
|
351
|
-
# @see https://github.com/alphagov/publishing-api/blob/
|
334
|
+
# @see https://github.com/alphagov/publishing-api/blob/main/docs/api.md#get-v2content
|
352
335
|
def get_content_items(params)
|
353
336
|
query = query_string(params)
|
354
337
|
get_json("#{endpoint}/v2/content#{query}")
|
@@ -361,7 +344,7 @@ class GdsApi::PublishingApi < GdsApi::Base
|
|
361
344
|
#
|
362
345
|
# @return [Enumerator] an enumerator of content items
|
363
346
|
#
|
364
|
-
# @see https://github.com/alphagov/publishing-api/blob/
|
347
|
+
# @see https://github.com/alphagov/publishing-api/blob/main/docs/api.md#get-v2content
|
365
348
|
def get_content_items_enum(params)
|
366
349
|
Enumerator.new do |yielder|
|
367
350
|
(1..Float::INFINITY).each do |index|
|
@@ -378,7 +361,7 @@ class GdsApi::PublishingApi < GdsApi::Base
|
|
378
361
|
|
379
362
|
# FIXME: Add documentation
|
380
363
|
#
|
381
|
-
# @see https://github.com/alphagov/publishing-api/blob/
|
364
|
+
# @see https://github.com/alphagov/publishing-api/blob/main/docs/api.md#get-v2linkables
|
382
365
|
def get_linkables(document_type: nil)
|
383
366
|
if document_type.nil?
|
384
367
|
raise ArgumentError, "Please provide a `document_type`"
|
@@ -389,7 +372,7 @@ class GdsApi::PublishingApi < GdsApi::Base
|
|
389
372
|
|
390
373
|
# FIXME: Add documentation
|
391
374
|
#
|
392
|
-
# @see https://github.com/alphagov/publishing-api/blob/
|
375
|
+
# @see https://github.com/alphagov/publishing-api/blob/main/docs/api.md#get-v2linkedcontent_id
|
393
376
|
def get_linked_items(content_id, params = {})
|
394
377
|
query = query_string(params)
|
395
378
|
validate_content_id(content_id)
|
@@ -403,7 +386,7 @@ class GdsApi::PublishingApi < GdsApi::Base
|
|
403
386
|
#
|
404
387
|
# @return [GdsApi::Response] a paginated list of editions
|
405
388
|
#
|
406
|
-
# @see https://github.com/alphagov/publishing-api/blob/
|
389
|
+
# @see https://github.com/alphagov/publishing-api/blob/main/docs/api.md#get-v2editions
|
407
390
|
def get_editions(params = {})
|
408
391
|
get_json(get_editions_url(params))
|
409
392
|
end
|
@@ -415,7 +398,7 @@ class GdsApi::PublishingApi < GdsApi::Base
|
|
415
398
|
#
|
416
399
|
# @return [Enumerator] an enumerator of editions responses
|
417
400
|
#
|
418
|
-
# @see https://github.com/alphagov/publishing-api/blob/
|
401
|
+
# @see https://github.com/alphagov/publishing-api/blob/main/docs/api.md#get-v2editions
|
419
402
|
def get_paged_editions(params = {})
|
420
403
|
Enumerator.new do |yielder|
|
421
404
|
next_link = get_editions_url(params)
|
@@ -488,7 +471,7 @@ class GdsApi::PublishingApi < GdsApi::Base
|
|
488
471
|
# }
|
489
472
|
# )
|
490
473
|
#
|
491
|
-
# @see https://github.com/alphagov/publishing-api/blob/
|
474
|
+
# @see https://github.com/alphagov/publishing-api/blob/main/docs/api.md#put-publish-intentbase_path
|
492
475
|
def put_intent(base_path, payload)
|
493
476
|
put_json(intent_url(base_path), payload)
|
494
477
|
end
|
@@ -497,7 +480,7 @@ class GdsApi::PublishingApi < GdsApi::Base
|
|
497
480
|
#
|
498
481
|
# @param base_path [String]
|
499
482
|
#
|
500
|
-
# @see https://github.com/alphagov/publishing-api/blob/
|
483
|
+
# @see https://github.com/alphagov/publishing-api/blob/main/docs/api.md#delete-publish-intentbase_path
|
501
484
|
def destroy_intent(base_path)
|
502
485
|
delete_json(intent_url(base_path))
|
503
486
|
rescue GdsApi::HTTPNotFound => e
|
@@ -20,17 +20,17 @@ module GdsApi
|
|
20
20
|
"results" => results,
|
21
21
|
}
|
22
22
|
|
23
|
-
stub_request(:get, "#{LOCATIONS_API_ENDPOINT}/locations?postcode=#{postcode}
|
23
|
+
stub_request(:get, "#{LOCATIONS_API_ENDPOINT}/v1/locations?postcode=#{postcode}")
|
24
24
|
.to_return(body: response.to_json, status: 200)
|
25
25
|
end
|
26
26
|
|
27
27
|
def stub_locations_api_has_no_location(postcode)
|
28
|
-
stub_request(:get, "#{LOCATIONS_API_ENDPOINT}/locations?postcode=#{postcode}
|
28
|
+
stub_request(:get, "#{LOCATIONS_API_ENDPOINT}/v1/locations?postcode=#{postcode}")
|
29
29
|
.to_return(body: { "results" => nil }.to_json, status: 200)
|
30
30
|
end
|
31
31
|
|
32
32
|
def stub_locations_api_does_not_have_a_bad_postcode(postcode)
|
33
|
-
stub_request(:get, "#{LOCATIONS_API_ENDPOINT}/locations?postcode=#{postcode}
|
33
|
+
stub_request(:get, "#{LOCATIONS_API_ENDPOINT}/v1/locations?postcode=#{postcode}")
|
34
34
|
.to_return(body: { "code" => 400, "error" => "Postcode '#{postcode}' is not valid." }.to_json, status: 400)
|
35
35
|
end
|
36
36
|
end
|
data/lib/gds_api/version.rb
CHANGED
data/lib/gds_api.rb
CHANGED
@@ -116,6 +116,13 @@ module GdsApi
|
|
116
116
|
GdsApi::LocalLinksManager.new(Plek.find("local-links-manager"), options)
|
117
117
|
end
|
118
118
|
|
119
|
+
# Creates a GdsApi::LocationsApi adapter
|
120
|
+
#
|
121
|
+
# @return [GdsApi::LocationsApi]
|
122
|
+
def self.locations_api(options = {})
|
123
|
+
GdsApi::LocationsApi.new(Plek.find("locations-api"), options)
|
124
|
+
end
|
125
|
+
|
119
126
|
# Creates a GdsApi::Mapit adapter
|
120
127
|
#
|
121
128
|
# @return [GdsApi::Mapit]
|
@@ -202,11 +209,4 @@ module GdsApi
|
|
202
209
|
def self.worldwide(options = {})
|
203
210
|
GdsApi::Worldwide.new(Plek.new.website_root, options)
|
204
211
|
end
|
205
|
-
|
206
|
-
# Creates a GdsApi::LocationsApi adapter
|
207
|
-
#
|
208
|
-
# @return [GdsApi::LocationsApi]
|
209
|
-
def self.locations_api(options = {})
|
210
|
-
GdsApi::LocationsApi.new(Plek.find("locations-api"), options)
|
211
|
-
end
|
212
212
|
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:
|
4
|
+
version: 80.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: 2022-
|
11
|
+
date: 2022-06-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|