rex

package module
v0.0.0-...-59827dc Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2018 License: MIT Imports: 15 Imported by: 1

README

REX Golang package

This repository contains a client-side implementation for accessing REX, the cloud-based augmented reality operating system. You can find more information about REX here.

Getting REX

Just go get it:

go get github.com/breiting/rex

Getting started

The first thing you have to do is to register for a free REX account. Once you activated your account, you can simply create an API access token with a ClientId and a ClientSecret.

This that information in your pocket, you can start building your REX-enabled application. An example application is called rx which is a command line tool accessing the REX system.

Application using rex

There is a command line CLI tool called rx which uses this library. Please have a look and fork the project.

Documentation

Overview

Package rex provides a library for accessing the REX API. REX is a cloud-based operating system for building augmented reality applications.

The first thing you have to do is to register at https://rex.robotic-eyes.com for a free REX account. Once you activated your account, you can simply create an API access token with a `ClientId` and a `ClientSecret`.

This that information in your pocket, you can start building your REX-enabled application. An example application is called rx (https://github.com/breiting/rx) which is a command line tool accessing the REX system.

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	RexBaseURL = "https://rex.robotic-eyes.com" // hostname for accessing REX cloud services
)

Global variables

Functions

func CreateProject

func CreateProject(e Executor, userID, name string, address *ProjectAddress, absoluteTransformation *ProjectTransformation) error

CreateProject creates a new project for the current user.

The name is used as project name

func DownloadFile

func DownloadFile(e Executor, link string) error

DownloadFile downloads a given link (e.g. project file link).

The file name is anticipated by the provided information from the server using the content-disposition

func GetTotalNumberOfUsers

func GetTotalNumberOfUsers(e Executor) (uint64, error)

GetTotalNumberOfUsers returns the number of registered users.

Requires admin permissions!

func UploadProjectFile

func UploadProjectFile(e Executor, projectID string, name string, fileName string, transform *FileTransformation, r io.Reader) error

UploadProjectFile uploads a new project file.

The project is identified by the projectID (e.g. 1020). The file requires a name, which is displayed, but also a fileName which includes the suffix. The fileName is used for detecting the mimetype. The content of the file will be read from the io.Reader r.

Types

type Client

type Client struct {
	User  *User        // Stores the user information
	Token oauth2.Token // Contains the authentication token
	// contains filtered or unexported fields
}

Client stores all user relevant information. The client holds the authentication token but also the user information such as username, email, and some more.

To create a new client you simply use the following code

client :=  NewClient(nil)
err := client.Login("<ClientId>", "<ClientSecret>")

func NewClient

func NewClient(httpClient *http.Client) *Client

NewClient creates a new client instance

Example
package main

import (
	"log"

	"github.com/breiting/rex"
)

func main() {

	clientID := "855889020987285jklj2345j"   // generated by REX, this is only an example
	clientSecret := "Aasjdji09948jr4j3hllkj" // generated by REX, this is only an example

	client := rex.NewClient(nil)

	err := client.Login(clientID, clientSecret)

	if err != nil {
		log.Fatal(err)
	}

	_ = client

}
Output:

client for subsequent calls

func NewClientWithToken

func NewClientWithToken(token oauth2.Token, httpClient *http.Client) (*Client, error)

NewClientWithToken takes token and reads the user information. If the token is not valid anymore, an error will be returned, else a new client will be provided.

func (*Client) Execute

func (c *Client) Execute(req *http.Request) (*http.Response, error)

Execute fullfills the Executor interface and performs a REX web request. Makes sure that the authentication token is set

func (*Client) Login

func (c *Client) Login(clientID, clientSecret string) error

Login uses the user's authentication information and gets a new authentication token

type Executor

type Executor interface {
	Execute(req *http.Request) (*http.Response, error)
}

Executor is an interface which is used to perform the actual REX request. This interface should be used for any REX API call. The Client structure is implementing this interface and performs the actual call.

type FileTransformation

