xee

package module
v0.0.0-...-4a3276a Latest Latest
Warning

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

Go to latest
Published: May 12, 2016 License: MIT Imports: 7 Imported by: 0

README

Build Status Software License GoDoc Coverage Status

Xee Go SDK

This is an unofficial SDK for Xee.

Getting started

package main

import (
    "github.com/laibulle/go-xee"
    "net/http"
    "io"
    "fmt"
)

var (
    sdk *xee.SDK
)

// Handle home and redirect Xee Login
func xeeCallback(w http.ResponseWriter, r *http.Request) {
    code := r.URL.Query().Get("code")

    // Get a token from auth code
    token, err := sdk.GetTokenFromCode(code)
    checkError(err)
    io.WriteString(w, fmt.Sprint(token))

    // Fetch user from Xee
    user, err := sdk.GetMe(token.AccessToken)
    checkError(err)
    io.WriteString(w, fmt.Sprint(user))

    // Fetch User cars
    cars, err := sdk.FindCars(user.ID, token.AccessToken)
    checkError(err)
    io.WriteString(w, fmt.Sprint(cars))

    // Fetch Car Status
    status, err := sdk.FindCarStatus(cars[0].ID, token.AccessToken)
    checkError(err)
    io.WriteString(w, fmt.Sprint(status))

    // Fetch Car locations
    locations, err := sdk.FindLocations(cars[0].ID, token.AccessToken, nil, nil, nil)
    checkError(err)
    io.WriteString(w, fmt.Sprint(locations))
}

// Handle authorization code
func home(w http.ResponseWriter, r *http.Request) {
    url := sdk.GetAuthURI("1")
    http.Redirect(w, r, url, http.StatusFound)
}

func checkError(err error) {
    if err != nil {
        panic(err)
    }
}

func main() {
    // Create a SDK instance
    sdk = xee.NewSDK("myclient", "mysecret", "http://127.0.0.1:8000/xee-callback")

    http.HandleFunc("/", home)
    http.HandleFunc("/xee-callback", xeeCallback)
    http.ListenAndServe(":8000", nil)
}

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	// ErrForbidden when resource is not accessible
	ErrForbidden = fmt.Errorf("Forbidden")

	// ErrValidation appen when a struct is not valid
	ErrValidation = fmt.Errorf("Validation error")

	// ErrEntityNotFound appen when entity is not found
	ErrEntityNotFound = fmt.Errorf("Entity not found")
)

Functions

This section is empty.

Types

type Accelerometer

type Accelerometer struct {
	X    float64   `json:"x"`
	Y    float64   `json:"y"`
	Z    float64   `json:"z"`
	Date time.Time `json:"date"`
}

Accelerometer struct

type Car

type Car struct {
	ID             int64     `json:"id"`
	UUID           string    `json:"uuid"`
	Name           string    `json:"name"`
	Make           *string   `json:"make"`
	Year           int       `json:"year"`
	NumberPlate    *string   `json:"numberPlate"`
	DeviceID       *string   `json:"deviceId"`
	CardbID        int64     `json:"cardbId"`
	CreationDate   time.Time `json:"creationDate"`
	LastUpdateDate time.Time `json:"lastUpdateDate"`
}

Car struct

type Location

type Location struct {
	Latitude   float32   `json:"latitude"`
	Longitude  float32   `json:"longitude"`
	Altitude   float32   `json:"altitude"`
	Satellites int       `json:"satellites"`
	Date       time.Time `json:"date"`
}

Location struct

type SDK

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

SDK struct is used to handle API calls

func NewSDK

func NewSDK(identifier string, secret string, redirect string) *SDK

NewSDK create an new instance of SDK

Example (NewSDK)
xee.NewSDK("myidentifier", "mysecret", "http://127.0.0.1:3000/xee-callback")

func (*SDK) FindCarByID

func (s *SDK) FindCarByID(userID int64, carID int64, token string) (Car, error)

FindCarByID find with ID for a given user

func (*SDK) FindCarStatus

func (s *SDK) FindCarStatus(carID int64, token string) (Status, error)

FindCarStatus for a given car

func (*SDK) FindCars

func (s *SDK) FindCars(userID int64, token string) ([]Car, error)

FindCars for a given user

func (*SDK) FindLocations

func (s *SDK) FindLocations(carID int64, token string, limit *int, begin *time.Time, stop *time.Time) ([]Location, error)

FindLocations for a given car

func (*SDK) FindLocationsByTrip

func (s *SDK) FindLocationsByTrip(carID int64, tripID string, token string) ([]Location, error)

FindLocationsByTrip for a given car

func (*SDK) FindSignals

func (s *SDK) FindSignals(carID int64, token string, names *[]string, limit *int, begin *time.Time, stop *time.Time) ([]Location, error)

FindSignals for a given car

func (*SDK) FindSignalsByTrip

func (s *SDK) FindSignalsByTrip(carID int64, tripID string, token string, names *[]string) ([]Location, error)

FindSignalsByTrip for a given car

func (*SDK) FindTrips

func (s *SDK) FindTrips(carID int64, token string, begin *time.Time, stop *time.Time) ([]Trip, error)

FindTrips for a given car

func (*SDK) GetAuthURI

func (s *SDK) GetAuthURI(state string) string

GetAuthURI to allow user to connect

func (*SDK) GetMe

func (s *SDK) GetMe(token string) (User, error)

GetMe return a user from an access token

func (*SDK) GetTokenFromCode

func (s *SDK) GetTokenFromCode(code string) (TokenResponse, error)

GetTokenFromCode is used to get a Token from a code

func (*SDK) GetTokenFromRefreshToken

func (s *SDK) GetTokenFromRefreshToken(refreshToken string) (TokenResponse, error)

GetTokenFromRefreshToken is used to get a Token from a code

func (*SDK) SetSandbox

func (sdk *SDK) SetSandbox(isSandbox bool)

SetSandbox to use pre-production environment

type Signal

type Signal struct {
	Date  time.Time `json:"date"`
	Value float64   `json:"value"`
	Name  string    `json:"name"`
}

Signal struct

type Status

type Status struct {
	Signals        []Signal      `json:"signals"`
	CreationDate   time.Time     `json:"creationDate"`
	LastUpdateDate time.Time     `json:"lastUpdateDate"`
	Location       Location      `json:"location"`
	Accelerometer  Accelerometer `json:"accelerometer"`
}

Status struct

type TokenResponse

type TokenResponse struct {
	AccessToken  string `json:"access_token"`
	RefreshToken string `json:"refresh_token"`
	ExpiresIn    int    `json:"expires_in"`
	ReceivedDate time.Time
}

TokenResponse struct

type Trip

type Trip struct {
	ID            string    `json:"id"`
	BeginLocation Location  `json:"beginLocation"`
	EndLocation   Location  `json:"endLocation"`
	BeginDate     time.Time `json:"beginDate"`
	StopDate      time.Time `json:"stopDate"`
}

Trip struct

type User

type User struct {
	ID                int64     `json:"id"`
	UUID              string    `json:"uuid"`
	LastName          string    `json:"lastName"`
	FirstName         string    `json:"firstName"`
	Nickname          *string   `json:"nickname"`
	Gender            string    `json:"gender"`
	Role              string    `json:"role"`
	IsLocationEnabled bool      `json:"isLocationEnabled"`
	CreationDate      time.Time `json:"creationDate"`
	LastUpdateDate    time.Time `json:"lastUpdateDate"`
}

User struct

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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