rest

package
v0.0.0-...-a17a3e0 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2017 License: AGPL-3.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const ConvoNotifs = "convos"

ConvoNotifs is the notif code for Convos.

View Source
const NotifStream = "notifs"

NotifStream is the streamID to be used for notifs.

View Source
const StreamNotifs = "streams"
View Source
const TaskNotifs = "tasks"

Variables

View Source
var AdminNotifs = "admin"

Functions

func Bind

func Bind(
	db *bolt.DB,
	source SourceInfo,
	apiKey auth.Token,
) (*httprouter.Router, error)

Bind binds the API on the given DB. It sets up REST endpoints as needed.

Types

type API

type API interface {
	Bind(*httprouter.Router) error
}

API is a transform on an httprouter.Router, passing a DB for passing on to httprouter.Handles.

type Admin

type Admin struct {
	auth.Token
	*bolt.DB
	river.Pub
}

Admin implements API for an admin token and DB handle.

func (*Admin) Bind

func (a *Admin) Bind(r *htr.Router) error

Bind implements API.Bind on Admin.

func (Admin) DeleteTicket

func (a Admin) DeleteTicket(w http.ResponseWriter, r *http.Request, ps htr.Params)

func (Admin) DeleteUser

func (a Admin) DeleteUser(w http.ResponseWriter, r *http.Request, ps htr.Params)

func (Admin) GetAllProfiles

func (a Admin) GetAllProfiles(w http.ResponseWriter, r *http.Request, _ htr.Params)

func (Admin) NewLogin

func (a Admin) NewLogin(w http.ResponseWriter, r *http.Request, _ htr.Params)

NewLogin allows an Admin to create a new Login without punching a Ticket.

func (Admin) NewTicket

func (a Admin) NewTicket(w http.ResponseWriter, r *http.Request, _ htr.Params)

func (Admin) PatchProfile

func (a Admin) PatchProfile(w http.ResponseWriter, r *http.Request, ps htr.Params)

PatchProfile is a PATCH handler for an Admin to add Coin to a given user's Profile. The User is notified with the updated Profile value. The caller should use the URL parameter addCoin=<int64 coin amount>.

func (Admin) Verify

func (Admin) Verify(w http.ResponseWriter, r *http.Request, _ htr.Params)

type Convo

type Convo struct {
	*bolt.DB
	river.Pub
}

Convo implements API. It manages Convos.

func (*Convo) Bind

func (c *Convo) Bind(r *htr.Router) error

Bind implements API.Bind on Convo.

func (Convo) Connect

func (c Convo) Connect(w http.ResponseWriter, r *http.Request, ps htr.Params)

Connect is a Handle which opens and binds a WebSocket session to a Convo. Messages written by the WS client are bound in a convo.Message with the username and timestamp.

func (Convo) Create

func (c Convo) Create(w http.ResponseWriter, r *http.Request, _ htr.Params)

Create is a Handle over the DB which checks that the POSTed Convo is valid and then creates it, returning the created Convo.

func (Convo) Delete

func (c Convo) Delete(w http.ResponseWriter, r *http.Request, ps htr.Params)

Delete deletes the given Convo by ID.

func (Convo) Get

func (c Convo) Get(w http.ResponseWriter, r *http.Request, ps htr.Params)

Get is a Handle which gets the given Convo by ID. Any user who is an Owner, Reader, or Writer can get a Convo by ID.

func (Convo) GetAll

func (c Convo) GetAll(w http.ResponseWriter, r *http.Request, _ htr.Params)

GetAll is a Handle which writes all Convos owned by the user to the ResponseWriter.

TODO: Make Filters more flexible so users who aren't Owners can also

get Convos they belong to.

func (Convo) GetMessages

func (c Convo) GetMessages(w http.ResponseWriter, r *http.Request, ps htr.Params)

GetMessages gets an array of convo.Message. It can have filters applied in order to get a specific range of Messages.

func (Convo) Put

func (c Convo) Put(w http.ResponseWriter, r *http.Request, ps htr.Params)

Put is a Handle which updates a Convo in the DB by ID.

type Incept

type Incept struct {
	*bolt.DB
}

Incept implements API on a database. It handles new user creation.

func (Incept) Bind

func (i Incept) Bind(r *httprouter.Router) error

Bind implements API.Bind on Incept.

func (Incept) Incept

func (i Incept) Incept(w http.ResponseWriter, r *http.Request, ps httprouter.Params)

