Class: GdsApi::LinkCheckerApi

Inherits:
Base
  • Object
show all
Defined in:
lib/gds_api/link_checker_api.rb

Defined Under Namespace

Classes: BatchReport, LinkReport

Instance Attribute Summary

Attributes inherited from Base

#options

Instance Method Summary collapse

Methods inherited from Base

#client, #create_client, #get_list, #initialize, #url_for_slug

Constructor Details

This class inherits a constructor from GdsApi::Base

Instance Method Details

#check(uri, synchronous: nil, checked_within: nil) ⇒ LinkReport

Checks whether a link is broken.

Makes a GET request to the link checker api to check a link.

Parameters:

  • uri (String)

    The URI to check.

  • synchronous (Boolean) (defaults to: nil)

    Whether the check should happen immediately. (optional)

  • checked_within (Fixnum) (defaults to: nil)

    The number of seconds the last check should be within before doing another check. (optional)

Returns:

  • (LinkReport)

    A SimpleDelegator of the GdsApi::Response which responds to:

    :uri              the URI of the link
    :status           the status of the link, one of: ok, pending, broken, caution
    :checked          the date the link was checked
    :errors           a list of error descriptions
    :warnings         a list of warning descriptions
    :problem_summary  a short description of the most critical problem with the link
    :suggested_fix    where possible, this provides a potential fix for the problem
    

Raises:



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/gds_api/link_checker_api.rb', line 23

def check(uri, synchronous: nil, checked_within: nil)
  params = {
    uri:,
    synchronous:,
    checked_within:,
  }

  response = get_json(
    "#{endpoint}/check" + query_string(params.delete_if { |_, v| v.nil? }),
  )

  LinkReport.new(response.to_hash)
end

#create_batch(uris, checked_within: nil, webhook_uri: nil, webhook_secret_token: nil) ⇒ BatchReport

Create a batch of links to check.

Makes a POST request to the link checker api to create a batch.

Parameters:

  • uris (Array)

    A list of URIs to check.

  • checked_within (Fixnum) (defaults to: nil)

    The number of seconds the last check should be within before doing another check. (optional)

  • webhook_uri (String) (defaults to: nil)

    The URI to be called when the batch finishes. (optional)

  • webhook_secret_token (String) (defaults to: nil)

    A secret token that the API will use to generate a signature of the request. (optional)

Returns:

  • (BatchReport)

    A SimpleDelegator of the GdsApi::Response which responds to:

    :id            the ID of the batch
    :status        the status of the check, one of: complete or in_progress
    :links         an array of link reports
    :totals        an +OpenStruct+ of total information, fields: links, ok, caution, broken, pending
    :completed_at  a date when the batch was completed
    

Raises:



55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/gds_api/link_checker_api.rb', line 55

def create_batch(uris, checked_within: nil, webhook_uri: nil, webhook_secret_token: nil)
  payload = {
    uris:,
    checked_within:,
    webhook_uri:,
    webhook_secret_token:,
  }

  response = post_json(
    "#{endpoint}/batch", payload.delete_if { |_, v| v.nil? }
  )

  BatchReport.new(response.to_hash)
end

#get_batch(id) ⇒ BatchReport

Get information about a batch.

Makes a GET request to the link checker api to get a batch.

Parameters:

  • id (Fixnum)

    The batch ID to get information about.

Returns:

  • (BatchReport)

    A SimpleDelegator of the GdsApi::Response which responds to:

    :id            the ID of the batch
    :status        the status of the check, one of: completed or in_progress
    :links         an array of link reports
    :totals        an +OpenStruct+ of total information, fields: links, ok, caution, broken, pending
    :completed_at  a date when the batch was completed
    

Raises:



84
85
86
87
88
89
90
# File 'lib/gds_api/link_checker_api.rb', line 84

def get_batch(id)
  BatchReport.new(
    get_json(
      "#{endpoint}/batch/#{id}",
    ).to_hash,
  )
end