client

package
v0.0.0-...-9d69390 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2015 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DEFAULT_BRIDGE_ENDPOINT   = "http://127.0.0.1:8989/"
	DEFAULT_BINDING_PORT      = "8787"
	DEFAULT_BINDING_INTERFACE = "0.0.0.0"
	DEFAULT_BINDING           = DEFAULT_BINDING_INTERFACE + ":" + DEFAULT_BINDING_PORT
	PRE_EVENT                 = "PRE"
	POST_EVENT                = "POST"

	API_VERSION      = "/v1"
	API_PING         = API_VERSION + "/ping"
	API_SUBSCRIPTION = API_VERSION + "/subscriptions"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	// close the resource and unregister if required
	Close() error
	// register a hook in the API
	Subscribe(*Subscription, RequestsChannel) (string, error)
	// unsubscribe from the provider
	Unsubscribe(string) error
	// list the current subscriptions
	Subscriptions() ([]*Subscription, error)
}

The client interface

func NewClient

func NewClient(cfg *Config) (Client, error)

Create a new client to communicate with the bridge

config:		 	the configuration to use with the client

type ClientImpl

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

the implementation of the client

func (*ClientImpl) Close

func (r *ClientImpl) Close() error

Request to close off any resources, disconnect our self as an endpoint (if required) and close the client

func (*ClientImpl) Subscribe

func (r *ClientImpl) Subscribe(subscription *Subscription, channel RequestsChannel) (string, error)

Perform a registration request to the bridge

	register:		the registration structure containing the hooks
 channel:		the channel you want to receive the api requests on

func (*ClientImpl) Subscriptions

func (r *ClientImpl) Subscriptions() ([]*Subscription, error)

Retrieve a list of subscriptions from the bridge

func (*ClientImpl) Unsubscribe

func (r *ClientImpl) Unsubscribe(id string) error

Unregister from the bridge.io service

id:				the registration id which was given when you registered

type Config

type Config struct {
	// the rest endpoint for the bridge io server - e.g http://127.0.0.1:8989
	Bridge string `json:"bridge"`
	// the binding for the client i.e. where the endpoint will run
	Binding string `json:"bind"`
	// the token used to connect to bridge
	Token string `json:"token"`
	// the max time to wait for a request to fulfil
	MaxTime time.Duration
}

the configuration of the client

func DefaultConfig

func DefaultConfig() *Config

type Event

type Event struct {
	// an id for the origin - normally the hostname
	ID string `json:"id"`
	// a timestamp for the request
	Stamp time.Time `json:"timestamp"`
	// the hook type
	HookType string `json:"type"`
	// the uri for the request
	URI string `json:"uri"`
	// the query string
	Query string `json:"query"`
	// the payload itself
	Request string `json:"request"`
	// contains filtered or unexported fields
}

A structure to define and incoming request

func (*Event) Respond

func (r *Event) Respond()

func (Event) String

func (r Event) String() string

type Hook

type Hook struct {
	// should this hook be enforcing, i.e. if were not able to contact you, kill the request
	Enforcing bool `json:"enforcing"`
	// when the hook should be fired, i.e. pre, post or both
	HookType string `json:"type"`
	// the entry point for the request, a regex applied to URI
	URI string `json:"uri"`
}

A Hook definition / request for access to the API

func (*Hook) Valid

func (r *Hook) Valid() error

type MessageResponse

type MessageResponse struct {
	Message string `json:"message"`
}

type RequestsChannel

type RequestsChannel chan *Event

a channel for the below

type Subscription

type Subscription struct {
	// an application ID
	ID string `json:"id"`
	// the endpoint to send these requests
	Subscriber string `json:"subscriber"`
	// an array of hook requests
	Requests []*Hook `json:"hooks"`
}

A registration request structure: used buy the client register for hook events into the API

func (*Subscription) AddHook

func (r *Subscription) AddHook(h *Hook)

func (*Subscription) PostHook

func (r *Subscription) PostHook(uri string) *Subscription

func (*Subscription) PreHook

func (r *Subscription) PreHook(uri string) *Subscription

func (Subscription) Valid

func (r Subscription) Valid() error

type SubscriptionResponse

type SubscriptionResponse struct {
	ID string `json:"id"`
}

type SubscriptionsResponse

type SubscriptionsResponse struct {
	Subscriptions []*Subscription `json:"subscriptions"`
}

Jump to

Keyboard shortcuts

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