Documentation
¶
Overview ¶
Package contextio provides a simple way to sign API requests for http://Context.IO.
The simplest usage is to use DoJSON() to return a json byte array that you can use elsewhere in your code. For more advanced usage, you can use Do() and parse through the http.Response struct yourself. It is not specific to an API version, so you can use it to make any request you would make through http://console.Context.IO.
Index ¶
- type ContextIO
- func (c *ContextIO) AttachFile(req *http.Request, fieldName, fileName string) error
- func (c *ContextIO) Do(method, q string, params url.Values, body *string) (response *http.Response, err error)
- func (c *ContextIO) DoJSON(method, q string, params url.Values, body *string) (json []byte, err error)
- func (c *ContextIO) NewRequest(method, q string, queryParams url.Values, body *string) (req *http.Request, err error)
- func (c *ContextIO) SetAPIHost(h string) *ContextIO
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ContextIO ¶
type ContextIO struct {
// contains filtered or unexported fields
}
ContextIO is a struct containing the authentication information and a pointer to the oauth client
func NewContextIO ¶
NewContextIO returns a ContextIO struct based on your CIO User and Secret
Example ¶
c := NewContextIO("MyCIOUserKey", "MyCIOSecret") params := url.Values{} params.Set("limit", "10") // body is usually used for POSTs, ignored otherwise, but // its format looks like this: body := "some_param=1&some_other_param=2" j, err := c.DoJSON("GET", "/2.0/accounts", params, &body) if err != nil { fmt.Println("DoJSON Error:", err) return } var out bytes.Buffer json.Indent(&out, j, "", " ") fmt.Println(out.String())
Output:
func (*ContextIO) AttachFile ¶
AttachFile will create a file upload in the request, assumes NewRequest has already been called
func (*ContextIO) Do ¶
func (c *ContextIO) Do(method, q string, params url.Values, body *string) (response *http.Response, err error)
Do signs the request and returns an *http.Response. The body is a standard response.Body and must have defer response.Body.close(). Does not support uploads, use NewRequest and AttachFile for that. This is 2 legged authentication, and will not currently work with 3 legged authentication.
func (*ContextIO) DoJSON ¶
func (c *ContextIO) DoJSON(method, q string, params url.Values, body *string) (json []byte, err error)
DoJSON passes the request to Do and then returns the json in a []byte array
func (*ContextIO) NewRequest ¶
func (c *ContextIO) NewRequest(method, q string, queryParams url.Values, body *string) (req *http.Request, err error)
NewRequest generates a request and signs it
func (*ContextIO) SetAPIHost ¶
SetAPIHost sets the domain (i.e. "api.context.io) for the requests, useful if you are mocking the API for testing