mnubo

package
v0.0.0-...-db06e5a Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2020 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultTimeout = time.Second * 10

	DefaultBackoffMaxInterval = time.Minute * 5
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AccessToken

type AccessToken struct {
	Value     string `json:"access_token"`
	TokenType string `json:"token_type"`
	ExpiresIn int    `json:"expires_in"`
	ExpiresAt time.Time
	Scope     string `json:"scope"`
	Jti       string `json:"jti"`
}

AccessToken represents a token obtained after validating client id and secret.

type AttributeType

type AttributeType struct {
	HighLevelType string `json:"highLevelType"`
	ContainerType string `json:"containerType"`
}

type ChallengeCode

type ChallengeCode struct {
	Code string `json:"code"`
}

type ClaimResult

type ClaimResult struct {
	ID      string `json:"id"`
	Result  string `json:"result"`
	Message string `json:"message"`
}

ClaimResult contains useful information after claiming obects.

type ClientRequest

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

ClientRequest is an internal structure to help with making HTTP requests to SmartObjects.

type CompressionConfig

type CompressionConfig struct {
	Request  bool
	Response bool
}

CompressionConfig is used to compress requests and / or response to / from the SmartObjects platform.

type DataModel

type DataModel struct {
	ObjectTypes     []ObjectType     `json:"objectTypes"`
	EventTypes      []EventType      `json:"eventTypes"`
	OwnerAttributes []OwnerAttribute `json:"ownerAttributes"`
	Sessionizers    []Sessionizer    `json:"sessionizers"`
	Orphans         struct {
		Timeseries []Timeseries `json:"timeseries"`
	} `json:"orphans,omitempty"`
	Enrichers               map[string][]string `json:"enrichers,omitempty"`
	ReservedEnrichersFields []string            `json:"reservedEnrichersFields,omitempty"`
}

type Dataset

type Dataset struct {
	Key         string      `json:"key"`
	Description interface{} `json:"description"`
	DisplayName string      `json:"displayName"`
	Fields      []struct {
		Key           string `json:"key"`
		HighLevelType string `json:"highLevelType"`
		DisplayName   string `json:"displayName"`
		Description   string `json:"description"`
		ContainerType string `json:"containerType"`
		PrimaryKey    bool   `json:"primaryKey"`
	} `json:"fields"`
}

Dataset is the main structure used to make queries to SmartObjects. Its key represent the "From" to use when making queries.

type EntitiesExist

type EntitiesExist map[string]bool

EntitiesExist is an array of map useful when checking if events, objects or owners exist.

type EventType

type EventType struct {
	Key            string       `json:"key"`
	DisplayName    string       `json:"displayName"`
	Description    string       `json:"description"`
	Origin         string       `json:"origin"`
	TimeseriesKeys []string     `json:"timeseriesKeys,omitempty"`
	Timeseries     []Timeseries `json:"timeseries,omitempty"`
}

type Events

type Events struct {
	Mnubo *Mnubo
}

Events is a helper to Mnubo client which contains Events related functions.

func NewEvents

func NewEvents(m *Mnubo) *Events

NewEvents creates an Events wrapper for Mnubo client.

func (*Events) Exists

func (e *Events) Exists(eventIds []string, results *EntitiesExist) error

Exists checks if an event has already been submitted. See: https://smartobjects.mnubo.com/documentation/api_ingestion.html#post-api-v3-events-exists

func (*Events) Send

func (e *Events) Send(events interface{}, options SendEventsOptions, results interface{}) error

Send allows to post events to SmartObjects. The events payload depends on the data model. See: https://smartobjects.mnubo.com/documentation/api_ingestion.html#post-api-v3-events

func (*Events) SendFromDevice

func (e *Events) SendFromDevice(deviceId string, events interface{}, options SendEventsOptions, results interface{}) error

SendFromDevice allows to post events to SmartObjects from one device. See: https://smartobjects.mnubo.com/documentation/api_ingestion.html#post-api-v3-objects-x-device-id-events

