feat: partially added DMails into the Builder
This commit is contained in:
parent
d8eee5bc1b
commit
a8a87b83d9
79
pkg/e621/builder/dmail.go
Normal file
79
pkg/e621/builder/dmail.go
Normal file
@ -0,0 +1,79 @@
|
||||
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
|
||||
}
|
Reference in New Issue
Block a user