type FileTransformation struct {
	Rotation struct {
		X float64 `json:"x"`
		Y float64 `json:"y"`
		Z float64 `json:"z"`
	} `json:"rotation"`
	Position struct {
		Type        string    `json:"type"`
		Coordinates []float64 `json:"coordinates"`
	} `json:"position"`
	Scale float64 `json:"scale"`
}

FileTransformation is used for defining the relationship between the RexReference and the actual file.

type Project

type Project struct {
	DateCreated string `json:"dateCreated"`
	CreatedBy   string `json:"createdBy"`
	LastUpdated string `json:"lastUpdated"`
	UpdatedBy   string `json:"updatedBy"`
	Name        string `json:"name"`
	Owner       string `json:"owner"`
	TagLine     string `json:"tagLine"`
	Type        string `json:"type"`
	Description string `json:"description"`
	Embedded    struct {
		RootRexReference struct {
			RootReference bool   `json:"rootReference"`
			Key           string `json:"key"`
			Links         struct {
				Self struct {
					Href      string `json:"href"`
					Templated bool   `json:"templated"`
				} `json:"self"`
				Project struct {
					Href      string `json:"href"`
					Templated bool   `json:"templated"`
				} `json:"project"`
				ParentReference struct {
					Href      string `json:"href"`
					Templated bool   `json:"templated"`
				} `json:"parentReference"`
				ChildReferences struct {
					Href      string `json:"href"`
					Templated bool   `json:"templated"`
				} `json:"childReferences"`
				ProjectFiles struct {
					Href      string `json:"href"`
					Templated bool   `json:"templated"`
				} `json:"projectFiles"`
			} `json:"_links"`
		} `json:"rootRexReference"`
		ProjectFiles []struct {
			LastModified string `json:"lastModified"`
			FileSize     int    `json:"fileSize"`
			Name         string `json:"name"`
			Type         string `json:"type"`
			Links        struct {
				Self struct {
					Href      string `json:"href"`
					Templated bool   `json:"templated"`
				} `json:"self"`
				RexReference struct {
					Href      string `json:"href"`
					Templated bool   `json:"templated"`
				} `json:"rexReference"`
				Project struct {
					Href      string `json:"href"`
					Templated bool   `json:"templated"`
				} `json:"project"`
				FileDownload struct {
					Href string `json:"href"`
				} `json:"file.download"`
			} `json:"_links"`
		} `json:"projectFiles"`
		RexReferences []struct {
			RootReference bool   `json:"rootReference"`
			Key           string `json:"key"`
			Links         struct {
				Self struct {
					Href      string `json:"href"`
					Templated bool   `json:"templated"`
				} `json:"self"`
				Project struct {
					Href      string `json:"href"`
					Templated bool   `json:"templated"`
				} `json:"project"`
				ParentReference struct {
					Href      string `json:"href"`
					Templated bool   `json:"templated"`
				} `json:"parentReference"`
				ChildReferences struct {
					Href      string `json:"href"`
					Templated bool   `json:"templated"`
				} `json:"childReferences"`
				ProjectFiles struct {
					Href      string `json:"href"`
					Templated bool   `json:"templated"`
				} `json:"projectFiles"`
			} `json:"_links"`
		} `json:"rexReferences"`
	} `json:"_embedded"`
	Links struct {
		Self struct {
			Href string `json:"href"`
		} `json:"self"`
		Project struct {
			Href      string `json:"href"`
			Templated bool   `json:"templated"`
		} `json:"project"`
		ThumbnailUpload struct {
			Href string `json:"href"`
		} `json:"thumbnail.upload"`
		ThumbnailDownload struct {
			Href string `json:"href"`
		} `json:"thumbnail.download"`
		ProjectFavorite struct {
			Href string `json:"href"`
		} `json:"projectFavorite"`
		RootRexReference struct {
			Href      string `json:"href"`
			Templated bool   `json:"templated"`
		} `json:"rootRexReference"`
		ProjectFiles struct {
			Href      string `json:"href"`
			Templated bool   `json:"templated"`
		} `json:"projectFiles"`
		ProjectAcls struct {
			Href      string `json:"href"`
			Templated bool   `json:"templated"`
		} `json:"projectAcls"`
		RexReferences struct {
			Href      string `json:"href"`
			Templated bool   `json:"templated"`
		} `json:"rexReferences"`
	} `json:"_links"`
}

