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 PostBuilder interface {
SetPostID(postID model.PostID) PostBuilder
Execute() (*model.Post, error)
}
func NewGetPostBuilder(requestContext model.RequestContext) PostBuilder {
return &getPost{requestContext: requestContext}
type getPost struct {
requestContext model.RequestContext
postID model.PostID
func (g *getPost) SetPostID(postID model.PostID) PostBuilder {
g.postID = postID
return g
func (g *getPost) Execute() (*model.Post, error) {
if g.requestContext.RateLimiter != nil {
err := g.requestContext.RateLimiter.Wait(context.Background())
if err != nil {
return nil, err
post, err := endpoints.GetPost(g.requestContext, strconv.Itoa(int(g.postID)))
return &post, nil