gds-api-adapters 41.2.0 → 41.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/link_checker_api.rb +131 -0
- data/lib/gds_api/test_helpers/link_checker_api.rb +70 -0
- data/lib/gds_api/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5feb2ce88c93b7b3358523b586e7a756e3d4c4df
|
4
|
+
data.tar.gz: 5fb3102fd2d3b114ad2bffe89873478c6e6f4a53
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f64b7cece8973c47f5078a4aa07f24292581b9799c99ec908cad406a3946024555e19406c5767c52a7687ac042f95bb2384d45e8f51d1d29b646cdaada178ffe
|
7
|
+
data.tar.gz: e09157c36fbadfef46512ecc341cfa8671014d8008bfad84553709970b9b77417477bf19d61e892ba23e2204e5f3019a43535afca5f07824e3cb0116d4b1c57c
|
@@ -0,0 +1,131 @@
|
|
1
|
+
require_relative 'base'
|
2
|
+
|
3
|
+
class GdsApi::LinkCheckerApi < GdsApi::Base
|
4
|
+
# Checks whether a link is broken.
|
5
|
+
#
|
6
|
+
# Makes a +GET+ request to the link checker api to check a link.
|
7
|
+
#
|
8
|
+
# @param uri [String] The URI to check.
|
9
|
+
# @param synchronous [Boolean] Whether the check should happen immediately. (optional)
|
10
|
+
# @param checked_within [Fixnum] The number of seconds the last check should
|
11
|
+
# be within before doing another check. (optional)
|
12
|
+
# @return [LinkReport] A +SimpleDelegator+ of the +GdsApi::Response+ which
|
13
|
+
# responds to:
|
14
|
+
# :uri the URI of the link
|
15
|
+
# :status the status of the link, one of: ok, pending, broken, caution
|
16
|
+
# :checked the date the link was checked
|
17
|
+
# :errors a hash mapping short descriptions to arrays of long descriptions
|
18
|
+
# :warnings a hash mapping short descriptions to arrays of long descriptions
|
19
|
+
#
|
20
|
+
# @raise [HTTPErrorResponse] if the request returns an error
|
21
|
+
def check(uri, synchronous: nil, checked_within: nil)
|
22
|
+
params = {
|
23
|
+
uri: uri,
|
24
|
+
synchronous: synchronous,
|
25
|
+
checked_within: checked_within
|
26
|
+
}
|
27
|
+
|
28
|
+
response = get_json(
|
29
|
+
"#{endpoint}/check" + query_string(params.delete_if { |_, v| v.nil? })
|
30
|
+
)
|
31
|
+
|
32
|
+
LinkReport.new(response.to_hash)
|
33
|
+
end
|
34
|
+
|
35
|
+
# Create a batch of links to check.
|
36
|
+
#
|
37
|
+
# Makes a +POST+ request to the link checker api to create a batch.
|
38
|
+
#
|
39
|
+
# @param uris [Array] A list of URIs to check.
|
40
|
+
# @param checked_within [Fixnum] The number of seconds the last check should
|
41
|
+
# be within before doing another check. (optional)
|
42
|
+
# @param webhook_uri [String] The URI to be called when the batch finishes. (optional)
|
43
|
+
# @return [BatchReport] A +SimpleDelegator+ of the +GdsApi::Response+ which
|
44
|
+
# responds to:
|
45
|
+
# :id the ID of the batch
|
46
|
+
# :status the status of the check, one of: complete or in_progress
|
47
|
+
# :links an array of link reports
|
48
|
+
# :totals an +OpenStruct+ of total information, fields: links, ok, caution, broken, pending
|
49
|
+
# :completed_at a date when the batch was completed
|
50
|
+
#
|
51
|
+
# @raise [HTTPErrorResponse] if the request returns an error
|
52
|
+
def create_batch(uris, checked_within: nil, webhook_uri: nil)
|
53
|
+
payload = {
|
54
|
+
uris: uris,
|
55
|
+
checked_within: checked_within,
|
56
|
+
webhook_uri: webhook_uri
|
57
|
+
}
|
58
|
+
|
59
|
+
response = post_json(
|
60
|
+
"#{endpoint}/batch", payload.delete_if { |_, v| v.nil? }
|
61
|
+
)
|
62
|
+
|
63
|
+
BatchReport.new(response.to_hash)
|
64
|
+
end
|
65
|
+
|
66
|
+
# Get information about a batch.
|
67
|
+
#
|
68
|
+
# Makes a +GET+ request to the link checker api to get a batch.
|
69
|
+
#
|
70
|
+
# @param id [Fixnum] The batch ID to get information about.
|
71
|
+
# @return [BatchReport] A +SimpleDelegator+ of the +GdsApi::Response+ which
|
72
|
+
# responds to:
|
73
|
+
# :id the ID of the batch
|
74
|
+
# :status the status of the check, one of: complete or in_progress
|
75
|
+
# :links an array of link reports
|
76
|
+
# :totals an +OpenStruct+ of total information, fields: links, ok, caution, broken, pending
|
77
|
+
# :completed_at a date when the batch was completed
|
78
|
+
#
|
79
|
+
# @raise [HTTPErrorResponse] if the request returns an error
|
80
|
+
def get_batch(id)
|
81
|
+
BatchReport.new(
|
82
|
+
get_json(
|
83
|
+
"#{endpoint}/batch/#{id}"
|
84
|
+
).to_hash
|
85
|
+
)
|
86
|
+
end
|
87
|
+
|
88
|
+
class LinkReport < SimpleDelegator
|
89
|
+
def uri
|
90
|
+
self["uri"]
|
91
|
+
end
|
92
|
+
|
93
|
+
def status
|
94
|
+
self["status"].to_sym
|
95
|
+
end
|
96
|
+
|
97
|
+
def checked
|
98
|
+
Time.iso8601(self["checked"])
|
99
|
+
end
|
100
|
+
|
101
|
+
def errors
|
102
|
+
self["errors"].each_with_object({}) { |(k, v), hash| hash[k.to_sym] = v }
|
103
|
+
end
|
104
|
+
|
105
|
+
def warnings
|
106
|
+
self["warnings"].each_with_object({}) { |(k, v), hash| hash[k.to_sym] = v }
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
class BatchReport < SimpleDelegator
|
111
|
+
def id
|
112
|
+
self["id"]
|
113
|
+
end
|
114
|
+
|
115
|
+
def status
|
116
|
+
self["status"].to_sym
|
117
|
+
end
|
118
|
+
|
119
|
+
def links
|
120
|
+
self["links"].map { |link_report| LinkReport.new(link_report) }
|
121
|
+
end
|
122
|
+
|
123
|
+
def totals
|
124
|
+
OpenStruct.new(self["totals"])
|
125
|
+
end
|
126
|
+
|
127
|
+
def completed_at
|
128
|
+
Time.iso8601(self["completed_at"])
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require "gds_api/test_helpers/json_client_helper"
|
2
|
+
|
3
|
+
module GdsApi
|
4
|
+
module TestHelpers
|
5
|
+
module LinkCheckerApi
|
6
|
+
LINK_CHECKER_API_ENDPOINT = Plek.current.find("link-checker-api")
|
7
|
+
|
8
|
+
def link_checker_api_link_report_hash(uri:, status: :ok, checked: nil, errors: {}, warnings: {})
|
9
|
+
{
|
10
|
+
uri: uri,
|
11
|
+
status: status,
|
12
|
+
checked: checked || Time.now.iso8601,
|
13
|
+
errors: errors,
|
14
|
+
warnings: warnings,
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
def link_checker_api_batch_report_hash(id:, status: :completed, links: [], totals: {}, completed_at: nil)
|
19
|
+
{
|
20
|
+
id: id,
|
21
|
+
status: status,
|
22
|
+
links: links.map { |hash| link_checker_api_link_report_hash(**hash) },
|
23
|
+
totals: totals,
|
24
|
+
completed_at: completed_at || Time.now.iso8601,
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
def link_checker_api_check(uri:, status: :ok, checked: nil, errors: {}, warnings: {})
|
29
|
+
body = link_checker_api_link_report_hash(
|
30
|
+
uri: uri, status: status, checked: checked, errors: errors, warnings: warnings
|
31
|
+
).to_json
|
32
|
+
|
33
|
+
stub_request(:get, "#{LINK_CHECKER_API_ENDPOINT}/check")
|
34
|
+
.with(query: { uri: uri })
|
35
|
+
.to_return(body: body, status: 200, headers: { "Content-Type" => "application/json" })
|
36
|
+
end
|
37
|
+
|
38
|
+
def link_checker_api_get_batch(id:, status: :completed, links: [], totals: {}, completed_at: nil)
|
39
|
+
body = link_checker_api_batch_report_hash(
|
40
|
+
id: id, status: status, links: links, totals: totals, completed_at: completed_at
|
41
|
+
).to_json
|
42
|
+
|
43
|
+
stub_request(:get, "#{LINK_CHECKER_API_ENDPOINT}/batch/#{id}")
|
44
|
+
.to_return(body: body, status: 200, headers: { "Content-Type" => "application/json" })
|
45
|
+
end
|
46
|
+
|
47
|
+
def link_checker_api_create_batch(uris:, checked_within: nil, webhook_uri: nil, id: 0, status: :in_progress, links: nil, totals: {}, completed_at: nil)
|
48
|
+
links = uris.map { |uri| { uri: uri } } if links.nil?
|
49
|
+
|
50
|
+
response_body = link_checker_api_batch_report_hash(
|
51
|
+
id: id, status: status, links: links, totals: totals, completed_at: completed_at
|
52
|
+
).to_json
|
53
|
+
|
54
|
+
request_body = {
|
55
|
+
uris: uris,
|
56
|
+
checked_within: checked_within,
|
57
|
+
webhook_uri: webhook_uri,
|
58
|
+
}.delete_if { |_, v| v.nil? }.to_json
|
59
|
+
|
60
|
+
stub_request(:post, "#{LINK_CHECKER_API_ENDPOINT}/batch")
|
61
|
+
.with(body: request_body)
|
62
|
+
.to_return(
|
63
|
+
body: response_body,
|
64
|
+
status: status == :in_progress ? 202 : 201,
|
65
|
+
headers: { "Content-Type" => "application/json" }
|
66
|
+
)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
data/lib/gds_api/version.rb
CHANGED
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: 41.
|
4
|
+
version: 41.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: 2017-
|
11
|
+
date: 2017-04-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: plek
|
@@ -369,6 +369,7 @@ files:
|
|
369
369
|
- lib/gds_api/imminence.rb
|
370
370
|
- lib/gds_api/json_client.rb
|
371
371
|
- lib/gds_api/licence_application.rb
|
372
|
+
- lib/gds_api/link_checker_api.rb
|
372
373
|
- lib/gds_api/list_response.rb
|
373
374
|
- lib/gds_api/local_links_manager.rb
|
374
375
|
- lib/gds_api/mapit.rb
|
@@ -402,6 +403,7 @@ files:
|
|
402
403
|
- lib/gds_api/test_helpers/intent_helpers.rb
|
403
404
|
- lib/gds_api/test_helpers/json_client_helper.rb
|
404
405
|
- lib/gds_api/test_helpers/licence_application.rb
|
406
|
+
- lib/gds_api/test_helpers/link_checker_api.rb
|
405
407
|
- lib/gds_api/test_helpers/local_links_manager.rb
|
406
408
|
- lib/gds_api/test_helpers/mapit.rb
|
407
409
|
- lib/gds_api/test_helpers/need_api.rb
|