type Notif

type Notif struct {
	*bolt.DB
}

Notif implements API. It handles websocket connections to API endpoint notification publishers. A user will receive events on the websocket when an API publishes a notification event to its Pub.

func (Notif) Bind

func (n Notif) Bind(r *htr.Router) error

Bind implements API.Bind on Notif.

func (Notif) Connect

func (n Notif) Connect(w http.ResponseWriter, r *http.Request, _ htr.Params)

Connect binds a subscriber River and serves it over a Websocket.

type Profile

type Profile struct {
	*bolt.DB
}

Profile implements API. It handles user profiles.

func (Profile) Bind

func (p Profile) Bind(r *htr.Router) error

Bind implements API.Bind on Profile.

func (Profile) Delete

func (p Profile) Delete(w http.ResponseWriter, r *http.Request, _ htr.Params)

Delete deletes the User by ID from the UserBucket, disables the Login but retains it, and deletes all of the user's Sessions, Contexts, and Tokens. It also hangs up all of the user's connected rivers.

func (Profile) Get

func (p Profile) Get(w http.ResponseWriter, r *http.Request, _ htr.Params)

Get fetches the user's Profile by userID.

type SourceInfo

type SourceInfo struct {
	Version    store.Version `json:"version"`
	License    string        `json:"license"`
	LicensedTo string        `json:"licensedTo"`
	Location   string        `json:"location"`
}

SourceInfo represents the SG-Proto source location and license, and implements API.

func (SourceInfo) Bind

func (s SourceInfo) Bind(r *htr.Router) error

Bind implements API.Bind on SourceInfo.

type Stream

type Stream struct {
	*bolt.DB
	river.Pub
}

Stream implements API. It manages Streams and websocket connections to them.

func (*Stream) Bind

func (s *Stream) Bind(r *htr.Router) error

Bind implements API.Bind on Stream.

func (Stream) Connect

func (s Stream) Connect(w http.ResponseWriter, r *http.Request, ps htr.Params)

Connect is a Handle which opens and binds a WebSocket session to a Stream. The messages are transported as-is.

func (Stream) Create

func (s Stream) Create(w http.ResponseWriter, r *http.Request, _ htr.Params)

Create is a Handle over the DB which checks that the POSTed Stream is valid and then creates it, returning the created Stream.

func (Stream) Delete

func (s Stream) Delete(w http.ResponseWriter, r *http.Request, ps htr.Params)

Delete deletes the given Stream by ID.

func (Stream) Get

func (s Stream) Get(w http.ResponseWriter, r *http.Request, ps htr.Params)

Get is a Handle which gets the given Stream by ID. Any user who is an Owner, Reader, or Writer can get a Stream by ID.

func (Stream) GetAll

func (s Stream) GetAll(w http.ResponseWriter, r *http.Request, _ htr.Params)

GetAll is a Handle which writes all Streams owned by the user to the ResponseWriter.

TODO: Make Filters more flexible so users who aren't Owners can also

get Streams they belong to.

func (Stream) Put

func (s Stream) Put(w http.ResponseWriter, r *http.Request, ps htr.Params)

Put is a Handle which updates a Stream in the DB by ID.

type Task

type Task struct {
	*bolt.DB

	river.Pub

	util.Timer
}

func (*Task) Bind

func (t *Task) Bind(r *htr.Router) error

func (*Task) Create

func (t *Task) Create(w http.ResponseWriter, r *http.Request, _ htr.Params)

func (*Task) Delete

func (t *Task) Delete(w http.ResponseWriter, r *http.Request, ps htr.Params)

func (*Task) Get

func (t *Task) Get(w http.ResponseWriter, r *http.Request, ps htr.Params)

func (*Task) GetAll

func (t *Task) GetAll(w http.ResponseWriter, r *http.Request, _ htr.Params)

func (*Task) Put

func (t *Task) Put(w http.ResponseWriter, r *http.Request, ps htr.Params)

type Token

type Token struct{ *bolt.DB }

Token implements API. It handles creating and deleting login Tokens.

func (Token) Bind

func (t Token) Bind(r *htr.Router) error

Bind implements API.Bind on Token.

func (Token) Create

func (t Token) Create(w http.ResponseWriter, r *http.Request, _ htr.Params)

func (Token) Delete

func (t Token) Delete(w http.ResponseWriter, r *http.Request, ps htr.Params)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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