rest

package
v1.0.1-50 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2015 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NodeID = config.Serial()

doesn't change so we cache it.

Functions

func GetJsonPayload

func GetJsonPayload(r *http.Request) (map[string]interface{}, error)

func WriteServerErrorResponse

func WriteServerErrorResponse(msg string, code int, w http.ResponseWriter)

WriteServerErrorResponse Builds the wrapped error for the client

func WriteServerResponse

func WriteServerResponse(data interface{}, code int, w http.ResponseWriter)

WriteServerResponse Builds the wrapped object for the client

Types

type LocationRouter

type LocationRouter struct {
}

func NewLocationRouter

func NewLocationRouter() *LocationRouter

func (*LocationRouter) GetCalibrateDevice

func (lr *LocationRouter) GetCalibrateDevice(r *http.Request, w http.ResponseWriter)

GetCalibrateDevice

NOTE: This currently gets hit a ton by the web ui when you click the Calibrate button on the site.

func (*LocationRouter) GetCalibrateScores

func (lr *LocationRouter) GetCalibrateScores(r *http.Request, w http.ResponseWriter)

GetCalibrateScores This retrieves the calibration scores for a room

NOTE: Currently returns 504 Gateway Time-out on my sphere

func (*LocationRouter) GetCalibrationProgress

func (lr *LocationRouter) GetCalibrationProgress(r *http.Request, w http.ResponseWriter)

func (*LocationRouter) PostCreateThing

func (lr *LocationRouter) PostCreateThing(r *http.Request, w http.ResponseWriter, thingModel *models.ThingModel, deviceModel *models.DeviceModel)

PostCreateThing this will create a device and a thing from bluetooth devices discovered.

Sends application/json with content {"deviceId":"F0E4FFFFFFFF","thingName":"Bob","thingType":"person"}

Responds with {"success":true,"id":"7efa45b0-2108-464d-83c6-8af1785bc9ea"}

func (*LocationRouter) Register

func (lr *LocationRouter) Register(r martini.Router)

type ResponseWrapper

type ResponseWrapper struct {
	Type string      `json:"type,omitempty"`
	Data interface{} `json:"data,omitempty"`
}

ResponseWrapper used to wrap responses from the API

type RestServer

type RestServer struct {
	RedisPool    *redis.Pool         `inject:""`
	Conn         *ninja.Connection   `inject:""`
	RoomModel    *models.RoomModel   `inject:""`
	ThingModel   *models.ThingModel  `inject:""`
	DeviceModel  *models.DeviceModel `inject:""`
	SiteModel    *models.SiteModel   `inject:""`
	StateManager state.StateManager  `inject:""`
	// contains filtered or unexported fields
}

RestServer Holds stuff shared by all the rest services

func (*RestServer) Listen

func (r *RestServer) Listen() error

func (*RestServer) PostConstruct

func (r *RestServer) PostConstruct() error

type RoomRouter

type RoomRouter struct {
}

func NewRoomRouter

func NewRoomRouter() *RoomRouter

func (*RoomRouter) DeleteRoom

func (lr *RoomRouter) DeleteRoom(params martini.Params, w http.ResponseWriter, roomModel *models.RoomModel, conn redis.Conn)

DeleteRoom removes a room using it's identifier

func (*RoomRouter) GetAll

func (lr *RoomRouter) GetAll(w http.ResponseWriter, roomModel *models.RoomModel, conn redis.Conn)

GetAll retrieves a list of rooms

Response [

{
   "id" : "1468fbcd-3ca6-4c6f-a742-ab91221e5462",
   "things" : [
      {
         "type" : "light",
         "id" : "4b518a5d-f855-4e21-86e0-6e91f6772bea",
         "device" : "2864dd823a",
         "name" : "Hue Lamp 2",
         "location" : "1468fbcd-3ca6-4c6f-a742-ab91221e5462"
      },
      {
         "type" : "light",
         "id" : "525425b8-7d8e-4da9-9317-a38dd447ece7",
         "device" : "2df71ceb74",
         "name" : "Hue Lamp 1",
         "location" : "1468fbcd-3ca6-4c6f-a742-ab91221e5462"
      },
      {
         "device" : "076ca89411",
         "id" : "8252f0e2-43d5-4dd2-bf13-834af1b789ca",
         "type" : "light",
         "name" : "Hue Lamp",
         "location" : "1468fbcd-3ca6-4c6f-a742-ab91221e5462"
      }
   ],
   "name" : "Living Room"
}

]

