client

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2016 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RemoveAllProjTokens added in v0.7.4

func RemoveAllProjTokens(p *config.Profile) error

Types

type AuthToken

type AuthToken struct {
	Token     string
	Expires   string
	UserId    uint64 `json:"user_id,omitempty"`
	ProjectId uint64 `json:"project_id,omitempty"`
	Read      bool   `json:",omitempty"`
	Write     bool   `json:",omitempty"`
	Admin     bool   `json:",omitempty"`
}

AuthToken is a representation of both user and project tokens. It contains for all tokens the actual token string and when it expires. For user tokens it also contains the userID it pertains to. For project tokens it contains the projectID it pertains to, as well as its permissions.

func ReadProjToken

func ReadProjToken(p *config.Profile, id uint64) (*AuthToken, error)

ReadProjToken fetches the project token for a particular id from the disk, if it exists.

func ReadUserToken

func ReadUserToken(p *config.Profile) (*AuthToken, error)

ReadUserToken fetches the user token that is stored on disk, if it exists.

func (*AuthToken) IsExpired added in v0.5.0

func (t *AuthToken) IsExpired() (bool, error)

IsExpired reports whether AuthToken t has expired.

func (*AuthToken) Refresh added in v0.5.0

func (t *AuthToken) Refresh(client *Client, p *config.Profile) (*AuthToken, error)

Refresh attempts to update a given project token t. If t is not a project token (i.e., a user token) it will error.

func (*AuthToken) Save

func (t *AuthToken) Save(p *config.Profile) error

Save writes the token to disk in the user's .iobeam directory.

type Client

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

Client represents a http.Client that will be used to talk to a server running the iobeam API.

func NewClient

func NewClient(target *string, clientVersion string) *Client

NewClient returns a new HTTP client capable of communicating with a server running the iobeam API. The server address is passed via target.

func (*Client) Delete

func (client *Client) Delete(apiCall string) *Request

Delete returns a new Request with HTTP method of Delete for the supplied resource.

func (*Client) Get

func (client *Client) Get(apiCall string) *Request

Get returns a new Request with HTTP method of GET for the supplied resource.

func (*Client) Patch

func (client *Client) Patch(apiCall string) *Request

Patch returns a new Request with HTTP method of Patch for the supplied resource.

func (*Client) Post

func (client *Client) Post(apiCall string) *Request

Post returns a new Request with HTTP method of POST for the supplied resource.

func (*Client) Put

func (client *Client) Put(apiCall string) *Request

Put returns a new Request with HTTP method of Put for the supplied resource.

type Request

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

Request is an API HTTP request to the iobeam backend.

func NewRequest

func NewRequest(client *Client, method, apiCall string) *Request

NewRequest creates a new API request to iobeam. It takes a *Client that handles the actual execution, a string for the HTTP method, and a string for the API path.

func (*Request) BasicAuth

func (r *Request) BasicAuth(username string, password string) *Request

BasicAuth sets the username and password to use in case of Basic authentication on the API endpoint. It returns the *Request so it can be chained.

func (*Request) Body

func (r *Request) Body(content interface{}) *Request

Body sets the HTTP body of the *Request. It assumes the content can be serialized to JSON. It returns the *Request so it can be chained.

func (*Request) BodyStream added in v0.7.0

func (r *Request) BodyStream(stream io.Reader) *Request

BodyStream sets the stream to use for HTTP body of the *Request. Content is assumed to be an octet-stream. It returns the *Request so it can be chained.

func (*Request) DumpRequest added in v0.8.0

func (r *Request) DumpRequest(dumpFlag bool) *Request

DumpRequest sets whether the request should be dumped to stdout. It returns the *Request so it can be chained.

func (*Request) DumpResponse added in v0.8.0

func (r *Request) DumpResponse(dumpFlag bool) *Request

DumpResponse sets whether the response should be dumped to stdout. It returns the *Request so it can be chained.

func (*Request) Execute

func (r *Request) Execute() (*Response, error)

Execute causes the API request to be carried out, returning a *Response and possibly an error.

func (*Request) Expect

func (r *Request) Expect(statusCode int) *Request

Expect sets the HTTP status code value that the executed r should expect. It returns the *Request so it can be chained.

func (*Request) Param

func (r *Request) Param(name, value string) *Request

Param adds a query parameter to the *Request whose value is a string. It returns the *Request so it can be chained.

func (*Request) ParamBool

func (r *Request) ParamBool(name string, value bool) *Request

ParamBool adds a query parameter to the *Request whose value is a bool. It returns the *Request so it can be chained.

func (*Request) ParamInt

func (r *Request) ParamInt(name string, value int) *Request

ParamInt adds a query parameter to the *Request whose value is an int. It returns the *Request so it can be chained.

func (*Request) ParamInt64

func (r *Request) ParamInt64(name string, value int64) *Request

ParamInt64 adds a query parameter to the *Request whose value is an int64. It returns the *Request so it can be chained.

func (*Request) ParamUint

func (r *Request) ParamUint(name string, value uint) *Request

ParamUint adds a query parameter to the *Request whose value is a uint. It returns the *Request so it can be chained.

func (*Request) ParamUint64

func (r *Request) ParamUint64(name string, value uint64) *Request

ParamUint64 adds a query parameter to the *Request whose value is a uint64. It returns the *Request so it can be chained.

func (*Request) ProjectToken

func (r *Request) ProjectToken(p *config.Profile, id uint64) *Request

ProjectToken returns a Request with the project token set. If the token is expired, an attempt to refresh the token is made. It returns the *Request so it can be chained.

func (*Request) ResponseBody

func (r *Request) ResponseBody(content interface{}) *Request

ResponseBody sets the object where the *Request's response should be stored. It returns the *Request so it can be chained.

func (*Request) ResponseBodyHandler

func (r *Request) ResponseBodyHandler(handler ResponseBodyHandler) *Request

ResponseBodyHandler sets the ResponseBodyHandler to use when the request returns. It returns the *Request so it can be chained.

func (*Request) ResponseHeader added in v0.8.0

func (r *Request) ResponseHeader(headerPtr **http.Header) *Request

ResponseHeader sets a pointer that will be directed to the response header. It returns the *Request so it can be chained.

func (*Request) UserToken

func (r *Request) UserToken(p *config.Profile) *Request

UserToken returns a request with user token set. It returns the *Request so it can be chained.

type Response

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

func NewResponse

func NewResponse(http *http.Response) *Response

func (*Response) Http

func (r *Response) Http() *http.Response

func (*Response) Read

func (r *Response) Read(into interface{}) error

func (*Response) ReadError

func (r *Response) ReadError() (*RestError, error)

func (*Response) ReadJson added in v0.3.0

func (r *Response) ReadJson(into interface{}) error

func (*Response) ReadPlain added in v0.3.0

func (r *Response) ReadPlain(result *string) error

type ResponseBodyHandler

type ResponseBodyHandler func(responseBody interface{}) error

ResponseBodyHandler is a function called when an API request returns. The function takes an interface{} (usually converted to JSON) and returns an error.

type ResponseBodyReader

type ResponseBodyReader func(*Response, interface{}) error

type RestError

type RestError struct {
	Errors []struct {
		Code    uint
		Message string
		Details string
	}
}

Jump to

Keyboard shortcuts

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