type ExponentialBackoffConfig

type ExponentialBackoffConfig struct {
	// After MaxElapsedTime the ExponentialBackOff stops.
	// It never stops if MaxElapsedTime == 0.
	MaxElapsedTime time.Duration
	// Callback called between retries when the platform is not available.
	// It will not be called if value is nil.
	NotifyOnError func(error, time.Duration)
}

ExponentialBackoffConfig is used to configure exponential backoff. You should not need to configure this, but it's available if you require further tweaking.

type Mnubo

type Mnubo struct {
	ClientId           string
	ClientSecret       string
	ClientToken        string
	Host               string
	AccessToken        AccessToken
	Timeout            time.Duration // Timeout for HTTP requests sent to SmartObjects.
	Compression        CompressionConfig
	ExponentialBackoff ExponentialBackoffConfig
	Model              *Model
	Events             *Events
	Objects            *Objects
	Owners             *Owners
	Search             *Search
	CustomTransport    *http.Transport
}

Mnubo is the main object representing all available endpoints in SmartObjects.

func NewClient

func NewClient(id string, secret string, host string) *Mnubo

NewClient creates a new Mnubo structure based on id, secret and host.

func NewClientWithToken

func NewClientWithToken(token string, host string) *Mnubo

NewClientWithToken creates a new Mnubo structure based on a static token.

func (*Mnubo) GetAccessToken

func (m *Mnubo) GetAccessToken() (AccessToken, error)

GetAccessToken fetches a new AccessToken with scope ALL.

func (*Mnubo) GetAccessTokenWithScope

func (m *Mnubo) GetAccessTokenWithScope(scope string) (AccessToken, error)

GetAccessTokenWithScope fetches a new AccessToken with specified scope.

type Model

type Model struct {
	Mnubo *Mnubo
}

Model is a helper to Mnubo client which contains Model related functions.

func NewModel

func NewModel(m *Mnubo) *Model

func (*Model) AddEventTypeRelation

func (m *Model) AddEventTypeRelation(typeKey string, entityKey string) error

Add a relation to a timeseries. See: https://smartobjects.mnubo.com/documentation/api_modeler.html#linking-a-timeseries-to-an-event-type

func (*Model) AddObjectTypeRelation

func (m *Model) AddObjectTypeRelation(typeKey string, entityKey string) error

Add a relation to an object attribute. See: https://smartobjects.mnubo.com/documentation/api_modeler.html#linking-an-attribute-to-an-object-type

func (*Model) ApplyObjectAttributeDeployCode

func (m *Model) ApplyObjectAttributeDeployCode(key string, cc ChallengeCode) error

ApplyObjectAttributeDeployCode applies the challenge code to deploy the attribute to production. See: https://smartobjects.mnubo.com/documentation/api_modeler.html#id11

func (*Model) ApplyOwnerAttributeDeployCode

func (m *Model) ApplyOwnerAttributeDeployCode(key string, cc ChallengeCode) error

ApplyOwnerAttributeDeployCode applies the challenge code to deploy the attribute to production. See: https://smartobjects.mnubo.com/documentation/api_modeler.html#id11

func (*Model) ApplyResetCode

func (m *Model) ApplyResetCode(cc ChallengeCode) error

ApplyResetCode sends the reset code for sandbox reset (if the code is valid). See: https://smartobjects.mnubo.com/documentation/api_modeler.html#part-2-using-the-code

func (*Model) ApplyTimeseriesDeployCode

func (m *Model) ApplyTimeseriesDeployCode(key string, cc ChallengeCode) error

ApplyTimeseriesDeployCode applies the challenge code to deploy the timeseries to production. See: https://smartobjects.mnubo.com/documentation/api_modeler.html#part-2-challenging-code

func (*Model) CreateEventTypes

func (m *Model) CreateEventTypes(et []EventType) error

CreateEventTypes creates an array of event types in the data model. See: https://smartobjects.mnubo.com/documentation/api_modeler.html#creating-event-types

