43 lines
881 B
Go
43 lines
881 B
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"
|
|
)
|
|
|
|
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
|
|
}
|