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/dmail.go

80 lines
1.8 KiB
Go
Raw Normal View History

package builder
import (
"context"
"strconv"
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/endpoints"
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/utils"
)
type DMailsBuilder interface {
ByTitle(title string) DMailsBuilder
ByBody(body string) DMailsBuilder
ByToName(toName string) DMailsBuilder
ByFromName(fromName string) DMailsBuilder
SetLimit(limit int) DMailsBuilder
PageNumber(number int) DMailsBuilder
Execute() ([]model.DMail, error)
}
type getDMails struct {
requestContext model.RequestContext
query map[string]string
id int
}
func NewGetDMailsBuilder(requestContext model.RequestContext) DMailsBuilder {
dMailsBuilder := &getDMails{
requestContext: requestContext,
query: make(map[string]string),
}
return dMailsBuilder.SetLimit(utils.E621_MAX_POST_COUNT)
}
func (g getDMails) ByTitle(title string) DMailsBuilder {
g.query["title_matches"] = title
return g
}
func (g getDMails) ByBody(body string) DMailsBuilder {
g.query["message_matches"] = body
return g
}
func (g getDMails) ByToName(toName string) DMailsBuilder {
g.query["to_name"] = toName
return g
}
func (g getDMails) ByFromName(fromName string) DMailsBuilder {
g.query["from_name"] = fromName
return g
}
func (g getDMails) SetLimit(limit int) DMailsBuilder {
g.query["limit"] = strconv.Itoa(limit)
return g
}
func (g getDMails) PageNumber(number int) DMailsBuilder {
g.query["page"] = strconv.Itoa(number)
return g
}
func (g getDMails) Execute() ([]model.DMail, error) {
if g.requestContext.RateLimiter != nil {
err := g.requestContext.RateLimiter.Wait(context.Background())
if err != nil {
return nil, err
}
}
favorites, err := endpoints.GetAllDmails(g.requestContext, g.query)
if err != nil {
return nil, err
}
return favorites, nil
}