gds-api-adapters 97.6.0 → 98.1.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/json_client.rb +2 -2
- data/lib/gds_api/publishing_api.rb +37 -0
- data/lib/gds_api/test_helpers/publishing_api.rb +13 -0
- data/lib/gds_api/version.rb +1 -1
- data/lib/gds_api.rb +0 -14
- metadata +3 -8
- data/lib/gds_api/router.rb +0 -62
- data/lib/gds_api/test_helpers/router.rb +0 -94
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b2b9f52394507921888ca9abe107c764de4af4da163dc2609f9909559f31e288
|
4
|
+
data.tar.gz: 94ff2e4bfb6f7a6b015e0049f82bc609cdbe416ee6355fdcc757b3d8d3177668
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b1cdf84bd90af029ea2c0ca24cc091cdc3b69b9c261ee6ec2632b4587e4c7db454fb56de499d0e499b110ac39567c013313f6ee6440368fe46dbf67f0ed07e74
|
7
|
+
data.tar.gz: 53ad365fffa3ac456e7e77412c986af8e6403dabb63c571a3327db5ac16fbcf573605d901c8ca29bf6cea9f1e9573320299c8e40050a0d7d9e4ea17ec2ca73b3
|
data/lib/gds_api/json_client.rb
CHANGED
@@ -52,8 +52,8 @@ module GdsApi
|
|
52
52
|
do_json_request(:get, url, nil, additional_headers, &create_response)
|
53
53
|
end
|
54
54
|
|
55
|
-
def post_json(url, params = {}, additional_headers = {})
|
56
|
-
do_json_request(:post, url, params, additional_headers)
|
55
|
+
def post_json(url, params = {}, additional_headers = {}, &create_response)
|
56
|
+
do_json_request(:post, url, params, additional_headers, &create_response)
|
57
57
|
end
|
58
58
|
|
59
59
|
def put_json(url, params, additional_headers = {})
|
@@ -378,6 +378,24 @@ class GdsApi::PublishingApi < GdsApi::Base
|
|
378
378
|
get_host_content_for_content_id(content_id, params)
|
379
379
|
end
|
380
380
|
|
381
|
+
# Get events for a specific content_id
|
382
|
+
#
|
383
|
+
# @param content_id [UUID]
|
384
|
+
# @param params [Hash]
|
385
|
+
#
|
386
|
+
# publishing_api.get_events_for_content_id(
|
387
|
+
# "7ac47b33-c09c-4c1d-a9a7-0cfef99081ac",
|
388
|
+
# { action: "PutContent", from: "2023-01-01T00:00:00Z", to: "2023-01-05T10:00:00Z" }
|
389
|
+
# )
|
390
|
+
#
|
391
|
+
# @return [GdsApi::Response] A response containing a list of events for that content ID
|
392
|
+
#
|
393
|
+
# @see https://github.com/alphagov/publishing-api/blob/main/docs/api.md#get-v2contentcontent_idevents
|
394
|
+
def get_events_for_content_id(content_id, params = {})
|
395
|
+
query = query_string(params)
|
396
|
+
get_json("#{endpoint}/v2/content/#{content_id}/events#{query}")
|
397
|
+
end
|
398
|
+
|
381
399
|
# Returns an Enumerator of content items for the provided
|
382
400
|
# query string parameters.
|
383
401
|
#
|
@@ -584,6 +602,25 @@ class GdsApi::PublishingApi < GdsApi::Base
|
|
584
602
|
post_json("#{endpoint}/graphql", query:)
|
585
603
|
end
|
586
604
|
|
605
|
+
# Make a GraphQL query and return the response in the same format as a Content Store content item
|
606
|
+
#
|
607
|
+
# @param query [String]
|
608
|
+
#
|
609
|
+
# @return [GdsApi::Response] A response with the result of the GraphQL query formatted like a Content Store content item.
|
610
|
+
def graphql_content_item(query)
|
611
|
+
create_response = proc do |r|
|
612
|
+
updated_body = JSON.parse(r.body).dig("data", "edition")
|
613
|
+
updated_response = RestClient::Response.create(
|
614
|
+
updated_body.to_json,
|
615
|
+
r.net_http_res,
|
616
|
+
r.request,
|
617
|
+
)
|
618
|
+
GdsApi::Response.new(updated_response)
|
619
|
+
end
|
620
|
+
|
621
|
+
post_json("#{endpoint}/graphql", query:, &create_response)
|
622
|
+
end
|
623
|
+
|
587
624
|
private
|
588
625
|
|
589
626
|
def content_url(content_id, params = {})
|
@@ -201,6 +201,19 @@ module GdsApi
|
|
201
201
|
stub_request(:post, url).with(body: { query: }).to_return(response)
|
202
202
|
end
|
203
203
|
|
204
|
+
# Stub a POST /graphql content item request
|
205
|
+
#
|
206
|
+
# @param query [String]
|
207
|
+
def stub_publishing_api_graphql_content_item(query, response_hash = {})
|
208
|
+
url = "#{PUBLISHING_API_ENDPOINT}/graphql"
|
209
|
+
response = {
|
210
|
+
status: 200,
|
211
|
+
body: response_hash.to_json,
|
212
|
+
headers: { "Content-Type" => "application/json; charset=utf-8" },
|
213
|
+
}
|
214
|
+
stub_request(:post, url).with(body: { query: }).to_return(response)
|
215
|
+
end
|
216
|
+
|
204
217
|
# Assert that a draft was saved and published, and links were updated.
|
205
218
|
# - PUT /v2/content/:content_id
|
206
219
|
# - POST /v2/content/:content_id/publish
|
data/lib/gds_api/version.rb
CHANGED
data/lib/gds_api.rb
CHANGED
@@ -14,7 +14,6 @@ require "gds_api/locations_api"
|
|
14
14
|
require "gds_api/maslow"
|
15
15
|
require "gds_api/organisations"
|
16
16
|
require "gds_api/publishing_api"
|
17
|
-
require "gds_api/router"
|
18
17
|
require "gds_api/search"
|
19
18
|
require "gds_api/search_api_v2"
|
20
19
|
require "gds_api/support"
|
@@ -155,19 +154,6 @@ module GdsApi
|
|
155
154
|
)
|
156
155
|
end
|
157
156
|
|
158
|
-
# Creates a GdsApi::Router adapter for communicating with Router API
|
159
|
-
#
|
160
|
-
# This will set a bearer token if a ROUTER_API_BEARER_TOKEN environment
|
161
|
-
# variable is set
|
162
|
-
#
|
163
|
-
# @return [GdsApi::Router]
|
164
|
-
def self.router(options = {})
|
165
|
-
GdsApi::Router.new(
|
166
|
-
Plek.find("router-api"),
|
167
|
-
{ bearer_token: ENV["ROUTER_API_BEARER_TOKEN"] }.merge(options),
|
168
|
-
)
|
169
|
-
end
|
170
|
-
|
171
157
|
# Creates a GdsApi::Search adapter to access via a search.* hostname
|
172
158
|
#
|
173
159
|
# @return [GdsApi::Search]
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gds-api-adapters
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 98.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GOV.UK Dev
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date: 2024-12-
|
10
|
+
date: 2024-12-18 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: addressable
|
@@ -351,7 +350,6 @@ files:
|
|
351
350
|
- lib/gds_api/publishing_api/special_route_publisher.rb
|
352
351
|
- lib/gds_api/railtie.rb
|
353
352
|
- lib/gds_api/response.rb
|
354
|
-
- lib/gds_api/router.rb
|
355
353
|
- lib/gds_api/search.rb
|
356
354
|
- lib/gds_api/search_api_v2.rb
|
357
355
|
- lib/gds_api/support.rb
|
@@ -371,7 +369,6 @@ files:
|
|
371
369
|
- lib/gds_api/test_helpers/organisations.rb
|
372
370
|
- lib/gds_api/test_helpers/places_manager.rb
|
373
371
|
- lib/gds_api/test_helpers/publishing_api.rb
|
374
|
-
- lib/gds_api/test_helpers/router.rb
|
375
372
|
- lib/gds_api/test_helpers/search.rb
|
376
373
|
- lib/gds_api/test_helpers/support_api.rb
|
377
374
|
- lib/gds_api/test_helpers/worldwide.rb
|
@@ -387,7 +384,6 @@ files:
|
|
387
384
|
homepage: http://github.com/alphagov/gds-api-adapters
|
388
385
|
licenses: []
|
389
386
|
metadata: {}
|
390
|
-
post_install_message:
|
391
387
|
rdoc_options: []
|
392
388
|
require_paths:
|
393
389
|
- lib
|
@@ -402,8 +398,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
402
398
|
- !ruby/object:Gem::Version
|
403
399
|
version: '0'
|
404
400
|
requirements: []
|
405
|
-
rubygems_version: 3.
|
406
|
-
signing_key:
|
401
|
+
rubygems_version: 3.6.1
|
407
402
|
specification_version: 4
|
408
403
|
summary: Adapters to work with GDS APIs
|
409
404
|
test_files: []
|
data/lib/gds_api/router.rb
DELETED
@@ -1,62 +0,0 @@
|
|
1
|
-
require_relative "base"
|
2
|
-
|
3
|
-
class GdsApi::Router < GdsApi::Base
|
4
|
-
### Backends
|
5
|
-
|
6
|
-
def get_backend(id)
|
7
|
-
get_json("#{endpoint}/backends/#{CGI.escape(id)}")
|
8
|
-
end
|
9
|
-
|
10
|
-
def add_backend(id, url)
|
11
|
-
put_json("#{endpoint}/backends/#{CGI.escape(id)}", backend: { backend_url: url })
|
12
|
-
end
|
13
|
-
|
14
|
-
def delete_backend(id)
|
15
|
-
delete_json("#{endpoint}/backends/#{CGI.escape(id)}")
|
16
|
-
end
|
17
|
-
|
18
|
-
### Routes
|
19
|
-
|
20
|
-
def get_route(path)
|
21
|
-
get_json("#{endpoint}/routes?incoming_path=#{CGI.escape(path)}")
|
22
|
-
end
|
23
|
-
|
24
|
-
def add_route(path, type, backend_id)
|
25
|
-
put_json(
|
26
|
-
"#{endpoint}/routes",
|
27
|
-
route: {
|
28
|
-
incoming_path: path,
|
29
|
-
route_type: type,
|
30
|
-
handler: "backend",
|
31
|
-
backend_id:,
|
32
|
-
},
|
33
|
-
)
|
34
|
-
end
|
35
|
-
|
36
|
-
def add_redirect_route(path, type, destination, options = {})
|
37
|
-
put_json(
|
38
|
-
"#{endpoint}/routes",
|
39
|
-
route: {
|
40
|
-
incoming_path: path,
|
41
|
-
route_type: type,
|
42
|
-
handler: "redirect",
|
43
|
-
redirect_to: destination,
|
44
|
-
segments_mode: options[:segments_mode],
|
45
|
-
},
|
46
|
-
)
|
47
|
-
end
|
48
|
-
|
49
|
-
def add_gone_route(path, type)
|
50
|
-
put_json(
|
51
|
-
"#{endpoint}/routes",
|
52
|
-
route: { incoming_path: path, route_type: type, handler: "gone" },
|
53
|
-
)
|
54
|
-
end
|
55
|
-
|
56
|
-
def delete_route(path, hard_delete: false)
|
57
|
-
url = "#{endpoint}/routes?incoming_path=#{CGI.escape(path)}"
|
58
|
-
url += "&hard_delete=true" if hard_delete
|
59
|
-
|
60
|
-
delete_json(url)
|
61
|
-
end
|
62
|
-
end
|
@@ -1,94 +0,0 @@
|
|
1
|
-
require "gds_api/test_helpers/json_client_helper"
|
2
|
-
|
3
|
-
module GdsApi
|
4
|
-
module TestHelpers
|
5
|
-
module Router
|
6
|
-
ROUTER_API_ENDPOINT = Plek.find("router-api")
|
7
|
-
|
8
|
-
def stub_router_has_route(path, route, bearer_token = ENV["ROUTER_API_BEARER_TOKEN"])
|
9
|
-
stub_get_route(path, bearer_token).to_return(
|
10
|
-
status: 200,
|
11
|
-
body: route.to_json,
|
12
|
-
headers: { "Content-Type" => "application/json" },
|
13
|
-
)
|
14
|
-
end
|
15
|
-
|
16
|
-
def stub_router_doesnt_have_route(path, bearer_token = ENV["ROUTER_API_BEARER_TOKEN"])
|
17
|
-
stub_get_route(path, bearer_token).to_return(status: 404)
|
18
|
-
end
|
19
|
-
|
20
|
-
def stub_router_has_backend_route(path, backend_id:, route_type: "exact", disabled: false)
|
21
|
-
stub_router_has_route(path, handler: "backend", backend_id:, disabled:, route_type:)
|
22
|
-
end
|
23
|
-
|
24
|
-
def stub_router_has_redirect_route(path, redirect_to:, route_type: "exact", disabled: false)
|
25
|
-
stub_router_has_route(path, handler: "redirect", redirect_to:, disabled:, route_type:)
|
26
|
-
end
|
27
|
-
|
28
|
-
def stub_router_has_gone_route(path, route_type: "exact", disabled: false)
|
29
|
-
stub_router_has_route(path, handler: "gone", route_type:, disabled:)
|
30
|
-
end
|
31
|
-
|
32
|
-
def stub_all_router_registration
|
33
|
-
stub_request(:put, %r{\A#{ROUTER_API_ENDPOINT}/backends/[a-z0-9-]+\z})
|
34
|
-
stub_request(:put, "#{ROUTER_API_ENDPOINT}/routes")
|
35
|
-
end
|
36
|
-
|
37
|
-
def stub_router_backend_registration(backend_id, backend_url)
|
38
|
-
backend = { "backend" => { "backend_url" => backend_url } }
|
39
|
-
stub_http_request(:put, "#{ROUTER_API_ENDPOINT}/backends/#{backend_id}")
|
40
|
-
.with(body: backend.to_json)
|
41
|
-
.to_return(status: 201)
|
42
|
-
end
|
43
|
-
|
44
|
-
def stub_route_registration(path, type, backend_id)
|
45
|
-
stub_route_put({
|
46
|
-
route: {
|
47
|
-
incoming_path: path,
|
48
|
-
route_type: type,
|
49
|
-
handler: "backend",
|
50
|
-
backend_id:,
|
51
|
-
},
|
52
|
-
})
|
53
|
-
end
|
54
|
-
|
55
|
-
def stub_redirect_registration(path, type, destination, segments_mode = nil)
|
56
|
-
stub_route_put({
|
57
|
-
route: {
|
58
|
-
incoming_path: path,
|
59
|
-
route_type: type,
|
60
|
-
handler: "redirect",
|
61
|
-
redirect_to: destination,
|
62
|
-
segments_mode:,
|
63
|
-
},
|
64
|
-
})
|
65
|
-
end
|
66
|
-
|
67
|
-
def stub_gone_route_registration(path, type)
|
68
|
-
stub_route_put({
|
69
|
-
route: {
|
70
|
-
incoming_path: path,
|
71
|
-
route_type: type,
|
72
|
-
handler: "gone",
|
73
|
-
},
|
74
|
-
})
|
75
|
-
end
|
76
|
-
|
77
|
-
private
|
78
|
-
|
79
|
-
def stub_get_route(path, bearer_token)
|
80
|
-
stub_http_request(:get, "#{ROUTER_API_ENDPOINT}/routes")
|
81
|
-
.with(
|
82
|
-
query: { "incoming_path" => path },
|
83
|
-
headers: { "Authorization" => "Bearer #{bearer_token}" },
|
84
|
-
)
|
85
|
-
end
|
86
|
-
|
87
|
-
def stub_route_put(route)
|
88
|
-
stub_http_request(:put, "#{ROUTER_API_ENDPOINT}/routes")
|
89
|
-
.with(body: route.to_json)
|
90
|
-
.to_return(status: 201)
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|