metabase_client

package module
v0.0.0-...-08970ba Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2021 License: MIT Imports: 8 Imported by: 0

README

metabase-go

metabase-go is a simple golang client for Metabase REST API. Its still work in progress

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIClient

type APIClient struct {
	BasePath string `json:"basePath,omitempty"`
	// contains filtered or unexported fields
}

func NewAPIClient

func NewAPIClient(host string) *APIClient

func (*APIClient) AddCardToDashboard

func (c *APIClient) AddCardToDashboard(
	dashboardId int,
	cardId int,
) (OrderedCard, error)

func (*APIClient) CreateCard

func (c *APIClient) CreateCard(
	name string,
	description *string,
	collectionId *CollectionId,
	cardOptions ...CardOption) (*Card, error)

func (*APIClient) CreateCollection

func (c *APIClient) CreateCollection(
	name string, description *string, color *string, parent_id *CollectionId, namespace *string,
) (*Collection, error)

func (*APIClient) CreateDashboard

func (c *APIClient) CreateDashboard(
	name string,
	description *string,
	collectionId *CollectionId,
	collectionPosition *int,
	parameters []FilterParams,
) (*Dashboard, error)

func (*APIClient) CreateSnippet

func (c *APIClient) CreateSnippet(snippet *Snippet) (*Snippet, error)

func (*APIClient) EnableEmbedding

func (c *APIClient) EnableEmbedding(enable bool) error

func (*APIClient) GetAllCards

func (c *APIClient) GetAllCards(
	filter *string,
) ([]Card, error)

func (*APIClient) GetAllCollections

func (c *APIClient) GetAllCollections(isArchived *bool, namespace *string) ([]Collection, error)

func (*APIClient) GetAllDashboards

func (c *APIClient) GetAllDashboards(
	filter *string,
) ([]Dashboard, error)

func (*APIClient) GetAllDatabases

func (c *APIClient) GetAllDatabases(includeTables bool, includeSavedQuestions bool) ([]Database, error)

func (*APIClient) GetCollectionItems

func (c *APIClient) GetCollectionItems(id int, model *string, isArchived *bool) ([]CollectionItem, error)

func (*APIClient) GetDatabase

func (c *APIClient) GetDatabase(id int, includeTables bool, includeTableFields bool) (*Database, error)

func (*APIClient) GetSessionProperties

func (c *APIClient) GetSessionProperties() (*SessionProperties, error)

func (*APIClient) GetTableMetadata

func (c *APIClient) GetTableMetadata(tableId int, includeHiddenFields bool, includeSensitiveFields bool) (TableWithMetadata, error)

func (*APIClient) HealthCheck

func (c *APIClient) HealthCheck() error

func (*APIClient) Login

func (c *APIClient) Login(username string, password string, saveToken bool) (string, error)

func (*APIClient) RandomToken

func (c *APIClient) RandomToken() (string, error)

func (*APIClient) SetEmbeddingToken

func (c *APIClient) SetEmbeddingToken(token string) error

func (*APIClient) SetupInstance

func (c *APIClient) SetupInstance(body *InstanceSetup, saveToken bool) (string, error)

func (*APIClient) SyncSchema

func (c *APIClient) SyncSchema(databaseId int) error

func (*APIClient) UpdateCollection

func (c *APIClient) UpdateCollection(
	collectionID CollectionId,
	description *string,
	color *string,
	parentId *CollectionId,
	namespace *string,
	archived *bool,
) (*Collection, error)

func (*APIClient) UpdateDashboard

func (c *APIClient) UpdateDashboard(
	dashboardId int,
	dashboardOptions ...DashboardOption,
) (*Dashboard, error)

func (*APIClient) UpdateDashboardCards

func (c *APIClient) UpdateDashboardCards(
	dashboardId int,
	orderedCards ...OrderedCard,
) error

func (*APIClient) UpdateSetting

func (c *APIClient) UpdateSetting(key string, value interface{}) error

func (*APIClient) WithDefaultHeader

func (c *APIClient) WithDefaultHeader(key string, val string) *APIClient

func (*APIClient) WithSessionToken

func (c *APIClient) WithSessionToken(token string) *APIClient

type APIError

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

func NewAPIError

func NewAPIError(err error, code int, msg string) *APIError

func (*APIError) Cause

func (e *APIError) Cause() error

func (*APIError) Error

func (e *APIError) Error() string

func (*APIError) Format

func (e *APIError) Format(s fmt.State, verb rune)

func (*APIError) WithContext

func (e *APIError) WithContext(ctx map[string]string) *APIError

func (*APIError) WithField

func (e *APIError) WithField(field string, value string) *APIError

type Card

