handwritingio

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2016 License: MIT Imports: 7 Imported by: 2

Documentation

Overview

Package handwritingio provides a client library for interacting with the handwriting.io API

Additional API documentation available at https://handwriting.io/docs/

Index

Examples

Constants

This section is empty.

Variables

View Source
var DefaultHandwritingListParams = HandwritingListParams{
	Offset:   0,
	Limit:    200,
	OrderBy:  "id",
	OrderDir: "asc",
}

DefaultHandwritingListParams are the default values for HandwritingListParams

View Source
var DefaultRenderParamsPDF = RenderParamsPDF{
	HandwritingID:       "",
	Text:                "",
	HandwritingSize:     "20pt",
	HandwritingColor:    "(0, 0, 0, 1)",
	Width:               "7in",
	Height:              "5in",
	LineSpacing:         1.5,
	LineSpacingVariance: 0,
	WordSpacingVariance: 0,
	RandomSeed:          -1,
}

DefaultRenderParamsPDF are the default values for RenderParamsPDF

View Source
var DefaultRenderParamsPNG = RenderParamsPNG{
	HandwritingID:       "",
	Text:                "",
	HandwritingSize:     "20px",
	HandwritingColor:    "#000000",
	Width:               "504px",
	Height:              "360px",
	LineSpacing:         1.5,
	LineSpacingVariance: 0,
	WordSpacingVariance: 0,
	RandomSeed:          -1,
}

DefaultRenderParamsPNG are the default values for RenderParamsPNG

Functions

This section is empty.

Types

type APIError

type APIError struct {
	Error string `json:"error"`
	Field string `json:"field"`
}

APIError is a single error in the response from the API.

There can be one or more per response.

type APIErrors

type APIErrors struct {
	StatusCode int        `json:"-"`
	Body       []byte     `json:"-"`
	Errors     []APIError `json:"errors"`
}

APIErrors indicates an error response returned by the API.

func (APIErrors) Error

func (e APIErrors) Error() string

Error returns the message of the first APIError.

type Client

type Client struct {
	Key    string
	Secret string
	// contains filtered or unexported fields
}

Client is a client for making API calls

func NewClient

func NewClient(u *url.URL) (*Client, error)

NewClient constructs a Client from a URL

func (*Client) GetHandwriting

func (c *Client) GetHandwriting(id string) (handwriting Handwriting, err error)

GetHandwriting retrieves a single of handwriting

Example
id := "2D5S46A80003"

u, err := url.Parse(os.Getenv("HANDWRITINGIO_API_URL"))
if err != nil {
	fmt.Println("Make sure you have your environment variable HANDWRITINGIO_API_URL set correctly")
	fmt.Println(err)
	return
}

c, err := NewClient(u)
if err != nil {
	fmt.Println(err)
	return
}

handwriting, err := c.GetHandwriting(id)
if err != nil {
	fmt.Println(err)
	return
}

fmt.Println(handwriting.Title)
Output:

Perry

func (*Client) ListHandwritings

func (c *Client) ListHandwritings(params HandwritingListParams) (handwritings []Handwriting, err error)

ListHandwritings retrieves a list of handwritings

Example
u, err := url.Parse(os.Getenv("HANDWRITINGIO_API_URL"))
if err != nil {
	fmt.Println("Make sure you have your environment variable HANDWRITINGIO_API_URL set correctly")
	fmt.Println(err)
	return
}

var params = DefaultHandwritingListParams
params.Limit = 5
c, err := NewClient(u)
if err != nil {
	fmt.Println(err)
	return
}

handwritings, err := c.ListHandwritings(params)
if err != nil {
	fmt.Println(err)
	return
}

fmt.Printf("ListHandwritings returned %d Handwritings", len(handwritings))
Output:

ListHandwritings returned 5 Handwritings

func (*Client) RenderPDF

func (c *Client) RenderPDF(params RenderParamsPDF) (r io.ReadCloser, err error)

RenderPDF calls the API to produce a PDF image

Example
u, err := url.Parse(os.Getenv("HANDWRITINGIO_API_URL"))
if err != nil {
	fmt.Println("Make sure you have your environment variable HANDWRITINGIO_API_URL set correctly")
	fmt.Println(err)
	return
}

