contextio

package module
v0.0.0-...-d233640 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2017 License: MIT Imports: 11 Imported by: 0

README

goContextIO

A simple golang Context.IO client library. Primarily all it does is sign the requests made to Context.IO with your key and secret. This allows you to make requests to Context.IO endpoints and either get an *http.request object back for parsing, or just the json response.

Docs are available at http://godoc.org/github.com/dmlyons/goContextIO.

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

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

func NewContextIO(key, secret string) *ContextIO

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

func (c *ContextIO) AttachFile(req *http.Request, fieldName, fileName string) error

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 io.Reader) (req *http.Request, err error)

NewRequest generates a request and signs it

func (*ContextIO) SetApiHost

func (c *ContextIO) SetApiHost(h string) *ContextIO

SetApiHost sets the domain (i.e. "api.context.io) for the requests, useful if you are mocking the API for testing

func (*ContextIO) SetRate

func (c *ContextIO) SetRate(requestsPerMinute float64)

SetRate the number of possible requests per minute

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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