sdk

package
v0.4.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 29, 2024 License: MIT Imports: 11 Imported by: 2

README

dp-search-scrubber-api SDK

Overview

The scrubber API contains a Go client for interacting with the API. The client contains a methods for each API endpoint so that any Go application wanting to interact with the scrubber api can do so. Please refer to the swagger specification as the source of truth of how each endpoint works.

Example use of the API SDK

Initialise new Scrubber API client

package main

import (
	"context"
	"github.com/ONSdigital/dp-search-scrubber-api/sdk"
)

func main() {
    // code

	scrubberAPIClient := sdk.NewClient("http://localhost:28700")

    // code
}
Get Scrubber Results

Use the GetScrubber method to send a request to find scrubber results based on query parameters.

    // Set query parameters - no limit to which keys and values you set - please refer to swagger spec for list of available parameters
    opt := sdk.OptInit()
    opt.Q("E00000013,01220")

    resp, err := scrubberAPIClient.GetScrubber(ctx, opt)
    if err != nil {
        // handle error
    }
Handling errors

The error returned from the method contains status code that can be accessed via Status() method and similar to extracting the error message using Error() method; see snippet below:

    _, err := scrubberAPIClient.GetScrubber(ctx, Options{})
    if err != nil {
        // Retrieve status code from error
        statusCode := err.Status()
        // Retrieve error message from error
        errorMessage := err.Error()

        // log message, below uses "github.com/ONSdigital/log.go/v2/log" package
        log.Error(ctx, "failed to retrieve scrubber results", err, log.Data{"code": statusCode})

        return err
    }

Documentation

Index

Constants

View Source
const (
	// List of available headers
	Authorization string = "Authorization"
	CollectionID  string = "Collection-Id"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

func New

func New(scrubberAPIURL string) *Client

New creates a new instance of Client with a given Scrubber API url

func NewWithHealthClient

func NewWithHealthClient(hcCli *healthcheck.Client) *Client

NewWithHealthClient creates a new instance of Scrubber API Client, reusing the URL and Clienter from the provided healthcheck client

func (*Client) Checker

func (cli *Client) Checker(ctx context.Context, check *health.CheckState) error

Checker calls Scrubber API health endpoint and returns a check object to the caller

func (*Client) GetScrubber added in v0.3.0

func (cli *Client) GetScrubber(ctx context.Context, options *Options) (*models.ScrubberResp, errors.Error)

GetScrubber gets a list of OAC and SIC codes based on the request options contain headers and a query

func (*Client) Health

func (cli *Client) Health() *healthcheck.Client

Health returns the underlying Healthcheck Client for this Scrubber API client

func (*Client) URL

func (cli *Client) URL() string

URL returns the URL used by this client

type Clienter

type Clienter interface {
	Checker(ctx context.Context, check *health.CheckState) error
	GetScrubber(ctx context.Context, options *Options) (*models.ScrubberResp, errors.Error)
	Health() *healthcheck.Client
	URL() string
}

Clienter interface for scrubber API client

type Options

type Options struct {
	Headers http.Header
	Query   url.Values
}

Options is a struct containing for customised options for the scrubber API client

func OptInit added in v0.4.0

func OptInit() *Options

empty Options

func (*Options) Q

func (o *Options) Q(val string) *Options

Q sets the 'q' Query parameter to the request

type ResponseInfo

type ResponseInfo struct {
	Body    []byte
	Headers http.Header
	Status  int
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL