api

package module
v0.0.0-...-478f129 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2017 License: BSD-3-Clause Imports: 5 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

go-cooperhewitt-api

Go language API library for the Cooper Hewitt API.

How this Fits

This is one of many libraries that allow anyone to easily connect their application to the Cooper Hewitt API. This one is written in Go.

Example

Assume this is a file called echo.go:

package main

import (
	"flag"
	"fmt"
	"net/url"
	"org.cooperhewitt/api"
	"os"
	"strings"
)

func main() {

	token := flag.String("token", "", "token")
	flag.Parse()

	args := flag.Args()
	call := strings.Join(args, " ")

	client := api.OAuth2Client(*token)

	method := "api.test.echo"
	params := url.Values{}
	params.Set("echo", call)

	rsp, err := client.ExecuteMethod(method, &params)

	if err != nil {
		os.Exit(1)
	}

	_, api_err := rsp.Ok()

	if api_err != nil {
		os.Exit(1)
	}

	body := rsp.Body()

	var response string
	response, _ = body.Path("echo").Data().(string)

	fmt.Println(response)
	os.Exit(0)
}

This would yield:

$> echo -token ACCESS_TOKEN wub wub wub
wub wub wub

The Body method for API responses returns gabs.Container thingy for wrangling the actual JSON (in all it's unknowiness) returned by the API endpoint.

To do

  • APIError blobs are not recording error codes correctly
  • Setting host and endpoint in constructor
  • Support for multipart-mime uploads (just because, you can't actually do those in the API)
  • Better internal logging
  • Proper documentation
  • Update to derive most functionality from https://github.com/straup/go-flamework-api

See also

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIClient

type APIClient struct {
	Host     string
	Endpoint string
	Token    string
	// contains filtered or unexported fields
}

func OAuth2Client

func OAuth2Client(token string) *APIClient

func (*APIClient) ExecuteMethod

func (client *APIClient) ExecuteMethod(method string, params *url.Values) (*APIResponse, error)

type APIError

type APIError struct {
	Code    int64
	Message string
}

type APIResponse

type APIResponse struct {
	Raw    []byte
	Parsed *gabs.Container
}

func ParseAPIResponse

func ParseAPIResponse(raw []byte) (*APIResponse, error)

func (APIResponse) Body

func (rsp APIResponse) Body() *gabs.Container

func (APIResponse) Dumps

func (rsp APIResponse) Dumps() string

func (APIResponse) Error

func (rsp APIResponse) Error() *APIError

func (APIResponse) Ok

func (rsp APIResponse) Ok() (bool, *APIError)

func (APIResponse) Stat

func (rsp APIResponse) Stat() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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