func (*Model) CreateObjectAttributes

func (m *Model) CreateObjectAttributes(oa []ObjectAttribute) error

CreateObjectAttributes creates new object attribute. See: https://smartobjects.mnubo.com/documentation/api_modeler.html#creating-object-attributes

func (*Model) CreateObjectTypes

func (m *Model) CreateObjectTypes(ot []ObjectType) error

CreateObjectTypes creates an array of object types in the data model. See: https://smartobjects.mnubo.com/documentation/api_modeler.html#creating-object-types

func (*Model) CreateOwnerAttributes

func (m *Model) CreateOwnerAttributes(oa []OwnerAttribute) error

CreateOwnerAttributes creates new owner attribute. See: https://smartobjects.mnubo.com/documentation/api_modeler.html#creating-object-attributes

func (*Model) CreateTimeseries

func (m *Model) CreateTimeseries(ts []Timeseries) error

CreateTimeseries creates new timeseries to the data model. See: https://smartobjects.mnubo.com/documentation/api_modeler.html#creating-timeseries

func (*Model) DeleteEventType

func (m *Model) DeleteEventType(key string) error

DeleteEventType deletes an event type from the data model. See: https://smartobjects.mnubo.com/documentation/api_modeler.html#deleting-an-event-type

func (*Model) DeleteObjectType

func (m *Model) DeleteObjectType(key string) error

DeleteObjectType deletes an object type from the data model. See: https://smartobjects.mnubo.com/documentation/api_modeler.html#deleting-an-object-type

func (*Model) DeployObjectAttributeToProduction

func (m *Model) DeployObjectAttributeToProduction(key string) error

DeployObjectAttributeToProduction deploys an object attribute created in sandbox to production. Making calls to GenerateObjectAttributeDeployCode and ApplyObjectAttributeDeployCode. See: https://smartobjects.mnubo.com/documentation/api_modeler.html#deploying-an-object-attribute-into-production

func (*Model) DeployOwnerAttributeToProduction

func (m *Model) DeployOwnerAttributeToProduction(key string) error

DeployOwnerAttributeToProduction deploys an owner attribute created in sandbox to production. Making calls to GenerateOwnerAttributeDeployCode and ApplyOwnerAttributeDeployCode. See: https://smartobjects.mnubo.com/documentation/api_modeler.html#deploying-an-object-attribute-into-production

func (*Model) DeployTimeseriesToProduction

func (m *Model) DeployTimeseriesToProduction(key string) error

DeployTimeseriesToProduction deploys a timeseries created in sandbox to production. Making calls to GenerateTimeseriesDeployCode and ApplyTimeseriesDeployCode. See: https://smartobjects.mnubo.com/documentation/api_modeler.html#deploying-a-timeseries-into-production

func (*Model) Export

func (m *Model) Export(results *DataModel) error

Export dumps a JSON object representing the current data model. See: https://smartobjects.mnubo.com/documentation/api_modeler.html#exporting-your-data-model

func (*Model) GenerateObjectAttributeDeployCode

func (m *Model) GenerateObjectAttributeDeployCode(key string, results *ChallengeCode) error

GenerateObjectAttributeDeployCode generates a new challenge code before deploying an object attribute to production. See: https://smartobjects.mnubo.com/documentation/api_modeler.html#id10

func (*Model) GenerateOwnerAttributeDeployCode

func (m *Model) GenerateOwnerAttributeDeployCode(key string, results *ChallengeCode) error

GenerateOwnerAttributeDeployCode generates a new challenge code before deploying an owner attribute to production. See: https://smartobjects.mnubo.com/documentation/api_modeler.html#id10

func (*Model) GenerateResetCode

func (m *Model) GenerateResetCode(results *ChallengeCode) error

GenerateResetCode generates a new code that must be used in order to reset a data model in sandbox. See: https://smartobjects.mnubo.com/documentation/api_modeler.html#resetting-your-sandbox-data-model

func (*Model) GenerateTimeseriesDeployCode

