performanceclient

package module
v0.0.0-...-dbee1eb Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2016 License: MIT Imports: 9 Imported by: 2

README

Build Status Code Coverage

Overview

Go client for the Performance Platform.

import "github.com/alphagov/performanceplatform-client.go"

Development

You will need go and make installed

To run the tests:

> make

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound is an error indicating that the server returned a 404.
	ErrNotFound = errors.New("not found")
	// ErrBadRequest is an error indicating that the client request had a problem.
	ErrBadRequest = errors.New("bad request")
)

Functions

func NewRequest

func NewRequest(url string, options ...Option) (*http.Response, error)

NewRequest tries to make a request to the URL, returning the http.Response if it was successful, or an error if there was a problem. Optional Option arguments can be passed to specify contextual behaviour for this request. See MaxElapsedTime.

func ReadResponseBody

func ReadResponseBody(response *http.Response) ([]byte, error)

ReadResponseBody reads the response body stream and returns a byte array, or an error if there was a problem.

Types

type BackdropResponse

type BackdropResponse struct {
	Data    json.RawMessage `json:"data"`
	Warning string          `json:"warning,omitempty"`
	Status  string          `json:"status,omitempty"`
	Message string          `json:"message,omitempty"`
}

BackdropResponse is a response from the Backdrop Read API

type Dashboard

type Dashboard struct {
	Department    Organisation `json:"department"`
	Agency        Organisation `json:"agency,omitempty"`
	DashboardType string       `json:"dashboard-type"`
	Slug          string       `json:"slug"`
	Title         string       `json:"title"`
	Description   string       `json:"description"`
	Modules       []Module     `json:"modules"`
	Published     bool         `json:"published"`
	PageType      string       `json:"page-type"`
	Costs         string       `json:"costs"`
}

Dashboard represents a collection of modules for a given organisation

type Dashboards

type Dashboards struct {
	Items []Dashboard `json:"Items"`
}

Dashboards is a collection of Dashboard instances

type DataClient

type DataClient interface {
	// BuildURL creates the URL to make a request to the read API
	BuildURL(dataGroup, dataType string, dataQuery QueryParams) string
	// Fetch makes a request to the read API and returns a non-nil BackdropResponse or an error
	Fetch(dataGroup, dataType string, dataQuery QueryParams) (*BackdropResponse, error)
}

DataClient is a client for the Backdrop Read API

func NewDataClient

func NewDataClient(url string, logger *logrus.Logger, options ...Option) DataClient

NewDataClient creates a new DataClient for talking to the Read API

type DataSource

type DataSource struct {
	DataGroup   string      `json:"data-group"`
	DataType    string      `json:"data-type"`
	QueryParams QueryParams `json:"query-params"`
}

DataSource is the data source for a module

type MetaClient

type MetaClient interface {
	Fetch(slug string) (Dashboard, error)
	FetchDashboards() (Dashboards, error)
}

MetaClient defines the interface that we need to talk to the meta data API

func NewMetaClient

func NewMetaClient(baseURL string, log *logrus.Logger) MetaClient

NewMetaClient returns a new MetaClient implementation with sensible defaults.

type Module

type Module struct {
	Info       []string   `json:"info"`
	DataSource DataSource `json:"data-source"`
	Tabs       []Tab      `json:"tabs"`
	Title      string     `json:"title"`
}

Module represents a visualisation with a Dashboard

type Option

type Option func(*http.Request, *RequestOptions) Option

Option is a self-referential function used to configure a RequestOptions struct. See http://commandcenter.blogspot.com.au/2014/01/self-referential-functions-and-design.html

func BearerToken

func BearerToken(bearerToken string) Option

BearerToken sets the Authorization header for a request

func MaxElapsedTime

func MaxElapsedTime(duration time.Duration) Option

MaxElapsedTime specifies the maximum duration that we should use to retry requests to the origin server. The default value is 5 seconds.

type Organisation

type Organisation struct {
	Abbreviation string `json:"abbr"`
	Title        string `json:"title"`
}

Organisation represents a government organisational unit, such as department or agency

type QueryParams

type QueryParams struct {
	FilterBy       []string  `json:"filter_by,omitempty" url:"filter_by,omitempty"`
	FilterByPrefix []string  `json:"filter_by_prefix,omitempty" url:"filter_by_prefix,omitempty"`
	GroupBy        []string  `json:"group_by,omitempty" url:"group_by,omitempty"`
	Collect        []string  `json:"collect,omitempty" url:"collect,omitempty"`
	SortBy         string    `json:"sort_by,omitempty" url:"sort_by,omitempty"`
	Duration       int       `json:"duration,omitempty" url:"duration,omitempty"`
	Period         string    `json:"period,omitempty" url:"period,omitempty"`
	Limit          int       `json:"limit,omitempty" url:"limit,omitempty"`
	StartAt        time.Time `json:"start_at,omitempty" url:"start_at,omitempty"`
	EndAt          time.Time `json:"end_at,omitempty" url:"end_at,omitempty"`
}

QueryParams represents the possible parameters that the Backdrop RPC read API supports

type RequestOptions

type RequestOptions struct {
	// MaxElapsedTime is the duration allowed to try to get a response from the origin server.
	MaxElapsedTime time.Duration
}

RequestOptions is the container for tweaking how NewRequest functions.

type Tab

type Tab struct {
	Description string     `json:"description"`
	DataSource  DataSource `json:"data-source"`
}

Tab is a UI construct exposed within the meta data API

Jump to

Keyboard shortcuts

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