type Card struct {
	CommonFields
	Display              string                `json:"display"`
	CollectionId         *CollectionId         `json:"collection_id"`
	VisualizationSetting visualizationSettings `json:"visualization_settings"`
	DatabaseQuery        datasetQuery          `json:"dataset_query"`
	Archived             *bool                 `json:"archived,omitempty"`
	EnableEmbedding      *bool                 `json:"enable_embedding,omitempty"`
}

type CardOption

type CardOption func(card *Card) (*Card, error)

func AllowCardEmbedding

func AllowCardEmbedding() CardOption

func NativeQuery

func NativeQuery(databaseId int, query string, templateTags map[string]interface{}) CardOption

func SetDisplay

func SetDisplay(display string, settings map[string]interface{}) CardOption

func SetDisplayAsLine

func SetDisplayAsLine(settings *LineVisualizationSetting) CardOption

func SetDisplayAsScalar

func SetDisplayAsScalar() CardOption

func SetVisualizationSettings

func SetVisualizationSettings(settings map[string]interface{}) CardOption

type Collection

type Collection struct {
	Id          CollectionId  `json:"id,omitempty"`
	Name        string        `json:"name,omitempty"`
	Color       *string       `json:"color,omitempty"`
	Description *string       `json:"description,omitempty"`
	Namespace   *string       `json:"namespace,omitempty"`
	Archived    *bool         `json:"archived,omitempty"`
	ParentId    *CollectionId `json:"parent_id,omitempty"`
}

func (*Collection) GetUrl

func (c *Collection) GetUrl() string

type CollectionId

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

func (*CollectionId) Int

func (c *CollectionId) Int() int

func (CollectionId) MarshalJSON

func (c CollectionId) MarshalJSON() ([]byte, error)

func (*CollectionId) UnmarshalJSON

func (c *CollectionId) UnmarshalJSON(b []byte) error

type CollectionItem

type CollectionItem struct {
	Id          int     `json:"id"`
	Name        string  `json:"name"`
	Description *string `json:"description,omitempty"`
	Favorite    bool    `json:"favorite"`
	Model       string  `json:"model"`
}

type CommonFields

type CommonFields struct {
	Id          int        `json:"id,omitempty"`
	Name        string     `json:"name,omitempty"`
	Description *string    `json:"description,omitempty"`
	CreatedAt   customTime `json:"created_at,omitmepty"`
	UpdatedAt   customTime `json:"updated_at,omitmepty"`
}

type Dashboard

type Dashboard struct {
	CommonFields
	CollectionId        *CollectionId          `json:"collection_id,omitempty"`
	CollectionPoisition *int                   `json:"collection_position,omitempty"`
	OrderedCards        []OrderedCard          `json:"ordered_cards"`
	Archived            *bool                  `json:"archived,omitempty"`
	CanWrite            *bool                  `json:"can_write,omitempty"`
	EnableEmbedding     *bool                  `json:"enable_embedding,omitempty"`
	EmbeddingParams     map[string]interface{} `json:"embedding_params,omitempty"`
	CreatorID           *int                   `json:"creator_id,omitempty"`
	ParamFields         map[string]interface{} `json:"param_fields,omitempty"`
	ParamValues         interface{}            `json:"param_values,omitempty"`
	Parameters          []FilterParams         `json:"parameters,omitempty"`
}

type DashboardOption

type DashboardOption func(dashboard *Dashboard) (*Dashboard, error)

func ToggleDashboardEmbedding

func ToggleDashboardEmbedding(enable bool, params map[string]interface{}) DashboardOption

func WithParameter

func WithParameter(
	param FilterParams,
) DashboardOption

type Database

type Database struct {
	CommonFields
	Timezone       string                 `json:"timezone"`
	AutoRunQueries *bool                  `json:"auto_run_queries"`
	IsFullSync     *bool                  `json:"is_full_sync"`
	Details        map[string]interface{} `json:"details"`
	Engine         string                 `json:"engine"`
	Tables         []Table                `json:"tables"`
	Features       []string               `json:"features"`
}

type DbEngineSetup

type DbEngineSetup struct {
	Engine         string            `json:"engine"`
	Name           string            `json:"name"`
	Details        map[string]string `json:"details"`
	IsFullSync     *bool             `json:"is_full_sync,omitempty"`
	AutoRunQueries *bool             `json:"auto_run_queries,omitempty"`
}

type ErrorCode

type ErrorCode int
const (
	UnknownError        ErrorCode = -99
	NetworkError        ErrorCode = 1
	BadRequest          ErrorCode = 400
	Unauthorized        ErrorCode = 401
	PermissionDenied    ErrorCode = 403
	NotFound            ErrorCode = 404
	InternalServerError ErrorCode = 500
	ServiceUnavialble   ErrorCode = 503
)

type FilterParams

