infogram

package module
v0.0.0-...-2e28975 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2021 License: MIT Imports: 14 Imported by: 0

README

Infogram API Go

Go Reference

Go client for the Infogram API.

Installation

$ go get github.com/blainsmith/infogram-go

Usage

Default Client

import "github.com/blainsmith/infogram-go"

func main() {
    client := infogram.NewClient("api-key", "api-secret")

    infographic, _ := client.Infographic(13)
}

With Options

import "github.com/blainsmith/infogram-go"

func main() {
    httpClient := http.Client{
        Timeout: 10 * time.Second,
    }

    client := infogram.NewClient(
        "api-key",
        "api-secret",
        infogram.ClientOptHTTPClient(&httpClient),
        infogram.ClientOptEndpoint("https://example.com/infogram"),
    )

    infographic, _ := client.Infographic(13)
}

Documentation

Index

Constants

View Source
const (
	// DefaultEndpoint is the default API endpoint for Infogram
	DefaultEndpoint = "https://infogr.am/service/v1"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	HTTPClient *http.Client
	Endpoint   string
	APIKey     string
	APISecret  string
	// contains filtered or unexported fields
}

Client is used to interact with the Infogram API

func (*Client) Do

func (c *Client) Do(ctx context.Context, req *http.Request, v interface{}) (*http.Response, error)

Do performs the *http.Request and decodes the http.Response.Body into v and return the *http.Response. If v is an io.Writer it will copy the body to the writer.

func (*Client) Infographic

func (c *Client) Infographic(id string) (*Infographic, error)

Infographics fetches a single infographic by identification number

func (*Client) Infographics

func (c *Client) Infographics() ([]Infographic, error)

Infographics fetches the list of infographics

func (*Client) SignRequest

func (c *Client) SignRequest(req *http.Request) error

SignRequest adds the `api_key` and `api_sig` query parameter in accordance with https://developers.infogr.am/rest/request-signing.html

func (*Client) Themes

func (c *Client) Themes() ([]Theme, error)

Infographics fetches a available themes to use for infographics

func (*Client) UserInfographics

func (c *Client) UserInfographics(id string) ([]Infographic, error)

UserInfographics fetches the list of infographics for the user's identification number

type Infographic

type Infographic struct {
	Id        string
	Title     string
	Thumbnail *url.URL
	ThemeId   int
	Published bool
	Modified  time.Time
	URL       *url.URL
}

Infographic defines the type returned by the Infogram API

func (*Infographic) HTMLReader

func (i *Infographic) HTMLReader(client *Client) (io.Reader, error)

HTMLReader returns an io.Reader of the Infographic in HTML format

func (*Infographic) MarshalJSON

func (i *Infographic) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler

func (*Infographic) PDFReader

func (i *Infographic) PDFReader(client *Client) (io.Reader, error)

PDFReader returns an io.Reader of the Infographic in PDF format

func (*Infographic) PNGReader

func (i *Infographic) PNGReader(client *Client) (io.Reader, error)

PNGReader returns an io.Reader of the Infographic in PNG format

func (*Infographic) UnmarshalJSON

func (i *Infographic) UnmarshalJSON(bytes []byte) error

UnmarshalJSON implements json.Unarshaler

type Theme

type Theme struct {
	Id        int
	Title     string
	Thumbnail *url.URL
}

Theme defines the type returned by the Infogram API

func (*Theme) MarshalJSON

func (t *Theme) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler

func (*Theme) UnmarshalJSON

func (t *Theme) UnmarshalJSON(bytes []byte) error

UnmarshalJSON implements json.Unmarshaler

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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