func (m *Model) GenerateTimeseriesDeployCode(key string, results *ChallengeCode) error

GenerateTimeseriesDeployCode generates a new challenge code before deploying a timeseries to production. See: https://smartobjects.mnubo.com/documentation/api_modeler.html#part-1-getting-code

func (*Model) GetEventTypes

func (m *Model) GetEventTypes(results *[]EventType) error

GetEventTypes retrieves the event types of the data model. See: https://smartobjects.mnubo.com/documentation/api_modeler.html#getting-all-event-types

func (*Model) GetObjectAttributes

func (m *Model) GetObjectAttributes(results *[]ObjectAttribute) error

GetObjectAttributes retrieves the object attributes of the data model. See: https://smartobjects.mnubo.com/documentation/api_modeler.html#getting-all-object-attributes

func (*Model) GetObjectTypes

func (m *Model) GetObjectTypes(results *[]ObjectType) error

GetObjectTypes retrieves the object types of the data model. See: https://smartobjects.mnubo.com/documentation/api_modeler.html#getting-all-event-types

func (*Model) GetOwnerAttributes

func (m *Model) GetOwnerAttributes(results *[]OwnerAttribute) error

GetOwnerAttributes retrieves the owner attributes of the data model. See: https://smartobjects.mnubo.com/documentation/api_modeler.html#getting-all-owner-attributes

func (*Model) GetTimeseries

func (m *Model) GetTimeseries(results *[]Timeseries) error

GetTimeseries retrieves the timeseries of the data model. See: https://smartobjects.mnubo.com/documentation/api_modeler.html#getting-all-timeseries

func (*Model) RemoveEventTypeRelation

func (m *Model) RemoveEventTypeRelation(typeKey string, entityKey string) error

Remove a relation to a timeseries. See: https://smartobjects.mnubo.com/documentation/api_modeler.html#deleting-the-link-between-a-timeseries-and-an-event-type

func (*Model) RemoveObjectTypeRelation

func (m *Model) RemoveObjectTypeRelation(typeKey string, entityKey string) error

Remove a relation to an object attribute. See: https://smartobjects.mnubo.com/documentation/api_modeler.html#deleting-the-link-between-an-attribute-and-an-object-type

func (*Model) ResetDataModel

func (m *Model) ResetDataModel() error

ResetDataModel performs both GenerateResetCode and ApplyResetCode at the same time for convenience.

func (*Model) UpdateEventType

func (m *Model) UpdateEventType(key string, et EventType) error

UpdateEventType updates an event type in the data model. See: https://smartobjects.mnubo.com/documentation/api_modeler.html#updating-an-event-type

func (*Model) UpdateObjectAttribute

func (m *Model) UpdateObjectAttribute(key string, oa ObjectAttribute) error

UpdateObjectAttribute updates the DisplayName and Description (only those) from an object attribute. See: https://smartobjects.mnubo.com/documentation/api_modeler.html#updating-an-object-attribute

func (*Model) UpdateObjectType

func (m *Model) UpdateObjectType(key string, ot ObjectType) error

UpdateObjectType updates an object type in the data model. See: https://smartobjects.mnubo.com/documentation/api_modeler.html#updating-an-object-type

func (*Model) UpdateOwnerAttribute

func (m *Model) UpdateOwnerAttribute(key string, oa OwnerAttribute) error

UpdateOwnerAttribute updates the DisplayName and Description (only those) from an owner attribute. See: https://smartobjects.mnubo.com/documentation/api_modeler.html#updating-an-object-attribute

func (*Model) UpdateTimeseries

func (m *Model) UpdateTimeseries(key string, ts Timeseries) error

UpdateTimeseries updates the DisplayName and Description (only those) from a Timeseries. See: https://smartobjects.mnubo.com/documentation/api_modeler.html#updating-timeseries

type ObjectAttribute