type FilterParams struct {
	Id      string  `json:"id"`
	Name    string  `json:"name"`
	Slug    string  `json:"slug"`
	Type    string  `json:"type"`
	Default *string `json:"default,omitempty"`
}

func MakeFilterParam

func MakeFilterParam(name string, type_ string, default_ *string) FilterParams

type InstanceSetup

type InstanceSetup struct {
	User     UserSetup     `json:"user"`
	Token    string        `json:"token"`
	Database DbEngineSetup `json:"database"`
	Pref     PrefSetup     `json:"prefs"`
}

type LineVisualizationSetting

type LineVisualizationSetting struct {
	Dimension     []string       `mapstructure:"graph.dimensions,omitempty"`
	Metrics       []string       `mapstructure:"graph.metrics,omitempty"`
	XAxis         string         `mapstructure:"graph.x_axis.title_text,omitempty"`
	YAxis         string         `mapstructure:"graph.y_axis.title_text,omitempty"`
	PivotColumn   string         `mapstructure:"table.pivot_column,omitempty"`
	CellColumn    string         `mapstructure:"table.cell_column,omitempty"`
	SeriesSetting seriesSettings `mapstructure:"series_settings,omitempty"`
}

type OrderedCard

type OrderedCard struct {
	CommonFields
	CardId                int                    `json:"card_id"`
	DashboardId           int                    `json:"dashboard_id"`
	SizeX                 int                    `json:"sizeX"`
	SizeY                 int                    `json:"sizeY"`
	Row                   int                    `json:"row"`
	Column                int                    `json:"col"`
	Series                []interface{}          `json:"series"`
	ParameterMappings     []ParamMapping         `json:"parameter_mappings"`
	VisualizationSettings map[string]interface{} `json:"visualization_settings"`
}

type ParamMapping

type ParamMapping struct {
	CardId      int           `json:"card_id"`
	ParameterId string        `json:"parameter_id"`
	Target      []interface{} `json:"target"`
}

type PrefSetup

type PrefSetup struct {
	SiteName      string `json:"site_name"`
	SiteLocale    string `json:"site_locale,omitempty"`
	AllowTracking *bool  `json:"allow_tracking,omitempty"`
}

type SessionProperties

type SessionProperties struct {
	GACode              string `json:"ga-code"`
	SiteLocale          string `json:"en"`
	ApplicationName     string `json:"application-name"`
	SiteUrl             string `json:"site-url"`
	EnablePasswordLogin bool   `json:"enable-password-login"`
	SetupToken          string `json:"setup-token"`
	EmbeddingSecretKey  string `json:"embedding-secret-key"`
	EnableEmbedding     bool   `json:"enable-embedding"`
	ShowHomePageXRays   bool   `json:"show-homepage-xrays"`
}

type Snippet

type Snippet struct {
	Name         string  `json:"name"`
	Description  *string `json:"description,omitempty"`
	Id           int     `json:"id,omitempty"`
	CollectionId *int    `json:"collection_id"`
	Content      string  `json:"content"`
}

type Table

type Table struct {
	CommonFields
	DbID        int    `json:"db_id"`
	EntityType  string `json:"entity_type"`
	Schema      string `json:"schema"`
	DisplayName string `json:"display_name"`
	Active      *bool  `json:"active"`
}

type TableField

type TableField struct {
	CommonFields
	DatabaseType           string                 `json:"database_type"`
	TableID                int                    `json:"table_id"`
	SpecialType            *string                `json:"special_type"`
	FingerprintVersion     int                    `json:"fingerprint_version"`
	HasFieldValues         string                 `json:"has_field_values"`
	FkTargetFieldID        *int                   `json:"fk_target_field_id"`
	Dimensions             []string               `json:"dimensions"`
	DimensionOptions       []string               `json:"dimension_options"`
	CustomPosition         *int                   `json:"custom_position"`
	Active                 bool                   `json:"active"`
	ParentID               *int                   `json:"parent_id"`
	LastAnalyzed           *string                `json:"last_analyzed"`
	Position               *int                   `json:"position"`
	VisibilityType         *string                `json:"visibility_type"`
	DefaultDimensionOption *string                `json:"default_dimension_option"`
	PreviewDisplay         bool                   `json:"preview_display"`
	DisplayName            string                 `json:"display_name"`
	DatabasePosition       int                    `json:"database_position"`
	Fingerprint            map[string]interface{} `json:"fingerprint"`
	BaseType               *string                `json:"base_type"`
}

type TableWithMetadata

type TableWithMetadata struct {
	Table
	Fields []TableField `json:"fields"`
}

type UserSetup

type UserSetup struct {
	FirstName string `json:"first_name"`
	LastName  string `json:"last_name"`
	Email     string `json:"email"`
	Password  string `json:"password"`
}

Jump to

Keyboard shortcuts

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