A Go client library for working with the ClearBlade Platform
Clone or download
Latest commit 8ae1f66 Dec 5, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore Added code to allow for using queries when updating or deleting devices Nov 9, 2017
LICENSE Initial commit Oct 8, 2014
README.md Update README.md Oct 26, 2018
adaptorcalls.go moved get contents for file to separate function Oct 10, 2017
admincalls.go add old admin endpoints Nov 18, 2018
assetcalls.go Merge branch 'master' of https://github.com/clearblade/Go-SDK Feb 14, 2018
autodeletion.go Last bit for Autodeletion API Nov 19, 2018
codeadmin.go added setLongRunningServiceParams Oct 22, 2018
codecalls.go Merge branch 'master' of https://github.com/clearblade/Go-SDK into ne… Mar 2, 2018
connect.go added mongo to connect collections Nov 5, 2018
datacalls.go add systemKey suffix to all collections call Feb 22, 2018
devcalls.go removed debug print Nov 7, 2018
devicecalls.go added session rest api funcs Oct 15, 2018
edgecalls.go added adapter root dir flag to edge config Jul 19, 2018
edgegroupcalls.go tweaks to get a scenetest build working -- added CreateDeploymentByName Nov 15, 2017
eventcalls.go removed debug prints Nov 20, 2018
librarycalls.go Lotsa changes so that the sdk now handles multiple connections to nov… May 13, 2016
mdevcalls.go Added multiple developers per system calls Sep 14, 2016
metriccalls.go remove edge specific calls Sep 20, 2017
mqtt.go removed debug prints Nov 20, 2018
plugincalls.go Admin portal updates (#39) Nov 2, 2018
portalcalls.go added return to end of function Sep 15, 2017
provisioningcalls.go removed debug prints Nov 20, 2018
query.go query documentation Aug 19, 2015
usercalls.go Autodeletion test bits Nov 16, 2018
utils.go using forked paho now Jul 24, 2018

README.md

Go-SDK

API Reference

Setup

newUserClient(systemkey, systemsecret, email, password string) *UserClient

	systemKey // string
		Required. The systemKey of the system to connect to. Retrievable from the Console's System Settings.
	systemSecret // string
		Required. The systemSecret of the system to connect to. Retrievable from the Console's System Settings.
	email // string
		Email of non-dev user to connect to system as. If registerUser key is not provided, the user must be registered through the Auth tab of the console, and given appropriate roles.
	password // string
		Password of non-dev user to connect to system as.

Authentication

userClient.Authenticate() error

Authenticates credentials set on userClient and sets session token

userClient.Register(username, password string) error

Register a new user with the platform.

	username // string
		Email of the new user
	password // string
		Password of the new user

userClient.RegisterUser(username, password string) (map[string]interface{}, error)

Register a new user with the platform, and return response with token

	username // string
		Email of the new user
	password // string
		Password of the new user

userClient.Logout() error

End session for current user

Data

userClient.InsertData(collection_id string, data interface{}) error

Insert new item in the collection

	collection_id // string
		ID assigned to the collection by the system
	data // interface
		Representatation of data object to be inserted

userClient.CreateData(collection_id string, data interface{}) ([]interface{}, error)

Insert new item in the collection and return the response

	collection_id // string
		ID assigned to the collection by the system
	data // interface
		Representation of data object to be inserted

userClient.GetData(collectionId string, query *GoSDK.Query) (map[string]interface{}, error)

Retrieve array of items from the collection using the collection ID

	collectionId // string
		ID assigned to the collection by the system
	query // *GoSDK.Query
		Custom query created using this SDK

userClient.GetDataByName(collectionName string, query *GoSDK.Query) (map[string]interface{}, error)

Retrieve array of items from the collection using the collection name

	collectionName // string
		Name assigned to the collection by the developer
	query // *GoSDK.Query
		Custom query created using this SDK

userClient.UpdateData(collection_id string, query *GoSDK.Query, changes map[string]interface{}) error

Updates existing items in the collection that match the provided query

	collectionId // string
		ID assigned to the collection by the system
	query // *GoSDK.Query
		Custom query created using this SDK
	changes // map[string]interface{}
		Key-value pairs representing column names to be updated and new values

userClient.DeleteData(collection_id string, query *GoSDK.Query) error

Removes every item in the collection that match the provided query

	collectionId // string
		ID assigned to the collection by the system
	query // *GoSDK.Query
		Custom query created using this SDK

userClient.GetColumns(collection_id string) ([]interface{}, error)

Retrieves column names, types and primary keys for a collection

	collectionId // string
		ID assigned to the collection by the system

Queries

query := NewQuery() *GoSDK.Query

Returns new Query to be used in Data operations

query.EqualTo(field string, value interface{})

Select where field is equal to value

	field // string
		Field / column name in collection
	value // interface{}
		Data to match in field

query.GreaterThan(field string, value interface{})

Select where field is > to value

	field // string
		Field / column name in collection
	value // interface{}
		Data to match in field

query.GreaterThanEqualTo(field string, value interface{})

Select where field is >= to value

	field // string
		Field / column name in collection
	value // interface{}
		Data to match in field

query.LessThan(field string, value interface{})

Select where field is < to value

	field // string
		Field / column name in collection
	value // interface{}
		Data to match in field

query.LessThanEqualTo(field string, value interface{})

Select where field is <= to value

	field // string
		Field / column name in collection
	value // interface{}
		Data to match in field

query.NotEqualTo(field string, value interface{})

Select where field is != to value

	field // string
		Field / column name in collection
	value // interface{}
		Data to match in field

query.Matches(field string, value interface{})

Query where field is ~ than value using regex

	field // string
		Field / column name in collection
	value // interface{}
		Data to match in field

query.Or(orQuery *GoSDK.Query)

Join two queries together with OR condition

	orQuery // *GoSDK.Query
		Second GoSDk.Query

Code Services

userClient.CallService(systemKey, name string, params map[string]interface{}) (map[string]interface{}, error)

Run a named code service that exists on the system with options, and returns the response object or an error

	systemKey // string
		Key to system that contains desired code service
	name // string
		Name of code service to be executed
	params // map[string]interface{}
		Request object to be passed to code service function on execution

Messaging

userClient.InitializeMQTT(clientid string, ignore string, timeout int) error

Set required MQTT options on user client

	clientid // string
		MQTT client id
	ignore // string
		Not used, default to ""
	timeout // int
		Timeout value for MQTT client in Seconds

userClient.ConnectMQTT(ssl *tls.Config, lastWill *GoSDK.LastWillPacket) error

Establish MQTT connection for set user

	clientid // *tls.Config,
	lastWill // *GoSDK.LastWillPacket, 

userClient.Publish(topic string, message []byte, qos int) error

Publish message on MQTT topic

	topic // string
		MQTT topic to publish on
	message // []byte
		Byte-seralized message
	qos // int
		QOS priority for message

userClient.Subscribe(topic string, qos int) (<-chan *mqtt.Publish, error)

Asynchronoulsy subscribe to MQTT topic and push messages onto channel as they arrive

	topic // string
		MQTT topic to subscribe
	qos // int
		QOS priority for message

userClient.Unsubscribe(topic string) error

Stop subscription to MQTT topic

	topic // string
		MQTT topic to unsusbcribe

userClient.Disconnect() error

End MQTT connection for set user

QuickStart

Download and Install Go

Follow the instructions for downloading and installing Go from https://golang.org/doc/install

Clone the ClearBlade Go-SDK repository

Do a git clone https://github.com/ClearBlade/Go-SDK.git to clone the Go-SDK for the ClearBlade Platform.

Import the Go-SDK package in your project

In order to use the Go-SDK in your project, you will need to import the Go-SDK package that you cloned from github, in your project.

GoDoc

The GoDoc for the Go API can be found at https://docs.clearblade.com/v/3/static/goapi/pkg/github.com/clearblade/Go-SDK/index.html