revolt

package module
v0.0.0-...-0f50425 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2018 License: Apache-2.0 Imports: 9 Imported by: 0

README

Revolt Golang SDK

Go SDK for event tracking with Revolt.

Installation

Use the go command:

go run -u bitbucket.org/miquido/revolt-sdk-go

Creating events

Event can be created with revolt.NewEvent() method.

Using struct

Example:

revolt.NewEvent("test.event.type", struct {
    UserId       int    `json:"userId"`
    CreationType string `json:"creationType"`
    Description  string `json:"description"`
}{
    UserId:       1,
    CreationType: "webbapp.test",
    Description:  "short description",
})

When using struct{} don't forget to set explicit json tags for format purposes.

Using map

Example:

revolt.NewEvent("test.event.type",
    map[string]interface{}{
        "userId": 5,
        "description": "short description",
    },
)

Example

Example usage

client, err := revolt.NewClient("trackingId", "app.code", "secret")
if err != nil {
    panic(err)
}

event, err := revolt.NewEvent("test.event.type", struct {
	UserId       int    `json:"userId"`
}{
	UserId:       1,
})

event2, err := revolt.NewEvent("test.event.type",
	map[string]interface{}{
		"userId": 5,
	},
)


resp, err := client.SendEvents([]revolt.Event{event, event2})

Async event sending

For async event sending use channels and goroutines.

Custom Parameters

There are few parameters which will be supported soon:

  • endpoint - Specifies endpoint on which communication with Revolt service should take place.
  • maxBatchSize - Specifies maximum batch size of events that can be sent to Revolt API.
  • eventDelayMillis - Specifies maximum number of seconds for Event to be stored in queue. After delay is up, all events in queue will be sent automatically.
  • offlineMaxSize - Specifies maximum size of events that can be stored in queue when service does not respond.
  • retryIntervalSecs - Specifies first time interval in seconds to retry sending batch of events when any error occurs.
  • maxRetryIntervalSecs - Specifies maximum time interval in seconds to retry sending batch of events when any error occurs.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrApiEndpoint = errors.New("API endpoint cannot be empty")
View Source
var ErrClientCode = errors.New("Client code cannot be empty")
View Source
var ErrEventData = errors.New("Event data cannot be nil")
View Source
var ErrEventType = errors.New("Event type cannot be empty")
View Source
var ErrMaxBatchSize = errors.New("Max batch size cannot bet set to 0 seconds")
View Source
var ErrMaxRetryInterval = errors.New("Max retry interval cannot exceed 300 seconds")
View Source
var ErrRetryInterval = errors.New("Retry interval cannot bet set to 0 seconds")
View Source
var ErrSecretKey = errors.New("Secret key cannot be empty")
View Source
var ErrTrackingId = errors.New("Tracking id cannot be empty")

Functions

This section is empty.

Types

type Client

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

Client is an Revolt API client. It can be configured in NewClient via ClientConfig fun

func NewClient

func NewClient(trackingId, appCode, secret string, opts ...ClientConfig) (*Client, error)

NewClient returns an Revolt Client for use communicating with a Revolt service API configured with the given ClientConfig.

func (*Client) NewEvent

func (c *Client) NewEvent(eventType string, data interface{}) (Event, error)

NewEvent is a clients method wrapper around NewEvent function. It creates a new Event instance.

func (*Client) SendEvent

func (c *Client) SendEvent(event Event) (*http.Response, error)

SendEvent Sends an Event to Revolt API.

func (*Client) ServiceResponseFromHTTP

func (c *Client) ServiceResponseFromHTTP(response *http.Response) (*ServiceResponse, error)

ServiceResponseFromHTTP is a clients method wrapper around ServiceResponseFromHTTP function. It extracts Revolt service response from an http response.

type ClientConfig

type ClientConfig func(c *Client)

func WithCustomClient

func WithCustomClient(httpClient *http.Client) ClientConfig

Specifies Client used to communication with Revolt service.

func WithEndpoint

func WithEndpoint(endpoint string) ClientConfig

Specifies endpoint on which communication with Revolt service should take place.

type Event

type Event struct {
	Meta Meta        `json:"meta"`
	Data interface{} `json:"data"`
}

Event is a representation of a message sent to Revolt API

func NewEvent

func NewEvent(eventType string, data interface{}) (Event, error)

NewEvent creates a new instance of a Event with given type and embedded data.

type Meta

type Meta struct {
	ID        string `json:"id"`
	Type      string `json:"type"`
	Timestamp int64  `json:"timestamp"`
}

Meta is a representation of Meta tags

type ServiceResponse

type ServiceResponse struct {
	EventsAccepted int `json:"eventsAccepted"`
	EventError     *struct {
		EventOffset  int         `json:"eventOffset"`
		EventId      interface{} `json:"eventId"`
		ErrorCode    int         `json:"errorCode"`
		ErrorMessage string      `json:"errorMessage"`
	} `json:"eventError"`
}

ServiceResponse represents a response from Revolt service

func ServiceResponseFromHTTP

func ServiceResponseFromHTTP(response *http.Response) (*ServiceResponse, error)

ServiceResponseFromHTTP extracts Revolt service struct response from an http response.

Jump to

Keyboard shortcuts

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