Project is the full structure of a REX project.

func GetProject

func GetProject(e Executor, projectID string) (*Project, error)

GetProject retrieves the full project specified by the projectID (e.g. 1020)

func (Project) String

func (p Project) String() string

String nicely prints a project

type ProjectAddress

type ProjectAddress struct {
	AddressLine1 string `json:"addressLine1"`
	AddressLine2 string `json:"addressLine2"`
	AddressLine3 string `json:"addressLine3"`
	AddressLine4 string `json:"addressLine4"`
	PostCode     string `json:"postcode"`
	City         string `json:"city"`
	Region       string `json:"region"`
	Country      string `json:"country"`
}

ProjectAddress defines the address information for a project

type ProjectSimple

type ProjectSimple struct {
	ID    string // auto-generated after getting the list of projects
	Name  string `json:"name"`
	Owner string `json:"owner"`
	Links struct {
		Self struct {
			Href string `json:"href"`
		} `json:"self"`
	} `json:"_links"`
}

ProjectSimple is the basic structure representing a simple RexProject

type ProjectSimpleList

type ProjectSimpleList struct {
	Embedded struct {
		Projects []ProjectSimple `json:"projects"`
	} `json:"_embedded"`
}

ProjectSimpleList is a list ProjectSimple objects.

Mainly required for JSON encoding/decoding

func GetProjects

func GetProjects(e Executor, userID string) (*ProjectSimpleList, error)

GetProjects gets all projects for the current user.

This call only fetches the project list, but not the content of every project. Please use GetProject for getting the detailed project information.

func (ProjectSimpleList) String

func (p ProjectSimpleList) String() string

String nicely prints a list of projects.

type ProjectTransformation

type ProjectTransformation struct {
	Rotation struct {
		X float64 `json:"x"`
		Y float64 `json:"y"`
		Z float64 `json:"z"`
	} `json:"rotation"`
	Position struct {
		Type        string    `json:"type"`
		Coordinates []float64 `json:"coordinates"`
	} `json:"position"`
}

ProjectTransformation is used for the absoluteTransformation as well as for the relativeTransformation of a RexReference

type Reference

type Reference struct {
	Key             string                 `json:"key"`
	Project         string                 `json:"project"`
	ParentReference string                 `json:"parentReference"`
	RootReference   bool                   `json:"rootReference"`
	Address         *ProjectAddress        `json:"address"`
	AbsTransform    *ProjectTransformation `json:"absoluteTransformation"`
	RelTransform    *ProjectTransformation `json:"relativeTransformation"`
	FileTransform   *FileTransformation    `json:"fileTransformation"`
}

Reference is a spatial anchor which can be attached to a project or a project file.

type User

type User struct {
	UserID    string `json:"userId"`
	Username  string `json:"username,omitempty"`
	Email     string `json:"email,omitempty"`
	FirstName string `json:"firstName,omitempty"`
	LastName  string `json:"lastName,omitempty"`
	LastLogin string `json:"lastLogin,omitempty"`
	SelfLink  string
	Roles     []string `json:"roles,omitempty"`
	Links     struct {
		User struct {
			Href string `json:"href"`
		} `json:"user"`
	} `json:"_links,omitempty"`
}

User stores information of the current user.

The user can either contain the currentUser information, but also information from a user query. The SelfLink can be used to directly access the data, but is also often required for other operations (e.g. insert a project).

func GetCurrentUser

func GetCurrentUser(e Executor) (*User, error)

GetCurrentUser gets the user details of the current user.

The current user is the one which has been identified by the authentication token. When a new client is created by NewClient, this function will already be called implicitly.

func GetUserByEmail

func GetUserByEmail(e Executor, email string) (*User, error)

GetUserByEmail retrieves the user information based on a given email address

func (User) String

func (u User) String() string

String nicely prints out the user information.

Jump to

Keyboard shortcuts

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