sdk

package
v1.17.0 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2026 License: MIT Imports: 15 Imported by: 2

README

dis-bundle-api SDK

Overview

This API contains a client with functions for interacting with the Bundle API from other applications. It provides methods to retrieve and update bundle information.

Available methods
Method Description
GetBundles Retrieves a paginated list of bundles, optionally filtered by scheduled date
GetBundle Retrieves a single bundle by ID
PutBundleState Updates the state of a bundle (DRAFT, IN_REVIEW, APPROVED, PUBLISHED)
Checker Performs a health check against the Bundle API endpoint
Health Returns the underlying health check client
URL Returns the base URL of the Bundle API

Example Use of the Client

package main

import (
    "context"
    "log"
    "time"

    "github.com/ONSdigital/dis-bundle-api/models"
    "github.com/ONSdigital/dis-bundle-api/sdk"
    sdkErrors "github.com/ONSdigital/dis-bundle-api/sdk/errors"
)

func main() {
    client := sdk.New("http://localhost:29800")
    
    headers := sdk.Headers{
        ServiceAuthToken: "your-service-token",
    }
    
    bundles, err := client.GetBundles(context.Background(), headers, &time.Time{}, nil)
    if err != nil {
        statusCode := sdkErrors.ErrorStatus(err)
        message := sdkErrors.ErrorMessage(err)
        log.Printf("Failed to get bundles: %s (status: %d)", message, statusCode)
        return
    }
    
    log.Printf("Retrieved %d bundles", len(bundles.Items))
}
With Health Client
    import (
        "github.com/ONSdigital/dis-bundle-api/sdk"
        "github.com/ONSdigital/dp-api-clients-go/v2/health"
    )

    hcClient := health.NewClient("my-service", "http://localhost:29800")
    client := sdk.NewWithHealthClient(hcClient)
    bundles, err := client.GetBundles(context.Background(), headers, &time.Time{}, nil)

Available Functionality

GetBundles

Retrieves a paginated list of bundles, optionally filtered by scheduled date.

queryParams := &sdk.QueryParams{Limit: 10, Offset: 0}
bundles, err := client.GetBundles(ctx, headers, &time.Time{}, queryParams)
GetBundle

Retrieves a single bundle by ID.

respInfo, err := client.GetBundle(ctx, headers, "bundle-id")
PutBundleState

Updates the state of a bundle (DRAFT, IN_REVIEW, APPROVED, PUBLISHED).

headers := sdk.Headers{
    ServiceAuthToken: "token",
    IfMatch:          "etag-value",
}
bundle, err := client.PutBundleState(ctx, headers, "bundle-id", models.BundleStateApproved)
Checker

Performs a health check against the Bundle API endpoint.

check := &health.CheckState{}
err := client.Checker(ctx, check)
Health

Returns the underlying health check client.

hcClient := client.Health()
URL

Returns the base URL of the Bundle API.

url := client.URL()

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BundlesList

type BundlesList struct {
	Items      []models.Bundle `json:"items"`
	Count      int             `json:"count"`
	Offset     int             `json:"offset"`
	Limit      int             `json:"limit"`
	TotalCount int             `json:"total_count"`
}

BundlesList represents an object containing a list of paginated bundles. This struct is based on the `pagination.page` struct which is returned when we call the `api.getBundles` endpoint

type Client

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

func New

func New(bundleAPIURL string) *Client

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

func NewWithHealthClient

func NewWithHealthClient(hcCli *healthcheck.Client) *Client

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

func (*Client) GetBundle

func (cli *Client) GetBundle(ctx context.Context, headers Headers, id string) (*ResponseInfo, apiError.Error)

func (*Client) GetBundles

func (cli *Client) GetBundles(ctx context.Context, headers Headers, scheduledAt *time.Time, queryParams *QueryParams) (*BundlesList, apiError.Error)

GetBundles gets a list of bundles

func (*Client) Health

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

Health returns the underlying Healthcheck Client for this bundle API client

func (*Client) PutBundleState

func (cli *Client) PutBundleState(ctx context.Context, headers Headers, id string, state models.BundleState) (*models.Bundle, apiError.Error)

func (*Client) URL

func (cli *Client) URL() string

URL returns the URL used by this client

type Clienter added in v1.7.0

type Clienter interface {
	Checker(ctx context.Context, check *healthcheck.CheckState) error
	Health() *health.Client
	URL() string
	GetBundles(ctx context.Context, headers Headers, scheduledAt *time.Time, queryParams *QueryParams) (*BundlesList, apiError.Error)
	GetBundle(ctx context.Context, headers Headers, id string) (*ResponseInfo, apiError.Error)
	PutBundleState(ctx context.Context, headers Headers, id string, state models.BundleState) (*models.Bundle, apiError.Error)
}

type Headers

type Headers struct {
	ServiceAuthToken string
	UserAccessToken  string
	IfMatch          string
}

func (*Headers) Add

func (h *Headers) Add(req *http.Request)

type QueryParams

type QueryParams struct {
	Limit  int
	Offset int
}

QueryParams represents the possible query parameters that a caller can provide

func (*QueryParams) Validate

func (q *QueryParams) Validate() error

Validate validates tht no negative values are provided for limit or offset, and that the length of IDs is lower than the maximum

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