giphy

package
v0.0.0-...-cfb91dc Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2023 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NoThrottle = int64(-1)
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewClient

func NewClient(apiKey string) (*Client, error)

func NewClientFromEnvOrDefault

func NewClientFromEnvOrDefault() (*Client, error)

func (*Client) GIFByID

func (c *Client) GIFByID(ctx context.Context, id string) (*Giph, error)

func (*Client) RandomGIF

func (c *Client) RandomGIF(ctx context.Context, req *Request) (*Giph, error)

func (*Client) RandomSticker

func (c *Client) RandomSticker(ctx context.Context, req *Request) (*Giph, error)

func (*Client) Search

func (c *Client) Search(ctx context.Context, req *Request) (*ResponsePager, error)

func (*Client) SearchStickers

func (c *Client) SearchStickers(ctx context.Context, req *Request) (*ResponsePager, error)

func (*Client) SetAPIKey

func (c *Client) SetAPIKey(key string)

func (*Client) SetHTTPRoundTripper

func (c *Client) SetHTTPRoundTripper(rt http.RoundTripper)

func (*Client) Trending

func (c *Client) Trending(ctx context.Context, req *Request) (*ResponsePager, error)

func (*Client) TrendingStickers

func (c *Client) TrendingStickers(ctx context.Context, req *Request) (*ResponsePager, error)

type Format

type Format string
const (
	FormatHTMl Format = "html"
	FormatJSON Format = "json"
)

type GIF

type GIF struct {
	Type     string `json:"type,omitempty"`
	ID       string `json:"id,omitempty"`
	URL      string `json:"url"`
	Width    int    `json:"width,string,omitempty"`
	Height   int    `json:"height,string,omitempty"`
	Size     int64  `json:"size,string,omitempty"`
	MP4      string `json:"mp4,omitempty"`
	MP4Size  int64  `json:"mp4_size,string,omitempty"`
	Webp     string `json:"webp,omitempty"`
	WebpSize int64  `json:"webp_size,string,omitempty"`
}

type Giph

type Giph struct {
	Type        string `json:"type,omitempty"`
	ID          string `json:"id,omitempty"`
	Slug        string `json:"slug,omitempty"`
	URL         string `json:"url,omitempty"`
	BitlyURL    string `json:"bitly_url,omitempty"`
	BitlyGIFURL string `json:"bitly_gif_url,omitempty"`
	EmbedURL    string `json:"embed_url,omitempty"`
	Owner       string `json:"username,omitempty"`
	Source      string `json:"source,omitempty"`
	Rating      string `json:"rating,omitempty"`
	Caption     string `json:"caption,omitempty"`
	ContentURL  string `json:"content_url,omitempty"`

	SourceTopLevelDomain string `json:"source_tld,omitempty"`
	SourcePostURL        string `json:"source_post_url,omitempty"`

	ImportDate   *GiphyTime `json:"import_datetime,omitempty"`
	TrendingDate *GiphyTime `json:"trending_datetime,omitempty"`

	Sizes map[string]*GIF `json:"images"`

	ImageOriginalURL string `json:"image_original_url,omitempty"`
	ImageURL         string `json:"image_url,omitempty"`
	FrameCount       uint   `json:"image_frames,string,omitempty"`
	ImageWidth       int    `json:"image_width,string,omitempty"`
	ImageHeight      int    `json:"image_height,string,omitempty"`

	FixedHeightDownsampledURL    string `json:"fixed_height_downsampled_url,omitempty"`
	FixedHeightDownsampledHeight int    `json:"fixed_height_downsampled_height,string,omitempty"`
	FixedHeightDownsampledWidth  int    `json:"fixed_height_downsampled_width,string,omitempty"`

	FixedHeightSmallURL    string `json:"fixed_height_small_url,omitempty"`
	FixedHeightSmallHeight int    `json:"fixed_height_small_height,string,omitempty"`
	FixedHeightSmallWidth  int    `json:"fixed_height_small_width,string,omitempty"`

	FixedHeightSmallStillURL    string `json:"fixed_height_small_still_url,omitempty"`
	FixedHeightSmallStillHeight int    `json:"fixed_height_small_still_height,string,omitempty"`
	FixedHeightSmallStillWidth  int    `json:"fixed_height_small_still_width,string,omitempty"`

	FixedWidthDownsampledURL    string `json:"fixed_width_downsampled_url,omitempty"`
	FixedWidthDownsampledHeight int    `json:"fixed_width_downsampled_height,string,omitempty"`
	FixedWidthDownsampledWidth  int    `json:"fixed_width_downsampled_width,string,omitempty"`

	FixedWidthSmallURL    string `json:"fixed_width_small_url,omitempty"`
	FixedWidthSmallHeight int    `json:"fixed_width_small_height,string,omitempty"`
	FixedWidthSmallWidth  int    `json:"fixed_width_small_width,string,omitempty"`

	FixedWidthSmallStillURL    string `json:"fixed_width_small_still_url,omitempty"`
	FixedWidthSmallStillHeight int    `json:"fixed_width_small_still_height,string,omitempty"`
	FixedWidthSmallStillWidth  int    `json:"fixed_width_small_still_width,string,omitempty"`
}

