CataasAPI

package module
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2021 License: MIT Imports: 9 Imported by: 0

README

Cataas API

Cat as a service API wrapper for go.

Cat as a service is a REST API to spread peace and love (or not) thanks to cats.

Install

go get github.com/iArmann/Cataas-API-go

Examples

Import:

import CataasAPI "github.com/iArmann/Cataas-API-go"

Get()

c := new(CataasAPI.Cataas)
c.Gif = true
c.Text = "Hey dude"
c.Color = "LightBlue"
c.TextSize = 30
c.Size = CataasAPI.SIZE_MEDIUM
c.Encode()
data, err := c.Get()

Download(string)

c := new(CataasAPI.Cataas)
c.Filter = CataasAPI.FILTER_SEPIA
c.Encode()
err := c.Download("cat.png")

GetAllTags()

c := new(CataasAPI.Cataas)
tags, err := c.GetAllTags()
fmt.Printf("total tags: %d", len(tags))

GetTags([]string, *GetCatsOptions)

c := new(CataasAPI.Cataas)
// get 'cute' tags
cats, err := c.GetCats([]string{"cute"}, nil)
// use options
cats, err := c.GetCats([]string{"cute"}, &CataasAPI.GetCatsOptions{
    Skip:  0,
    Limit: 10,
})
// print cat ids
for i, cat := range cats {
    fmt.Printf("%d) id: %s\n", i+1, cat.Id)
}
Tips:
  • After setting Gif = true, Tag is ignored
  • Don't forget to Encode() | EncodeById before Get() | Download()

Reference

API website

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CatByTag

type CatByTag struct {
	Id        string   `json:"id"`
	CreatedAt string   `json:"created_at"`
	Tags      []string `json:"tags"`
}

type Cataas

type Cataas struct {
	Gif       bool
	Tag       string
	Text      string
	Width     uint
	Height    uint
	TextSize  uint
	TextColor string
	Size      Size
	Filter    Filter
}

Cataas API wrapper

func (*Cataas) Download

func (c *Cataas) Download(path string) (err error)

like Get, but saves the data to a file

func (*Cataas) Encode

func (c *Cataas) Encode() *url.URL

Encodes url by using fields of Cataas object

func (*Cataas) EncodeById

func (c *Cataas) EncodeById(id string) *url.URL

returns the encoded url by using the id of the image

func (*Cataas) Get

func (c *Cataas) Get() (data []byte, err error)

sends get request then reads the response body and returns the data. can be used after encoding using Encode or EncodeById

func (*Cataas) GetAllTags

func (c *Cataas) GetAllTags() (tags []string, err error)

get all tags

func (*Cataas) GetCats

func (c *Cataas) GetCats(tags []string, options *GetCatsOptions) (cats []*CatByTag, err error)

get cats which include the given tag(s)

type Filter

type Filter string
const (
	FILTER_BLUR     Filter = "blur"
	FILTER_MONO     Filter = "mono"
	FILTER_PAINT    Filter = "paint"
	FILTER_PIXEL    Filter = "pixel"
	FILTER_SEPIA    Filter = "sepia"
	FILTER_NEGATIVE Filter = "negative"
)

blur, mono, sepia, negative, paint, pixel

type GetCatsOptions

type GetCatsOptions struct {
	Skip  uint
	Limit uint
}

type Size

type Size string
const (
	SIZE_SMALL    Size = "sm"
	SIZE_MEDIUM   Size = "md"
	SIZE_SQUARE   Size = "sq"
	SIZE_ORIGINAL Size = "or"
)

small or sm, medium or md, square or sq, original or or

Jump to

Keyboard shortcuts

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