type ObjectAttribute struct {
	Key            string        `json:"key"`
	DisplayName    string        `json:"displayName"`
	Description    string        `json:"description"`
	Type           AttributeType `json:"type,omitempty"`
	ObjectTypeKeys []string      `json:"objectTypeKeys,omitempty"`
}

type ObjectOwnerPair

type ObjectOwnerPair struct {
	XDeviceID string `json:"x_device_id"`
	Username  string `json:"username"`
}

ObjectOwnerPair can be used to claim and unclaim devices.

type ObjectType

type ObjectType struct {
	Key                  string            `json:"key"`
	DisplayName          string            `json:"displayName"`
	Description          string            `json:"description"`
	ObjectAttributesKeys []string          `json:"objectAttributesKeys,omitempty"`
	ObjectAttributes     []ObjectAttribute `json:"objectAttributes,omitempty"`
}

type Objects

type Objects struct {
	Mnubo *Mnubo
}

Objects is a helper to Mnubo client which contains Objects related functions.

func NewObjects

func NewObjects(m *Mnubo) *Objects

NewObjects creates an Objects wrapper for Mnubo client.

func (*Objects) Create

func (o *Objects) Create(objects interface{}, results interface{}) error

Create creates an object to SmartObjects. The objects payload is based on the data model. See: https://smartobjects.mnubo.com/documentation/api_ingestion.html#post-api-v3-objects

func (*Objects) Exist

func (o *Objects) Exist(deviceIds []string, results *EntitiesExist) error

Exist checks if an array of objects have been created. See: https://smartobjects.mnubo.com/documentation/api_ingestion.html#post-api-v3-objects-exists

func (*Objects) Update

func (o *Objects) Update(objects interface{}, results interface{}) error

Update creates and / or updates a batch of objects at once. See: https://smartobjects.mnubo.com/documentation/api_ingestion.html#put-api-v3-objects-batch

type OwnerAttribute

type OwnerAttribute struct {
	Key         string        `json:"key"`
	DisplayName string        `json:"displayName"`
	Description string        `json:"description"`
	Type        AttributeType `json:"type"`
}

type Owners

type Owners struct {
	Mnubo *Mnubo
}

Owners is a helper to Mnubo client which contains Owners related functions.

func NewOwners

func NewOwners(m *Mnubo) *Owners

NewOwners creates an Owners wrapper for Mnubo client.

func (*Owners) Claim

func (o *Owners) Claim(pairs []ObjectOwnerPair, results *[]ClaimResult) error

Claim claims an array of object / owner pair. See: https://smartobjects.mnubo.com/documentation/api_ingestion.html#post-api-v3-owners-claim-batch

func (*Owners) Create

func (o *Owners) Create(owners interface{}, results interface{}) error

Create creates a new owner to SmartObjects. The owner payload is based on the data model. See: https://smartobjects.mnubo.com/documentation/api_ingestion.html#post-api-v3-owners

func (*Owners) Delete

func (o *Owners) Delete(username string) error

Delete deletes an owner from SmartObjects. See: https://smartobjects.mnubo.com/documentation/api_ingestion.html#delete-api-v3-owners-username

func (*Owners) Exist

func (o *Owners) Exist(usernames []string, results *EntitiesExist) error

Exist checks if an array of owners exist in SmartObjects. See: https://smartobjects.mnubo.com/documentation/api_ingestion.html#get-api-v3-owners-exists-username

func (*Owners) Unclaim

func (o *Owners) Unclaim(pairs []ObjectOwnerPair, results *[]ClaimResult) error

Unclaim unclaims an array of object / owner pair. See: https://smartobjects.mnubo.com/documentation/api_ingestion.html#post-api-v3-owners-unclaim-batch

func (*Owners) Update

func (o *Owners) Update(owners interface{}, results interface{}) error

Update creates and / or updates a batch of owners at once. See: https://smartobjects.mnubo.com/documentation/api_ingestion.html#put-api-v3-owners-batch

func (*Owners) UpdateOwnerPassword

func (o *Owners) UpdateOwnerPassword(username string, password string) error