type GiphyTime

type GiphyTime time.Time

GiphyTime sends time back in the format:

2015-08-22 15:23:22 and that trips out the default

JSON unmarshaling, so make a custom unmarshaling.

func (*GiphyTime) UnmarshalJSON

func (gt *GiphyTime) UnmarshalJSON(b []byte) error

type Language

type Language string
const (
	LangSpanish            Language = "es"
	LangPortuguese         Language = "pt"
	LangIndonesian         Language = "id"
	LangFrench             Language = "fr"
	LangArabic             Language = "ar"
	LangTurkish            Language = "tr"
	LangThai               Language = "th"
	LangVietnamese         Language = "vi"
	LangGerman             Language = "de"
	LangItalian            Language = "it"
	LangJapanese           Language = "ja"
	LangChineseSimplified  Language = "zh-CN"
	LangChineseTraditional Language = "zh-TW"
	LangRussian            Language = "ru"
	LangKorean             Language = "ko"
	LangPolish             Language = "pl"
	LangDutch              Language = "nl"
	LangRomanian           Language = "ro"
	LangHungarian          Language = "hu"
	LangSwedish            Language = "sv"
	LangCzech              Language = "cs"
	LangHindi              Language = "hi"
	LangBengali            Language = "bn"
	LangDanish             Language = "da"
	LangFarsi              Language = "fa"
	LangFilipino           Language = "tl"
	LangFinnish            Language = "fi"
	LangHebrew             Language = "iw"
	LangMalay              Language = "ms"
	LangNorwegian          Language = "no"
	LangUkrainian          Language = "uk"
)

type Page

type Page struct {
	Giphs []*Giph `json:"giphs"`
	Err   error   `json:"error"`

	PageNumber uint64 `json:"page_number"`
}

type Pagination

type Pagination struct {
	TotalCount uint64 `json:"total_count,omitempty"`
	Offset     uint64 `json:"offset,omitempty"`
	Count      uint64 `json:"count,omitempty"`
}

type Rating

type Rating string
const (
	RatingPG      Rating = "pg"
	RatingPG13    Rating = "pg-13"
	RatingR       Rating = "r"
	RatingGeneral Rating = "g"
	RatingYouth   Rating = "y"
)

type Request

type Request struct {
	Query string `json:"query"`

	Rating Rating `json:"rating"`
	Format Format `json:"format"`

	MaxPageNumber uint64    `json:"max_page_number"`
	LimitPerPage  uint64    `json:"limit_per_page"`
	Language      Language  `json:"lang"`
	SortBy        SortOrder `json:"sort_by"`
	Tag           string    `json:"tag"`

	ThrottleDurationMs int64 `json:"throttle_duration_ms"`
}

type Response

type Response struct {
	Giphs      []*Giph                `json:"data,omitempty"`
	Pagination *Pagination            `json:"pagination,omitempty"`
	Meta       map[string]interface{} `json:"meta,omitempty"`
}

type ResponsePager

type ResponsePager struct {
	Cancel func() error `json:"-"`
	Pages  <-chan *Page `json:"-"`
}

type SortOrder

type SortOrder string

Sort order

const (
	SortRecent   SortOrder = "recent"
	SortRelevant SortOrder = "relevant"
)

Jump to

Keyboard shortcuts

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