func (*RoomRouter) GetRoom

func (lr *RoomRouter) GetRoom(params martini.Params, w http.ResponseWriter, roomModel *models.RoomModel, conn redis.Conn)

GetRoom retrieves a room using it's identifier

func (*RoomRouter) PostNewRoom

func (lr *RoomRouter) PostNewRoom(r *http.Request, w http.ResponseWriter, roomModel *models.RoomModel, conn redis.Conn)

PostNewRoom creates a new room using the name submitted

Request {"name":"Bedroom","type":"bedroom"} Response {"name":"Bedroom","type":"bedroom","id":"16c63268-c0e5-48a2-b312-c74c64837802"}

func (*RoomRouter) PutAppRoomMessage

func (lr *RoomRouter) PutAppRoomMessage(params martini.Params, r *http.Request, w http.ResponseWriter, roomModel *models.RoomModel, conn *ninja.Connection, rconn redis.Conn)

PutAppRoomMessage sends a message to the app passing the identifier of the room which it applies too

func (*RoomRouter) PutCalibrateRoom

func (lr *RoomRouter) PutCalibrateRoom(params martini.Params, w http.ResponseWriter, roomModel *models.RoomModel, conn redis.Conn)

PutCalibrateRoom enables calibration for a specific room

Request {"id":"1468fbcd-3ca6-4c6f-a742-ab91221e5462","device":"20CD39A0899C","reset":true} Response 200

func (*RoomRouter) Register

func (lr *RoomRouter) Register(r martini.Router)

func (*RoomRouter) UpdateRoom

func (lr *RoomRouter) UpdateRoom(params martini.Params, r *http.Request, w http.ResponseWriter, roomModel *models.RoomModel, conn redis.Conn)

GetRoom updates a room using it's identifier

type SiteRouter

type SiteRouter struct {
}

func NewSiteRouter

func NewSiteRouter() *SiteRouter

func (*SiteRouter) DeleteSite

func (lr *SiteRouter) DeleteSite(params martini.Params, w http.ResponseWriter, siteModel *models.SiteModel, conn redis.Conn)

DeleteSite removes a site using it's identifier

func (*SiteRouter) GetAll

func (lr *SiteRouter) GetAll(r *http.Request, w http.ResponseWriter, siteModel *models.SiteModel, stateManager state.StateManager, conn redis.Conn)

GetAll retrieves a list of all sites

func (*SiteRouter) GetSite

func (lr *SiteRouter) GetSite(params martini.Params, w http.ResponseWriter, siteModel *models.SiteModel, stateManager state.StateManager, conn redis.Conn)

GetSite retrieves a site using it's identifier

func (*SiteRouter) PutSite

func (lr *SiteRouter) PutSite(params martini.Params, r *http.Request, w http.ResponseWriter, siteModel *models.SiteModel, conn redis.Conn)

GetAll updates a site using it's identifier, with the JSON payload containing name and type

func (*SiteRouter) Register

func (lr *SiteRouter) Register(r martini.Router)

type ThingRouter

type ThingRouter struct {
}

func NewThingRouter

func NewThingRouter() *ThingRouter

func (*ThingRouter) DeleteThing

func (lr *ThingRouter) DeleteThing(params martini.Params, w http.ResponseWriter, thingModel *models.ThingModel, conn redis.Conn)

DeleteThing removes a thing using it's identifier

func (*ThingRouter) GetAll

func (lr *ThingRouter) GetAll(r *http.Request, w http.ResponseWriter, thingModel *models.ThingModel, conn redis.Conn)

GetAll retrieves a list of all things

func (*ThingRouter) GetThing

func (lr *ThingRouter) GetThing(params martini.Params, w http.ResponseWriter, thingModel *models.ThingModel, conn redis.Conn)

GetThing retrieves a thing using it's identifier

func (*ThingRouter) PutThing

func (lr *ThingRouter) PutThing(params martini.Params, r *http.Request, w http.ResponseWriter, thingModel *models.ThingModel, conn redis.Conn)

GetAll updates a thing using it's identifier, with the JSON payload containing name and type

func (*ThingRouter) PutThingLocation

func (lr *ThingRouter) PutThingLocation(params martini.Params, r *http.Request, w http.ResponseWriter, thingModel *models.ThingModel, conn redis.Conn)

PutThingLocation assigns or clears the location for a thing, this is currently a room identifier sent in the payload

func (*ThingRouter) Register

func (lr *ThingRouter) Register(r martini.Router)

Jump to

Keyboard shortcuts

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