UpdateOwnerPassword updates an owner password. See: https://smartobjects.mnubo.com/documentation/api_ingestion.html#put-api-v3-owners-username-password

type PasswordUpdatePayload

type PasswordUpdatePayload struct {
	XPassword string `json:"x_password"`
}

PasswordUpdatePayload helps building the update password function.

type QueryValidation

type QueryValidation struct {
	IsValid          bool     `json:"isValid"`
	ValidationErrors []string `json:"validationErrors"`
}

QueryValidation is a helper structure that contains useful information about MQL queries validity.

type Search struct {
	Mnubo *Mnubo
}

Search is a helper to Mnubo client which contains Search related functions.

func NewSearch

func NewSearch(m *Mnubo) *Search

NewSearch creates a Search wrapper for Mnubo client.

func (*Search) CreateBasicQuery

func (s *Search) CreateBasicQuery(mql interface{}, results interface{}) error

CreateBasicQuery is the main function to make analytics queries to SmartObjects. Its mql data structure varies depending on the data model. This method trust the user will use the proper structure based on its model. See: https://smartobjects.mnubo.com/documentation/api_search.html#basic

func (*Search) CreateBasicQueryWithBytes

func (s *Search) CreateBasicQueryWithBytes(mql []byte, results interface{}) error

CreateBasicQueryWithString is a helper to use an array of bytes.

func (*Search) CreateBasicQueryWithString

func (s *Search) CreateBasicQueryWithString(mql string, results interface{}) error

CreateBasicQueryWithString is a helper to use a string instead of creating a dedicated structure.

func (*Search) GetDatasets

func (s *Search) GetDatasets(results *[]Dataset) error

GetDatasets returns an array of SmartObjects datasets to perform queries.

func (*Search) ValidateQuery

func (s *Search) ValidateQuery(mql interface{}, results *QueryValidation) error

ValidateQuery is the main function to use to understand why an MQL query is not valid. See: https://smartobjects.mnubo.com/documentation/api_search.html#validate

func (*Search) ValidateQueryWithBytes

func (s *Search) ValidateQueryWithBytes(mql []byte, results *QueryValidation) error

ValidateQueryWithBytes is a helper that allows to send bytes.

func (*Search) ValidateQueryWithString

func (s *Search) ValidateQueryWithString(mql string, results *QueryValidation) error

ValidateQueryWithString is a helper that allows to send a string instead of creating a dedicated structure.

type SearchResults

type SearchResults struct {
	Columns []SearchResultsColumn `json:"columns"`
	Rows    [][]interface{}       `json:"rows"`
}

SearchResults is the main structure that contain results after a valid query has been sent.

type SearchResultsColumn

type SearchResultsColumn struct {
	Label string `json:"label"`
	Type  string `json:"type"`
}

SearchResultsColumn is the definition of the a SearchResults column.

type SendEventsOptions

type SendEventsOptions struct {
	ReportResults    bool
	ObjectsMustExist bool
}

SendEventsOptions helps configure the Send events function.

type SendEventsReport

type SendEventsReport struct {
	ID           string `json:"id"`
	Result       string `json:"result"`
	ObjectExists bool   `json:"objectExists"`
}

SendEventsReport contains information when sending events with ReportResults set to true.

type Sessionizer

type Sessionizer struct {
	Key               string `json:"key"`
	DisplayName       string `json:"displayName"`
	Description       string `json:"description"`
	StartEventTypeKey string `json:"startEventTypeKey"`
	EndEventTypeKey   string `json:"endEventTypeKey"`
}

type Timeseries

type Timeseries struct {
	Key           string         `json:"key,omitempty"`
	DisplayName   string         `json:"displayName"`
	Description   string         `json:"description"`
	EventTypeKeys []string       `json:"eventTypeKeys,omitempty"`
	Type          TimeseriesType `json:"type,omitempty"`
}

type TimeseriesType

type TimeseriesType struct {
	HighLevelType string `json:"highLevelType"`
}

Jump to

Keyboard shortcuts

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