berlin

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

Berlin Client

Description

Responsible for identifying geospatial data for more information read this README.md

Usage

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

// Initialize the Berlin API client
client := berlin.New("http://berlinURL.com")
Functionality

signature

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

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

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

// Add custom headers to the options
options.Headers.Set(authHeader, "")
options.Headers.Set(someOtherHeader, "")

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

you can reuse a healthcheck client like so:

berlinClient := 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 berlin API client
func (cli *Client) Health() *healthcheck.Client {

// Checker calls berlin 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(berlinAPIURL string) *Client

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

func NewWithHealthClient

func NewWithHealthClient(hcCli *healthcheck.Client) *Client

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

func (*Client) GetBerlin

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

GetBerlin gets a list of berlin results based on the berlin request

func (*Client) Health

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

Health returns the underlying Healthcheck Client for this berlin 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
	GetBerlin(ctx context.Context, options Options) (*models.Berlin, 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

	// GetBerlinFunc mocks the GetBerlin method.
	GetBerlinFunc func(ctx context.Context, options Options) (*models.Berlin, 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")
		},
		GetBerlinFunc: func(ctx context.Context, options Options) (*models.Berlin, errors.Error) {
			panic("mock out the GetBerlin 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) GetBerlin

func (mock *ClienterMock) GetBerlin(ctx context.Context, options Options) (*models.Berlin, errors.Error)

GetBerlin calls GetBerlinFunc.

func (*ClienterMock) GetBerlinCalls

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

GetBerlinCalls gets all the calls that were made to GetBerlin. Check the length with:

len(mockedClienter.GetBerlinCalls())

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) LevDist

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

LevDist sets the 'lev_distance' Query parameter to the request Optional default is '2'

func (*Options) Limit

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

Limit sets the 'limit' Query parameter to the request Optional default is '10'

func (*Options) Q

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

Q sets the 'q' Query parameter to the request Required

func (*Options) State

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

State sets the 'state' Query parameter to the request Optional default is 'gb'

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