This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
e621-sdk-go/pkg/e621/builder/pool.go

43 lines
881 B
Go
Raw Normal View History

package builder
import (
"context"
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/endpoints"
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
"strconv"
)
type PoolBuilder interface {
ID(poolID int) PoolBuilder
Execute() (model.Pool, error)
}
func NewGetPoolBuilder(requestContext model.RequestContext) PoolBuilder {
return &getPool{requestContext: requestContext}
}
type getPool struct {
requestContext model.RequestContext
id int
}
func (g getPool) ID(poolID int) PoolBuilder {
g.id = poolID
return g
}
func (g getPool) Execute() (model.Pool, error) {
if g.requestContext.RateLimiter != nil {
err := g.requestContext.RateLimiter.Wait(context.Background())
if err != nil {
return model.Pool{}, err
}
}
pool, err := endpoints.GetPool(g.requestContext, strconv.Itoa(g.id))
if err != nil {
return model.Pool{}, err
}
return pool, nil
}