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
2024-07-11 13:10:30 +02:00

48 lines
1.3 KiB
Go

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"
)
// PoolBuilder represents a builder for constructing queries to retrieve a specific pool.
type PoolBuilder interface {
// ID sets the pool ID for the query.
ID(poolID int) PoolBuilder
// Execute sends the constructed query and returns the requested pool and an error, if any.
Execute() (model.Pool, error)
}
// NewGetPoolBuilder creates a new PoolBuilder with the provided RequestContext.
func NewGetPoolBuilder(requestContext model.RequestContext) PoolBuilder {
return &getPool{requestContext: requestContext}
}
type getPool struct {
requestContext model.RequestContext
id int
}
// ID sets the pool ID for the query.
func (g *getPool) ID(poolID int) PoolBuilder {
g.id = poolID
return g
}
// Execute sends the constructed query and returns the requested pool and an error, if any.
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
}