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 ¶
- Variables
- type APIError
- type APIErrors
- type Client
- func (c *Client) GetHandwriting(id string) (handwriting Handwriting, err error)
- func (c *Client) ListHandwritings(params HandwritingListParams) (handwritings []Handwriting, err error)
- func (c *Client) RenderPDF(params RenderParamsPDF) (r io.ReadCloser, err error)
- func (c *Client) RenderPNG(params RenderParamsPNG) (r io.ReadCloser, err error)
- type Handwriting
- type HandwritingListParams
- type RenderParamsPDF
- type RenderParamsPNG
- type TokenError
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultHandwritingListParams = HandwritingListParams{
Offset: 0,
Limit: 200,
OrderBy: "id",
OrderDir: "asc",
}
DefaultHandwritingListParams are the default values for HandwritingListParams
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
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 ¶
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.
type Client ¶
Client is a client for making API calls
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 ¶
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