cantabular

package
v3.0.0-...-1e29e98 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2021 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const Service = "cantabular"

Service is the cantabular service name

Variables

This section is empty.

Functions

This section is empty.

Types

type Category

type Category struct {
	Code  string `json:"code"`
	Label string `json:"label"`
}

Category represents the 'category' field from the GraphQL query dataset response

type Client

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

Client is the client for interacting with the Cantabular API

func NewClient

func NewClient(cfg Config, ua httpClient, g GraphQLClient) *Client

NewClient returns a new Client

func (*Client) Checker

func (c *Client) Checker(ctx context.Context, state *healthcheck.CheckState) error

Checker contacts the /v9/datasets endpoint and updates the healthcheck state accordingly.

func (*Client) GetCodebook

func (c *Client) GetCodebook(ctx context.Context, req GetCodebookRequest) (*GetCodebookResponse, error)

GetCodebook gets a Codebook from cantabular.

func (*Client) ParseTable

func (c *Client) ParseTable(table Table) (*bufio.Reader, error)

ParseTable takes a table from a GraphQL response and parses it into a header and rows of counts (observations) ready to be read line-by-line.

func (*Client) StaticDatasetQuery

func (c *Client) StaticDatasetQuery(ctx context.Context, req StaticDatasetQueryRequest) (*StaticDatasetQuery, error)

StaticDatasetQuery performs a query for a static dataset against the Cantabular Extended API using the /graphql endpoint

type Codebook

type Codebook []Variable

Codebook represents a 'codebook' object returned from Cantabular Server

type Config

type Config struct {
	Host           string
	ExtApiHost     string
	GraphQLTimeout time.Duration
}

Config holds the config used to initialise the Cantabular Client

type Dataset

type Dataset struct {
	Name             string    `json:"name"`
	Digest           string    `json:"digest"`
	Description      string    `json:"description"`
	Size             int       `json:"size"`
	RulebaseVariable string    `json:"ruleBaseVariable"`
	DateTime         time.Time `json:"datetime"`
}

Dataset represents a 'dataset' object returned from Cantabular Server

type Dimension

type Dimension struct {
	Count      int          `json:"count"`
	Categories []Category   `json:"categories"`
	Variable   VariableBase `json:"variable"`
}

Dimension represents the 'dimension' field from a GraphQL query dataset response

type ErrorResponse

type ErrorResponse struct {
	Message string `json:"message"`
}

ErrorResponse models the error response from cantabular

type GetCodebookRequest

type GetCodebookRequest struct {
	DatasetName string
	Variables   []string
	Categories  bool
}

GetCodebookRequest holds the query parameters for GET [cantabular-srv]/codebook/{dataset}?cats=xxx&v=xxx

type GetCodebookResponse

type GetCodebookResponse struct {
	Codebook Codebook `json:"codebook"`
	Dataset  Dataset  `json:"dataset"`
}

GetCodebookResponse holds the response body for GET [cantabular-srv]/codebook/{dataset}?cats=xxx&v=xxx

type GraphQLClient

type GraphQLClient interface {
	Query(ctx context.Context, query interface{}, vars map[string]interface{}) error
}

GraphQLClient is the Client used by the GraphQL package to make queries

type MapFrom

type MapFrom struct {
	SourceNames []string `json:"sourceNames,omitempty"`
	Code        []string `json:"codes,omitempty"`
}

MapFrom represents the 'mapFrom' object from variable when category information is included

type StaticDataset

type StaticDataset struct {
	Table Table `json:"table" graphql:"table(variables: $variables)"`
}

StaticDataset represents the 'dataset' field from a GraphQL static dataset query response

type StaticDatasetQuery

type StaticDatasetQuery struct {
	Dataset StaticDataset `json:"dataset" graphql:"dataset(name: $name)"`
}

StaticDatasetQuery holds the query for a static dataset landing page from POST [cantabular-ext]/graphql. It is used both as the internal query request to GraphQL as well as the response to the caller, as GraphQL query responses are essentially unmarshalled into the requests.

type StaticDatasetQueryRequest

type StaticDatasetQueryRequest struct {
	Dataset   string   `json:"dataset"`
	Variables []string `json:"variables"`
}

StaticDatasetQueryRequest holds the request variables required from the caller for making a request for a static dataset landing page from POST [cantabular-ext]/graphql

type Table

type Table struct {
	Dimensions []Dimension `json:"dimensions"`
	Values     []int       `json:"values"`
	Error      string      `json:"error,omitempty" `
}

Table represents the 'table' field from the GraphQL dataset query response

type Variable

type Variable struct {
	VariableBase
	Len     int       `json:"len"`
	Codes   []string  `json:"codes,omitempty"`
	Labels  []string  `json:"labels,omitempty"`
	MapFrom []MapFrom `json:"mapFrom,omitempty"`
}

Variable represents a 'variable' object returned from Cantabular

type VariableBase

type VariableBase struct {
	Name  string `json:"name"`
	Label string `json:"label"`
}

VariableBase represents the minimum amount of fields returned by Cantabular for a 'variable' object. Is kept separate from the full Variable struct because GraphQL/Cantabular has difficulty unmarshaling into a struct with unexpected objects (in this case MapFrom), even if they're set to not be included

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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