category

package
v2.260.0 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2024 License: MIT Imports: 12 Imported by: 2

README

Category Client

Description

Responsible for categorisation of the query for more information on the api this README.md

Usage

Initialization
import "github.com/ONSdigital/dp-api-clients-go/v2/nlp/category"

// Initialize the Category API client
client := category.New("https://categoryURL.com")
Functionality

signature

// GetCategory gets a list of category results based on the category request
// you can get options from the category client package 
func (cli *Client) GetCategory(ctx context.Context, options Options) (*models.Category, errors.Error)

Once initialized you can make a request to Category like so:

// Create an Options struct and set a query parameter 'query'
// you can also use url.Values directly into the Options
options := category.OptInit()
options.Q("your_query_here")

// Add custom headers to the options
options.Headers = http.Header{}
options.Headers.Set(authHeader, "")
options.Headers.Set(someOtherHeader, "")

// Get Category results using the created client and custom options
results, err := client.GetCategory(ctx, options)
if err != nil {
    // handle error
}

you can reuse a healthcheck client like so:

categoryClient := client.NewWithHealthClient(hcCli)
// same thing next

some other functionality:

// URL returns the URL used by this client
func (cli *Client) URL() string {

// Health returns the underlying Healthcheck Client for this category API client
func (cli *Client) Health() *healthcheck.Client {

// Checker calls category api health endpoint and returns a check object to the caller
func (cli *Client) Checker(ctx context.Context, check *health.CheckState) error {

Documentation

Index

Constants

This section is empty.

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(categoryAPIURL string) *Client

New creates a new instance of Client with a given category api url

func NewWithHealthClient

func NewWithHealthClient(hcCli *healthcheck.Client) *Client

NewWithHealthClient creates a new instance of category 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 category api health endpoint and returns a check object to the caller

func (*Client) GetCategory

func (cli *Client) GetCategory(ctx context.Context, options Options) (*[]models.Category, errors.Error)

GetCategory gets a list of category results based on the category request

func (*Client) Health

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

Health returns the underlying Healthcheck Client for this category 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
	GetCategory(ctx context.Context, options Options) (*[]models.Category, errors.Error)
	Health() *healthcheck.Client
	URL() string
}

type ClienterMock

type ClienterMock struct {
	// CheckerFunc mocks the Checker method.
	CheckerFunc func(ctx context.Context, check *health.CheckState) error

	// GetCategoryFunc mocks the GetCategory method.
	GetCategoryFunc func(ctx context.Context, options Options) (*[]models.Category, errors.Error)

	// HealthFunc mocks the Health method.
	HealthFunc func() *healthcheck.Client

	// URLFunc mocks the URL method.
	URLFunc func() string
	// contains filtered or unexported fields
}

ClienterMock is a mock implementation of Clienter.

func TestSomethingThatUsesClienter(t *testing.T) {

	// make and configure a mocked Clienter
	mockedClienter := &ClienterMock{
		CheckerFunc: func(ctx context.Context, check *health.CheckState) error {
			panic("mock out the Checker method")
		},
		GetCategoryFunc: func(ctx context.Context, options Options) (*[]models.Category, errors.Error) {
			panic("mock out the GetCategory method")
		},
		HealthFunc: func() *healthcheck.Client {
			panic("mock out the Health method")
		},
		URLFunc: func() string {
			panic("mock out the URL method")
		},
	}

	// use mockedClienter in code that requires Clienter
	// and then make assertions.

}

func (*ClienterMock) Checker

func (mock *ClienterMock) Checker(ctx context.Context, check *health.CheckState) error

Checker calls CheckerFunc.

func (*ClienterMock) CheckerCalls

func (mock *ClienterMock) CheckerCalls() []struct {
	Ctx   context.Context
	Check *health.CheckState
}

CheckerCalls gets all the calls that were made to Checker. Check the length with:

len(mockedClienter.CheckerCalls())

func (*ClienterMock) GetCategory

func (mock *ClienterMock) GetCategory(ctx context.Context, options Options) (*[]models.Category, errors.Error)

GetCategory calls GetCategoryFunc.

func (*ClienterMock) GetCategoryCalls

func (mock *ClienterMock) GetCategoryCalls() []struct {
	Ctx     context.Context
	Options Options
}

GetCategoryCalls gets all the calls that were made to GetCategory. Check the length with:

len(mockedClienter.GetCategoryCalls())

func (*ClienterMock) Health

func (mock *ClienterMock) Health() *healthcheck.Client

Health calls HealthFunc.

func (*ClienterMock) HealthCalls

func (mock *ClienterMock) HealthCalls() []struct {
}

HealthCalls gets all the calls that were made to Health. Check the length with:

len(mockedClienter.HealthCalls())

func (*ClienterMock) URL

func (mock *ClienterMock) URL() string

URL calls URLFunc.

func (*ClienterMock) URLCalls

func (mock *ClienterMock) URLCalls() []struct {
}

URLCalls gets all the calls that were made to URL. Check the length with:

len(mockedClienter.URLCalls())

type Options

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

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

func OptInit

func OptInit() Options

empty Options

func (*Options) Q

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

Q sets the 'q' Query parameter to the request

func (*Options) Snr

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

Snr sets the 'snr' 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