geckoboard

package module
v0.0.0-...-41bd2d2 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2024 License: MIT Imports: 9 Imported by: 0

README

go-geckoboard

Installing

Install with go modules

go get github.com/geckoboard/go-geckoboard

import with:

import (
    "github.com/geckoboard/go-geckoboard
)

API requests

Find or create a new dataset
	ctx := context.Background()
	svc := geckoboard.New('<apikey>').DatasetService()

	dataset := &geckoboard.Dataset{
		Name: "orders_by_country",
		Fields: map[string]geckoboard.Field{
			"report_date": {Type: geckoboard.DateType, Optional: false, Name: "Report date"},
			"country":     {Type: geckoboard.StringType, Optional: false, Name: "Country"},
			"orders":      {Type: geckoboard.NumberType, Optional: true, Name: "Orders"},
		},
		UniqueBy: []string{"report_date", "country"},
	}

	if err := svc.FindOrCreate(ctx, dataset); err != nil {
		log.Fatal(err)
	}
Update a dataset
err := svc.AppendData(ctx, dataset, geckoboard.Data{
	{
		"report_date": time.Date(2024, 5, 1, 0, 0, 0, 0, time.UTC).Format(time.DateOnly),
		"country":     "United States",
		"orders":      88,
	},
	{
		"report_date": time.Date(2024, 5, 1, 0, 0, 0, 0, time.UTC).Format(time.DateOnly),
		"country":     "United Kingdom",
		"orders":      33,
	},
	{
		"report_date": time.Date(2024, 6, 1, 0, 0, 0, 0, time.UTC).Format(time.DateOnly),
		"country":     "United States",
		"orders":      108,
	},
	{
		"report_date": time.Date(2024, 6, 1, 0, 0, 0, 0, time.UTC).Format(time.DateOnly),
		"country":     "United Kingdom",
		"orders":      42,
	},
})
Replace all data in a dataset
	err := svc.ReplaceData(ctx, dataset, geckoboard.Data{
		{
			"report_date": time.Date(2024, 5, 1, 0, 0, 0, 0, time.UTC).Format(time.DateOnly),
			"country":     "All",
			"orders":      888,
		}
	})
Delete a dataset

TBD

Ping to test connection

TBD

Running the tests

make test

Still to be developed

  • Support deleting a dataset
  • Support appending to dataset with delete_by option
  • Support ping to test connection good?
  • Custom json marshaling on data to serialize date or datetime from time object based on the schema

Documentation

Index

Constants

View Source
const (
	NumberType   FieldType = "number"
	DateType     FieldType = "date"
	DatetimeType FieldType = "datetime"
	StringType   FieldType = "string"
	PercentType  FieldType = "percentage"
	DurationType FieldType = "duration"
	MoneyType    FieldType = "money"

	Milliseconds TimeUnit = "milliseconds"
	Seconds      TimeUnit = "seconds"
	Minutes      TimeUnit = "minutes"
	Hours        TimeUnit = "hours"
)

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

func NewWithURL

func NewWithURL(apikey, baseURL string) *Client

func (*Client) DatasetService

func (c *Client) DatasetService() DatasetService

type Data

type Data []DataRow

type DataPayload

type DataPayload struct {
	Data Data `json:"data"`
}

type DataRow

type DataRow map[string]any

type Dataset

type Dataset struct {
	Name     string           `json:"id"`
	Fields   map[string]Field `json:"fields"`
	UniqueBy []string         `json:"unique_by,omitempty"`
}

type DatasetService

type DatasetService interface {
	FindOrCreate(context.Context, *Dataset) error
	AppendData(context.Context, *Dataset, Data) error
	ReplaceData(context.Context, *Dataset, Data) error
}

type DatasetType

type DatasetType string

type Detail

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

type Error

type Error struct {
	Detail     `json:"error"`
	StatusCode int `json:"-"`
}

func (Error) Error

func (e Error) Error() string

type Field

type Field struct {
	Type     FieldType `json:"type"`
	Name     string    `json:"name"`
	Optional bool      `json:"optional"`

	// Required only when field type is duration
	TimeUnit TimeUnit `json:"time_unit,omitempty"`
	// Required only when field type is money
	// ISO4217 currency code https://en.wikipedia.org/wiki/ISO_4217#Active_codes
	CurrencyCode string `json:"currency_code,omitempty"`
}

type FieldType

type FieldType string

type TimeUnit

type TimeUnit string

Jump to

Keyboard shortcuts

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