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 PostsBuilder interface {
Tags(tags string) PostsBuilder
PageAfter(postID int) PostsBuilder
pageBefore(postID int) PostsBuilder
SetLimit(limitUser int) PostsBuilder
Execute() ([]model.Post, error)
}
func NewGetPostsBuilder(requestContext model.RequestContext) PostsBuilder {
return &getPosts{
requestContext: requestContext,
query: make(map[string]string),
type getPosts struct {
requestContext model.RequestContext
query map[string]string
func (g *getPosts) Tags(tags string) PostsBuilder {
g.query["tags"] = tags
return g
func (g *getPosts) PageAfter(postID int) PostsBuilder {
g.query["page"] = "a" + strconv.Itoa(postID)
func (g *getPosts) pageBefore(postID int) PostsBuilder {
g.query["page"] = "b" + strconv.Itoa(postID)
func (g *getPosts) SetLimit(limitUser int) PostsBuilder {
g.query["limit"] = strconv.Itoa(limitUser)
func (g *getPosts) Execute() ([]model.Post, error) {
if g.requestContext.RateLimiter != nil {
err := g.requestContext.RateLimiter.Wait(context.Background())
if err != nil {
return nil, err
posts, err := endpoints.GetPosts(g.requestContext, g.query)
return posts, err