c, err := NewClient(u)
if err != nil {
	fmt.Println(err)
	return
}

var params = DefaultRenderParamsPDF
// Perry
params.HandwritingID = "2D5S46A80003"
// https://groups.google.com/forum/#!topic/comp.os.plan9/VUUznNK2t4Q%5B151-175%5D
params.Text = "object-oriented design is the roman numerals of computing.\n\n - Rob Pike"
r, err := c.RenderPDF(params)
if err != nil {
	fmt.Println(err)
	return
}
defer r.Close()

// os.TempDir can be overridden with TMP_DIR environment variable
filename := filepath.Join(os.TempDir(), "handwriting_io_render.pdf")
f, err := os.Create(filename)
if err != nil {
	fmt.Println(err)
	return
}
defer f.Close()

_, err = io.Copy(f, r)
if err != nil {
	fmt.Println(err)
	return
}

fmt.Println("handwriting_io_render.pdf written to temporary directory")
Output:

handwriting_io_render.pdf written to temporary directory

func (*Client) RenderPNG

func (c *Client) RenderPNG(params RenderParamsPNG) (r io.ReadCloser, err error)

RenderPNG calls the API to produce a PNG image

Example
u, err := url.Parse(os.Getenv("HANDWRITINGIO_API_URL"))
if err != nil {
	fmt.Println("Make sure you have your environment variable HANDWRITINGIO_API_URL set correctly")
	fmt.Println(err)
	return
}

c, err := NewClient(u)
if err != nil {
	fmt.Println(err)
	return
}

var params = DefaultRenderParamsPNG
// Perry
params.HandwritingID = "2D5S46A80003"
// https://groups.google.com/forum/#!topic/comp.os.plan9/VUUznNK2t4Q%5B151-175%5D
params.Text = "object-oriented design is the roman numerals of computing.\n\n - Rob Pike"
r, err := c.RenderPNG(params)
if err != nil {
	fmt.Println(err)
	return
}
defer r.Close()

// os.TempDir can be overridden with TMP_DIR environment variable
filename := filepath.Join(os.TempDir(), "handwriting_io_render.png")
f, err := os.Create(filename)
if err != nil {
	fmt.Println(err)
	return
}
defer f.Close()

_, err = io.Copy(f, r)
if err != nil {
	fmt.Println(err)
	return
}

fmt.Println("handwriting_io_render.png written to temporary directory")
Output:

handwriting_io_render.png written to temporary directory

type Handwriting

type Handwriting struct {
	ID                   string    `json:"id"`
	Title                string    `json:"title"`
	Created              time.Time `json:"date_created"`
	Modified             time.Time `json:"date_modified"`
	RatingNeatness       int       `json:"rating_neatness"`
	RatingCursivity      int       `json:"rating_cursivity"`
	RatingEmbellishment  int       `json:"rating_embellishment"`
	RatingCharacterWidth int       `json:"rating_character_width"`
}

Handwriting contains information about a handwriting style

type HandwritingListParams

type HandwritingListParams struct {
	Offset   int
	Limit    int
	OrderBy  string
	OrderDir string
}

HandwritingListParams contains the parameters for listing handwritings

type RenderParamsPDF

type RenderParamsPDF struct {
	HandwritingID       string
	Text                string
	HandwritingSize     string
	HandwritingColor    string
	Width               string
	Height              string
	LineSpacing         float64
	LineSpacingVariance float64
	WordSpacingVariance float64
	RandomSeed          int64
}

RenderParamsPDF contains the parameters for rendering a PDF image

type RenderParamsPNG

type RenderParamsPNG struct {
	HandwritingID       string
	Text                string
	HandwritingSize     string
	HandwritingColor    string
	Width               string
	Height              string
	LineSpacing         float64
	LineSpacingVariance float64
	WordSpacingVariance float64
	RandomSeed          int64
}

RenderParamsPNG contains the parameters for rendering a PNG image

type TokenError

type TokenError string

TokenError indicates a problem with API key or secret

func (TokenError) Error

func (e TokenError) Error() string

Jump to

Keyboard shortcuts

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