reqapi

package
v0.1.119 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	TMDBAPI = &API{
		Ident:       TMDBIdent,
		Endpoint:    "https://api.themoviedb.org/3",
		RetriesLeft: 3,
		RateLimiter: util.NewRateLimiter(50, 1*time.Second, 50),
	}

	TraktAPI = &API{
		Ident:       TraktIdent,
		Endpoint:    "https://api.trakt.tv",
		RetriesLeft: 3,
		RateLimiter: util.NewRateLimiter(100, 10*time.Second, 25),
	}

	// SimklAPI allows 10 GET/s and 1 POST/s and wants sequential requests, so stay at 1 request per second.
	SimklAPI = &API{
		Ident:       SimklIdent,
		Endpoint:    "https://api.simkl.com",
		RetriesLeft: 3,
		RateLimiter: util.NewRateLimiter(1, 1*time.Second, 1),
	}

	// MDBListAPI allows 1000 reads and 300 writes per 5 minutes; the daily quota is the real limit.
	MDBListAPI = &API{
		Ident:       MDBListIdent,
		Endpoint:    "https://api.mdblist.com",
		RetriesLeft: 3,
		RateLimiter: util.NewRateLimiter(60, 1*time.Minute, 2),
	}

	// ScrobAPI is a self-hosted server: requests carry the full URL from settings, so there is no endpoint.
	ScrobAPI = &API{
		Ident:       ScrobIdent,
		RetriesLeft: 3,
		RateLimiter: util.NewRateLimiter(10, 1*time.Second, 2),
	}

	FanartAPI = &API{
		Ident:       FanArtIdent,
		Endpoint:    "http://webservice.fanart.tv/v3",
		RetriesLeft: 3,
		RateLimiter: util.NewRateLimiter(100, 10*time.Second, 25),
	}

	OpenSubtitlesAPI = &API{
		Ident:       OpenSubtitlesIdent,
		Endpoint:    "https://api.opensubtitles.com/api/v1",
		RetriesLeft: 3,
		RateLimiter: util.NewRateLimiter(100, 10*time.Second, 25),
	}
)

Functions

This section is empty.

Types

type API

type API struct {
	Ident       APIIdent
	RateLimiter *util.RateLimiter
	Endpoint    string
	RetriesLeft int
}

func GetAPI

func GetAPI(ident APIIdent) *API

func (*API) GetSession

func (api *API) GetSession() *napping.Session

func (*API) GetURL

func (api *API) GetURL(url string) string

type APIIdent

type APIIdent string
const (
	TMDBIdent          APIIdent = cache.TMDBKey
	TraktIdent         APIIdent = cache.TraktKey
	SimklIdent         APIIdent = cache.SimklKey
	MDBListIdent       APIIdent = cache.MDBListKey
	ScrobIdent         APIIdent = cache.ScrobKey
	FanArtIdent        APIIdent = cache.FanartKey
	OpenSubtitlesIdent APIIdent = cache.OpensubtitlesKey
)

type CacheEntry

type CacheEntry struct {
	Header map[string][]string `json:"header"`
	Body   []byte              `json:"body"`
	// Result is msgpack-encoded Result, stored instead of Body when Result type has generated bindings
	Result     []byte `json:"result"`
	Status     string `json:"status"`
	StatusCode int    `json:"statuscode"`
}

func (*CacheEntry) MarshalMsg added in v0.1.115

func (z *CacheEntry) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (*CacheEntry) Msgsize added in v0.1.115

func (z *CacheEntry) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*CacheEntry) UnmarshalMsg added in v0.1.115

func (z *CacheEntry) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

type Request

type Request struct {
	trace.Tracer
	API *API

	Method      string
	URL         string
	Params      url.Values  `msg:"-"`
	Header      http.Header `msg:"-"`
	Payload     *bytes.Buffer
	Description string

	Retry        int
	RetryBackoff time.Duration

	ResponseError      error
	ResponseStatus     string
	ResponseStatusCode int
	ResponseHeader     http.Header
	ResponseBody       *bytes.Buffer
	ResponseSize       uint64
	ResponseIgnore     []int

	Result any

	Cache            bool
	CacheExpire      time.Duration
	CacheForceExpire bool
	CacheKey         string
	// contains filtered or unexported fields
}

func (*Request) ApplyCache

func (r *Request) ApplyCache(c *CacheEntry)

func (*Request) ApplyResponse

func (r *Request) ApplyResponse(resp *napping.Response)

func (*Request) CacheRead

func (r *Request) CacheRead() error

func (*Request) CacheWrite

func (r *Request) CacheWrite(data []byte) (err error)

func (*Request) Do

func (r *Request) Do() (err error)

func (*Request) Error

func (r *Request) Error(err error)

func (*Request) Lock

func (r *Request) Lock() error

func (*Request) LogStatus

func (r *Request) LogStatus()

func (*Request) Marshal

func (r *Request) Marshal() ([]byte, error)

func (*Request) MarshalCache

func (r *Request) MarshalCache() ([]byte, error)

func (*Request) Prepare

func (r *Request) Prepare() (err error)

func (*Request) Reset

func (r *Request) Reset()

func (*Request) Size

func (r *Request) Size(size uint64)

func (*Request) String

func (r *Request) String() string

func (*Request) Unlock

func (r *Request) Unlock() error

func (*Request) Unmarshal

func (r *Request) Unmarshal(b *bytes.Buffer) error

func (*Request) UnmarshalCache

func (r *Request) UnmarshalCache(b *bytes.Buffer) (*CacheEntry, error)

Jump to

Keyboard shortcuts

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