refactor: start rework of the high level API
Signed-off-by: soxx <soxx@fenpa.ws>
This commit is contained in:
parent
585c94b97a
commit
be44a669d9
@ -1,7 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/builder"
|
||||
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/builder/basic"
|
||||
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
||||
"log"
|
||||
"net/http"
|
||||
@ -19,7 +19,7 @@ func main() {
|
||||
}
|
||||
|
||||
log.Println("Getting a list of DB Exports: ")
|
||||
getDBExportList := builder.NewGetDBExportListBuilder(requestContext)
|
||||
getDBExportList := basic.NewGetDBExportListBuilder(requestContext)
|
||||
dbExportFiles, err := getDBExportList.Execute()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@ -35,7 +35,7 @@ func main() {
|
||||
exportFileName := dbExportFiles[0]
|
||||
log.Println("Downloading DB export")
|
||||
log.Printf("File to download: %s", exportFileName)
|
||||
getDBExportFile := builder.NewGetDBExportFileBuilder(requestContext)
|
||||
getDBExportFile := basic.NewGetDBExportFileBuilder(requestContext)
|
||||
|
||||
rawFile, err := getDBExportFile.SetFile(exportFileName).Execute()
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/builder"
|
||||
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/builder/basic"
|
||||
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
||||
_ "github.com/joho/godotenv/autoload"
|
||||
"log"
|
||||
@ -23,7 +23,7 @@ func main() {
|
||||
log.Println("Getting favorites API user: ")
|
||||
|
||||
// Call the GetFavorites function to retrieve favorite posts.
|
||||
getFavorites := builder.NewGetFavoritesBuilder(requestContext)
|
||||
getFavorites := basic.NewGetFavoritesBuilder(requestContext)
|
||||
posts, err := getFavorites.SetLimit(5).Execute()
|
||||
|
||||
if err != nil {
|
||||
|
@ -1,7 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/builder"
|
||||
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/builder/basic"
|
||||
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
||||
_ "github.com/joho/godotenv/autoload"
|
||||
"log"
|
||||
@ -27,7 +27,7 @@ func main() {
|
||||
noteID := 36957 // Replace with the desired note's ID.
|
||||
|
||||
// Call the GetNote function to retrieve the specified note.
|
||||
getNote := builder.NewGetNoteBuilder(requestContext)
|
||||
getNote := basic.NewGetNoteBuilder(requestContext)
|
||||
note, err := getNote.SetNoteID(noteID).Execute()
|
||||
|
||||
if err != nil {
|
||||
@ -42,7 +42,7 @@ func main() {
|
||||
log.Println("Getting a list of notes: ")
|
||||
|
||||
// Call the GetNotes function to retrieve a list of notes based on the query parameters.
|
||||
getNotes := builder.NewGetNotesBuilder(requestContext)
|
||||
getNotes := basic.NewGetNotesBuilder(requestContext)
|
||||
notes, err := getNotes.SetLimit(5).Active(true).SearchInBody("furry").Execute()
|
||||
|
||||
if err != nil {
|
||||
|
@ -1,7 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/builder"
|
||||
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/builder/basic"
|
||||
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
||||
_ "github.com/joho/godotenv/autoload"
|
||||
"log"
|
||||
@ -26,7 +26,7 @@ func main() {
|
||||
poolID := 36957 // Replace with the desired pool's ID.
|
||||
|
||||
// Call the GetPool function to retrieve the specified pool.
|
||||
getPool := builder.NewGetPoolBuilder(requestContext)
|
||||
getPool := basic.NewGetPoolBuilder(requestContext)
|
||||
pool, err := getPool.ID(poolID).Execute()
|
||||
|
||||
if err != nil {
|
||||
@ -41,7 +41,7 @@ func main() {
|
||||
log.Println("Getting a list of pools: ")
|
||||
|
||||
// Call the GetPools function to retrieve a list of pools based on the query parameters.
|
||||
getPools := builder.NewGetPoolsBuilder(requestContext)
|
||||
getPools := basic.NewGetPoolsBuilder(requestContext)
|
||||
pools, err := getPools.SetLimit(5).Active(true).SearchDescription("mass effect").Execute()
|
||||
|
||||
if err != nil {
|
||||
|
@ -1,7 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/builder"
|
||||
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/builder/basic"
|
||||
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
||||
_ "github.com/joho/godotenv/autoload"
|
||||
"log"
|
||||
@ -26,7 +26,7 @@ func main() {
|
||||
var postID model.PostID = 4353480 // Replace with the desired post's ID.
|
||||
|
||||
// Call the GetPost function to retrieve the specified post.
|
||||
getPost := builder.NewGetPostBuilder(requestContext)
|
||||
getPost := basic.NewGetPostBuilder(requestContext)
|
||||
post, err := getPost.SetPostID(postID).Execute()
|
||||
|
||||
if err != nil {
|
||||
@ -41,7 +41,7 @@ func main() {
|
||||
log.Println("Getting a list of posts: ")
|
||||
|
||||
// Call the GetPosts function to retrieve a list of posts based on the query parameters.
|
||||
getPosts := builder.NewGetPostsBuilder(requestContext)
|
||||
getPosts := basic.NewGetPostsBuilder(requestContext)
|
||||
posts, err := getPosts.SetLimit(5).Execute()
|
||||
|
||||
if err != nil {
|
||||
|
@ -1,7 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/builder"
|
||||
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/builder/basic"
|
||||
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
||||
_ "github.com/joho/godotenv/autoload"
|
||||
"log"
|
||||
@ -26,7 +26,7 @@ func main() {
|
||||
tagID := 1530 // Replace with the desired tag's ID.
|
||||
|
||||
// Call the GetTag function to retrieve the specified tag.
|
||||
getTag := builder.NewGetTagBuilder(requestContext)
|
||||
getTag := basic.NewGetTagBuilder(requestContext)
|
||||
tag, err := getTag.SetTagID(tagID).Execute()
|
||||
|
||||
if err != nil {
|
||||
@ -41,7 +41,7 @@ func main() {
|
||||
log.Println("Getting a list of tags: ")
|
||||
|
||||
// Call the GetTags function to retrieve a list of tags based on the query parameters.
|
||||
getTags := builder.NewGetTagsBuilder(requestContext)
|
||||
getTags := basic.NewGetTagsBuilder(requestContext)
|
||||
tagList, err := getTags.SetLimit(5).Artist(false).Execute()
|
||||
|
||||
if err != nil {
|
||||
|
@ -1,7 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/builder"
|
||||
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/builder/basic"
|
||||
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
||||
_ "github.com/joho/godotenv/autoload"
|
||||
"log"
|
||||
@ -26,7 +26,7 @@ func main() {
|
||||
username := "selloo" // Replace with the desired username.
|
||||
|
||||
// Call the GetUser function to retrieve the specified user.
|
||||
userBuilder := builder.NewGetUserBuilder(requestContext)
|
||||
userBuilder := basic.NewGetUserBuilder(requestContext)
|
||||
user, err := userBuilder.SetUsername(username).Execute()
|
||||
|
||||
if err != nil {
|
||||
@ -41,7 +41,7 @@ func main() {
|
||||
log.Println("Getting a list of users: ")
|
||||
|
||||
// Call the GetUsers function to retrieve a list of users based on the query parameters.
|
||||
usersBuilder := builder.NewGetUsersBuilder(requestContext)
|
||||
usersBuilder := basic.NewGetUsersBuilder(requestContext)
|
||||
userList, err := usersBuilder.SetLimit(5).Execute()
|
||||
|
||||
if err != nil {
|
||||
|
@ -1,4 +1,4 @@
|
||||
package builder
|
||||
package basic
|
||||
|
||||
import (
|
||||
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/endpoints"
|
@ -1,4 +1,4 @@
|
||||
package builder
|
||||
package basic
|
||||
|
||||
import (
|
||||
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/endpoints"
|
95
pkg/e621/builder/basic/favorite.go
Normal file
95
pkg/e621/builder/basic/favorite.go
Normal file
@ -0,0 +1,95 @@
|
||||
package basic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/endpoints"
|
||||
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// FavoritesBuilder represents a builder for constructing queries to retrieve user's favorite posts.
|
||||
type FavoritesBuilder interface {
|
||||
// SetUserID sets the user ID for the query.
|
||||
SetUserID(userID model.UserID) FavoritesBuilder
|
||||
// SetLimit sets the maximum number of favorite posts to retrieve.
|
||||
SetLimit(limitFavorites int) FavoritesBuilder
|
||||
// Page sets the page number for paginated results.
|
||||
Page(pageNumber int) FavoritesBuilder
|
||||
// Execute sends the constructed query and returns a slice of favorite posts and an error if any.
|
||||
Execute() ([]model.Post, error)
|
||||
}
|
||||
|
||||
// NewGetFavoritesBuilder creates a new instance of FavoritesBuilder with the provided RequestContext.
|
||||
//
|
||||
// Parameters:
|
||||
// - requestContext: The context for the API request, including the host, user agent, username, and API key.
|
||||
//
|
||||
// Returns:
|
||||
// - FavoritesBuilder: An instance of the FavoritesBuilder interface.
|
||||
func NewGetFavoritesBuilder(requestContext model.RequestContext) FavoritesBuilder {
|
||||
return &getFavorites{
|
||||
requestContext: requestContext,
|
||||
query: make(map[string]string),
|
||||
}
|
||||
}
|
||||
|
||||
// getFavorites is an implementation of the FavoritesBuilder interface.
|
||||
type getFavorites struct {
|
||||
query map[string]string
|
||||
requestContext model.RequestContext
|
||||
}
|
||||
|
||||
// SetUserID sets the user ID for the query.
|
||||
//
|
||||
// Parameters:
|
||||
// - userID: The ID of the user whose favorite posts are to be retrieved.
|
||||
//
|
||||
// Returns:
|
||||
// - FavoritesBuilder: The instance of the FavoritesBuilder for method chaining.
|
||||
func (g *getFavorites) SetUserID(userID model.UserID) FavoritesBuilder {
|
||||
g.query["user_id"] = strconv.Itoa(int(userID))
|
||||
return g
|
||||
}
|
||||
|
||||
// SetLimit sets the maximum number of favorite posts to retrieve.
|
||||
//
|
||||
// Parameters:
|
||||
// - limitFavorites: The maximum number of favorite posts to retrieve.
|
||||
//
|
||||
// Returns:
|
||||
// - FavoritesBuilder: The instance of the FavoritesBuilder for method chaining.
|
||||
func (g *getFavorites) SetLimit(limitFavorites int) FavoritesBuilder {
|
||||
g.query["limit"] = strconv.Itoa(limitFavorites)
|
||||
return g
|
||||
}
|
||||
|
||||
// Page sets the page number for paginated results.
|
||||
//
|
||||
// Parameters:
|
||||
// - pageNumber: The page number for paginated results.
|
||||
//
|
||||
// Returns:
|
||||
// - FavoritesBuilder: The instance of the FavoritesBuilder for method chaining.
|
||||
func (g *getFavorites) Page(pageNumber int) FavoritesBuilder {
|
||||
g.query["page"] = strconv.Itoa(pageNumber)
|
||||
return g
|
||||
}
|
||||
|
||||
// Execute sends the constructed query and returns a slice of favorite posts and an error if any.
|
||||
//
|
||||
// Returns:
|
||||
// - []model.Post: A slice of favorite posts.
|
||||
// - error: An error, if any, encountered during the API request or response handling.
|
||||
func (g *getFavorites) Execute() ([]model.Post, error) {
|
||||
if g.requestContext.RateLimiter != nil {
|
||||
err := g.requestContext.RateLimiter.Wait(context.Background())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
favorites, err := endpoints.GetFavorites(g.requestContext, g.query)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return favorites, nil
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package builder
|
||||
package basic
|
||||
|
||||
import (
|
||||
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
@ -1,4 +1,4 @@
|
||||
package builder
|
||||
package basic
|
||||
|
||||
import (
|
||||
"context"
|
@ -1,4 +1,4 @@
|
||||
package builder
|
||||
package basic
|
||||
|
||||
import (
|
||||
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
@ -1,4 +1,4 @@
|
||||
package builder
|
||||
package basic
|
||||
|
||||
import (
|
||||
"context"
|
@ -1,4 +1,4 @@
|
||||
package builder
|
||||
package basic
|
||||
|
||||
import (
|
||||
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
@ -1,4 +1,4 @@
|
||||
package builder
|
||||
package basic
|
||||
|
||||
import (
|
||||
"context"
|
@ -1,4 +1,4 @@
|
||||
package builder
|
||||
package basic
|
||||
|
||||
import (
|
||||
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
@ -1,4 +1,4 @@
|
||||
package builder
|
||||
package basic
|
||||
|
||||
import (
|
||||
"context"
|
@ -1,4 +1,4 @@
|
||||
package builder
|
||||
package basic
|
||||
|
||||
import (
|
||||
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
@ -1,4 +1,4 @@
|
||||
package builder
|
||||
package basic
|
||||
|
||||
import (
|
||||
"context"
|
@ -1,4 +1,4 @@
|
||||
package builder
|
||||
package basic
|
||||
|
||||
import (
|
||||
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
@ -1,4 +1,4 @@
|
||||
package builder
|
||||
package basic
|
||||
|
||||
import (
|
||||
"context"
|
@ -1,4 +1,4 @@
|
||||
package builder
|
||||
package basic
|
||||
|
||||
import (
|
||||
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
@ -1,4 +1,4 @@
|
||||
package builder
|
||||
package basic
|
||||
|
||||
import (
|
||||
"context"
|
@ -1,4 +1,4 @@
|
||||
package builder
|
||||
package basic
|
||||
|
||||
import (
|
||||
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
@ -1,4 +1,4 @@
|
||||
package builder
|
||||
package basic
|
||||
|
||||
import (
|
||||
"context"
|
@ -1,4 +1,4 @@
|
||||
package builder
|
||||
package basic
|
||||
|
||||
import (
|
||||
"context"
|
@ -1,4 +1,4 @@
|
||||
package builder
|
||||
package basic
|
||||
|
||||
import (
|
||||
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
@ -1,4 +1,4 @@
|
||||
package builder
|
||||
package basic
|
||||
|
||||
import (
|
||||
"context"
|
@ -1,4 +1,4 @@
|
||||
package builder
|
||||
package basic
|
||||
|
||||
import (
|
||||
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
@ -1,95 +1,130 @@
|
||||
package builder
|
||||
|
||||
import (
|
||||
"context"
|
||||
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/endpoints"
|
||||
"fmt"
|
||||
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/builder/basic"
|
||||
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// FavoritesBuilder represents a builder for constructing queries to retrieve user's favorite posts.
|
||||
type FavoritesBuilder interface {
|
||||
// SetUserID sets the user ID for the query.
|
||||
SetUserID(userID model.UserID) FavoritesBuilder
|
||||
// SetLimit sets the maximum number of favorite posts to retrieve.
|
||||
SetLimit(limitFavorites int) FavoritesBuilder
|
||||
// Page sets the page number for paginated results.
|
||||
Page(pageNumber int) FavoritesBuilder
|
||||
// Execute sends the constructed query and returns a slice of favorite posts and an error if any.
|
||||
FromUsername(username string) FavoritesBuilder
|
||||
FromUserID(userID model.UserID) FavoritesBuilder
|
||||
WithTags(tags []string) FavoritesBuilder
|
||||
Limit(amount int) FavoritesBuilder
|
||||
Execute() ([]model.Post, error)
|
||||
}
|
||||
|
||||
// NewGetFavoritesBuilder creates a new instance of FavoritesBuilder with the provided RequestContext.
|
||||
//
|
||||
// Parameters:
|
||||
// - requestContext: The context for the API request, including the host, user agent, username, and API key.
|
||||
//
|
||||
// Returns:
|
||||
// - FavoritesBuilder: An instance of the FavoritesBuilder interface.
|
||||
func NewGetFavoritesBuilder(requestContext model.RequestContext) FavoritesBuilder {
|
||||
return &getFavorites{
|
||||
requestContext: requestContext,
|
||||
query: make(map[string]string),
|
||||
}
|
||||
}
|
||||
|
||||
// getFavorites is an implementation of the FavoritesBuilder interface.
|
||||
type getFavorites struct {
|
||||
query map[string]string
|
||||
requestContext model.RequestContext
|
||||
user model.User
|
||||
tags string
|
||||
limit int
|
||||
error error
|
||||
}
|
||||
|
||||
// SetUserID sets the user ID for the query.
|
||||
//
|
||||
// Parameters:
|
||||
// - userID: The ID of the user whose favorite posts are to be retrieved.
|
||||
//
|
||||
// Returns:
|
||||
// - FavoritesBuilder: The instance of the FavoritesBuilder for method chaining.
|
||||
func (g *getFavorites) SetUserID(userID model.UserID) FavoritesBuilder {
|
||||
g.query["user_id"] = strconv.Itoa(int(userID))
|
||||
func (g *getFavorites) FromUsername(username string) FavoritesBuilder {
|
||||
user := model.User{Name: username}
|
||||
g.user = user
|
||||
return g
|
||||
}
|
||||
|
||||
// SetLimit sets the maximum number of favorite posts to retrieve.
|
||||
//
|
||||
// Parameters:
|
||||
// - limitFavorites: The maximum number of favorite posts to retrieve.
|
||||
//
|
||||
// Returns:
|
||||
// - FavoritesBuilder: The instance of the FavoritesBuilder for method chaining.
|
||||
func (g *getFavorites) SetLimit(limitFavorites int) FavoritesBuilder {
|
||||
g.query["limit"] = strconv.Itoa(limitFavorites)
|
||||
func (g *getFavorites) FromUserID(userID model.UserID) FavoritesBuilder {
|
||||
user := model.User{ID: userID}
|
||||
g.user = user
|
||||
return g
|
||||
}
|
||||
|
||||
// Page sets the page number for paginated results.
|
||||
//
|
||||
// Parameters:
|
||||
// - pageNumber: The page number for paginated results.
|
||||
//
|
||||
// Returns:
|
||||
// - FavoritesBuilder: The instance of the FavoritesBuilder for method chaining.
|
||||
func (g *getFavorites) Page(pageNumber int) FavoritesBuilder {
|
||||
g.query["page"] = strconv.Itoa(pageNumber)
|
||||
func (g *getFavorites) WithTags(tagList []string) FavoritesBuilder {
|
||||
tags := strings.Join(tagList, ",")
|
||||
g.tags = tags
|
||||
return g
|
||||
}
|
||||
|
||||
// Execute sends the constructed query and returns a slice of favorite posts and an error if any.
|
||||
//
|
||||
// Returns:
|
||||
// - []model.Post: A slice of favorite posts.
|
||||
// - error: An error, if any, encountered during the API request or response handling.
|
||||
func (g *getFavorites) Execute() ([]model.Post, error) {
|
||||
if g.requestContext.RateLimiter != nil {
|
||||
err := g.requestContext.RateLimiter.Wait(context.Background())
|
||||
func (g *getFavorites) Limit(amount int) FavoritesBuilder {
|
||||
g.limit = amount
|
||||
return g
|
||||
}
|
||||
|
||||
func (g getFavorites) Execute() ([]model.Post, error) {
|
||||
var err error
|
||||
basicFavoritesBuilder := basic.NewGetFavoritesBuilder(g.requestContext)
|
||||
var userFavorites []model.Post
|
||||
|
||||
if g.user.ID == 0 && g.user.Name == "" {
|
||||
return nil, fmt.Errorf("no UserID or UserName given")
|
||||
}
|
||||
|
||||
if g.user.Name != "" {
|
||||
g.user, err = basic.NewGetUserBuilder(g.requestContext).SetUsername(g.user.Name).Execute()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
favorites, err := endpoints.GetFavorites(g.requestContext, g.query)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
if g.user.ID != 0 {
|
||||
basicFavoritesBuilder.SetUserID(g.user.ID)
|
||||
}
|
||||
|
||||
if g.limit != 0 {
|
||||
basicFavoritesBuilder.SetLimit(g.limit)
|
||||
}
|
||||
|
||||
if g.tags == "" {
|
||||
userFavorites, err = basicFavoritesBuilder.Execute()
|
||||
}
|
||||
|
||||
if g.tags != "" {
|
||||
// TODO: implement with tags (channels)
|
||||
}
|
||||
|
||||
return userFavorites, err
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
// GetNFavoritesForUser retrieves a specified number of favorites for a user.
|
||||
func (c *CLient) GetNFavoritesForUser(n int, favoriteBuilder basic.FavoritesBuilder) ([]model.Post, error) {
|
||||
// Retrieves a specified number of favorite posts for a user.
|
||||
if n < utils.E621_MAX_POST_COUNT {
|
||||
favoriteBuilder.SetLimit(n)
|
||||
}
|
||||
|
||||
var favorites []model.Post
|
||||
var page = 1
|
||||
for len(favorites) < n {
|
||||
favoriteBuilder.Page(page)
|
||||
favoriteBuilder.SetLimit(n - len(favorites))
|
||||
newFavorites, err := favoriteBuilder.Execute()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(newFavorites) == 0 {
|
||||
break
|
||||
}
|
||||
favorites = append(favorites, newFavorites...)
|
||||
page = page + 1
|
||||
}
|
||||
|
||||
return favorites, nil
|
||||
}
|
||||
|
||||
// GetAllFavoritesForUser retrieves all favorites for a user.
|
||||
func (c *Client) GetAllFavoritesForUser(favoriteBuilder basic.FavoritesBuilder) ([]model.Post, error) {
|
||||
// Retrieves all favorite posts for a user.
|
||||
return c.GetNFavoritesForUser(math.MaxInt, favoriteBuilder)
|
||||
}
|
||||
|
||||
// GetFavoritesForUserWithTags returns a posts builder for a user's favorites with specific tags.
|
||||
func (c *Client) GetFavoritesForUserWithTags(username string, tags string) basic.PostsBuilder {
|
||||
// Returns a posts builder for a user's favorites with specific tags.
|
||||
favoritesBuilder := basic.NewGetPostsBuilder(c.RequestContext).Tags(fmt.Sprintf("fav:%s %s", username, tags))
|
||||
return favoritesBuilder
|
||||
}
|
||||
*/
|
||||
|
@ -5,7 +5,7 @@ import (
|
||||
"compress/gzip"
|
||||
"encoding/csv"
|
||||
"fmt"
|
||||
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/builder"
|
||||
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/builder/basic"
|
||||
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
||||
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/utils"
|
||||
"github.com/gocarina/gocsv"
|
||||
@ -44,88 +44,88 @@ func NewClient(username string, apiKey string) Client {
|
||||
//
|
||||
// Returns:
|
||||
// - builder.UserBuilder: An instance of the UserBuilder.
|
||||
func (c *Client) GetUserBuilder() builder.UserBuilder {
|
||||
return builder.NewGetUserBuilder(c.RequestContext)
|
||||
func (c *Client) GetUserBuilder() basic.UserBuilder {
|
||||
return basic.NewGetUserBuilder(c.RequestContext)
|
||||
}
|
||||
|
||||
// GetUsersBuilder returns a UsersBuilder instance for creating and executing requests to retrieve multiple users' information from the e621 API.
|
||||
//
|
||||
// Returns:
|
||||
// - builder.UsersBuilder: An instance of the UsersBuilder.
|
||||
func (c *Client) GetUsersBuilder() builder.UsersBuilder {
|
||||
return builder.NewGetUsersBuilder(c.RequestContext)
|
||||
func (c *Client) GetUsersBuilder() basic.UsersBuilder {
|
||||
return basic.NewGetUsersBuilder(c.RequestContext)
|
||||
}
|
||||
|
||||
// GetFavoritesBuilder returns a FavoritesBuilder instance for creating and executing requests to retrieve a user's favorite posts from the e621 API.
|
||||
//
|
||||
// Returns:
|
||||
// - builder.FavoritesBuilder: An instance of the FavoritesBuilder.
|
||||
func (c *Client) GetFavoritesBuilder() builder.FavoritesBuilder {
|
||||
return builder.NewGetFavoritesBuilder(c.RequestContext)
|
||||
func (c *Client) GetFavoritesBuilder() basic.FavoritesBuilder {
|
||||
return basic.NewGetFavoritesBuilder(c.RequestContext)
|
||||
}
|
||||
|
||||
// GetPostBuilder returns a PostBuilder instance for creating and executing requests to retrieve post information from the e621 API.
|
||||
//
|
||||
// Returns:
|
||||
// - builder.PostBuilder: An instance of the PostBuilder.
|
||||
func (c *Client) GetPostBuilder() builder.PostBuilder {
|
||||
return builder.NewGetPostBuilder(c.RequestContext)
|
||||
func (c *Client) GetPostBuilder() basic.PostBuilder {
|
||||
return basic.NewGetPostBuilder(c.RequestContext)
|
||||
}
|
||||
|
||||
// GetPostsBuilder returns a PostsBuilder instance for creating and executing requests to retrieve multiple posts' information from the e621 API.
|
||||
//
|
||||
// Returns:
|
||||
// - builder.PostsBuilder: An instance of the PostsBuilder.
|
||||
func (c *Client) GetPostsBuilder() builder.PostsBuilder {
|
||||
return builder.NewGetPostsBuilder(c.RequestContext)
|
||||
func (c *Client) GetPostsBuilder() basic.PostsBuilder {
|
||||
return basic.NewGetPostsBuilder(c.RequestContext)
|
||||
}
|
||||
|
||||
// GetNoteBuilder returns a NoteBuilder instance for creating and executing requests to retrieve note information from the e621 API.
|
||||
//
|
||||
// Returns:
|
||||
// - builder.NoteBuilder: An instance of the NoteBuilder.
|
||||
func (c *Client) GetNoteBuilder() builder.NoteBuilder {
|
||||
return builder.NewGetNoteBuilder(c.RequestContext)
|
||||
func (c *Client) GetNoteBuilder() basic.NoteBuilder {
|
||||
return basic.NewGetNoteBuilder(c.RequestContext)
|
||||
}
|
||||
|
||||
// GetNotesBuilder returns a NotesBuilder instance for creating and executing requests to retrieve multiple notes' information from the e621 API.
|
||||
//
|
||||
// Returns:
|
||||
// - builder.NotesBuilder: An instance of the NotesBuilder.
|
||||
func (c *Client) GetNotesBuilder() builder.NotesBuilder {
|
||||
return builder.NewGetNotesBuilder(c.RequestContext)
|
||||
func (c *Client) GetNotesBuilder() basic.NotesBuilder {
|
||||
return basic.NewGetNotesBuilder(c.RequestContext)
|
||||
}
|
||||
|
||||
// GetPoolBuilder returns a PoolBuilder instance for creating and executing requests to retrieve pool information from the e621 API.
|
||||
//
|
||||
// Returns:
|
||||
// - builder.PoolBuilder: An instance of the PoolBuilder.
|
||||
func (c *Client) GetPoolBuilder() builder.PoolBuilder {
|
||||
return builder.NewGetPoolBuilder(c.RequestContext)
|
||||
func (c *Client) GetPoolBuilder() basic.PoolBuilder {
|
||||
return basic.NewGetPoolBuilder(c.RequestContext)
|
||||
}
|
||||
|
||||
// GetPoolsBuilder returns a PoolsBuilder instance for creating and executing requests to retrieve multiple pools' information from the e621 API.
|
||||
//
|
||||
// Returns:
|
||||
// - builder.PoolsBuilder: An instance of the PoolsBuilder.
|
||||
func (c *Client) GetPoolsBuilder() builder.PoolsBuilder {
|
||||
return builder.NewGetPoolsBuilder(c.RequestContext)
|
||||
func (c *Client) GetPoolsBuilder() basic.PoolsBuilder {
|
||||
return basic.NewGetPoolsBuilder(c.RequestContext)
|
||||
}
|
||||
|
||||
// GetTagBuilder returns a TagBuilder instance for creating and executing requests to retrieve tag information from the e621 API.
|
||||
//
|
||||
// Returns:
|
||||
// - builder.TagBuilder: An instance of the TagBuilder.
|
||||
func (c *Client) GetTagBuilder() builder.TagBuilder {
|
||||
return builder.NewGetTagBuilder(c.RequestContext)
|
||||
func (c *Client) GetTagBuilder() basic.TagBuilder {
|
||||
return basic.NewGetTagBuilder(c.RequestContext)
|
||||
}
|
||||
|
||||
// GetTagsBuilder returns a TagsBuilder instance for creating and executing requests to retrieve multiple tags' information from the e621 API.
|
||||
//
|
||||
// Returns:
|
||||
// - builder.TagsBuilder: An instance of the TagsBuilder.
|
||||
func (c *Client) GetTagsBuilder() builder.TagsBuilder {
|
||||
return builder.NewGetTagsBuilder(c.RequestContext)
|
||||
func (c *Client) GetTagsBuilder() basic.TagsBuilder {
|
||||
return basic.NewGetTagsBuilder(c.RequestContext)
|
||||
}
|
||||
|
||||
// SetHost sets the API host for the client.
|
||||
@ -143,30 +143,30 @@ func (c *Client) SetAgentName(userAgent string) *Client {
|
||||
}
|
||||
|
||||
// GetUserByName returns a user builder for a given username.
|
||||
func (c *Client) GetUserByName(username string) builder.UserBuilder {
|
||||
func (c *Client) GetUserByName(username string) basic.UserBuilder {
|
||||
// Returns a user builder for the specified username.
|
||||
return builder.NewGetUserBuilder(c.RequestContext).SetUsername(username)
|
||||
return basic.NewGetUserBuilder(c.RequestContext).SetUsername(username)
|
||||
}
|
||||
|
||||
// GetUserByID returns a user builder for a given user ID.
|
||||
func (c *Client) GetUserByID(userID model.UserID) builder.UserBuilder {
|
||||
func (c *Client) GetUserByID(userID model.UserID) basic.UserBuilder {
|
||||
// Returns a user builder for the specified user ID.
|
||||
return builder.NewGetUserBuilder(c.RequestContext).SetUsername(strconv.FormatInt(int64(userID), 10))
|
||||
return basic.NewGetUserBuilder(c.RequestContext).SetUsername(strconv.FormatInt(int64(userID), 10))
|
||||
}
|
||||
|
||||
// GetFavoritesForUser returns a favorites builder for a given username.
|
||||
func (c *Client) GetFavoritesForUser(username string) (builder.FavoritesBuilder, error) {
|
||||
func (c *Client) GetFavoritesForUser(username string) (basic.FavoritesBuilder, error) {
|
||||
// Returns a favorites builder for the specified username.
|
||||
user, err := builder.NewGetUserBuilder(c.RequestContext).SetUsername(username).Execute()
|
||||
user, err := basic.NewGetUserBuilder(c.RequestContext).SetUsername(username).Execute()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
favoritesBuilder := builder.NewGetFavoritesBuilder(c.RequestContext).SetUserID(user.ID)
|
||||
favoritesBuilder := basic.NewGetFavoritesBuilder(c.RequestContext).SetUserID(user.ID)
|
||||
return favoritesBuilder, nil
|
||||
}
|
||||
|
||||
// GetNFavoritesForUser retrieves a specified number of favorites for a user.
|
||||
func (c *Client) GetNFavoritesForUser(n int, favoriteBuilder builder.FavoritesBuilder) ([]model.Post, error) {
|
||||
func (c *Client) GetNFavoritesForUser(n int, favoriteBuilder basic.FavoritesBuilder) ([]model.Post, error) {
|
||||
// Retrieves a specified number of favorite posts for a user.
|
||||
if n < utils.E621_MAX_POST_COUNT {
|
||||
favoriteBuilder.SetLimit(n)
|
||||
@ -192,32 +192,32 @@ func (c *Client) GetNFavoritesForUser(n int, favoriteBuilder builder.FavoritesBu
|
||||
}
|
||||
|
||||
// GetAllFavoritesForUser retrieves all favorites for a user.
|
||||
func (c *Client) GetAllFavoritesForUser(favoriteBuilder builder.FavoritesBuilder) ([]model.Post, error) {
|
||||
func (c *Client) GetAllFavoritesForUser(favoriteBuilder basic.FavoritesBuilder) ([]model.Post, error) {
|
||||
// Retrieves all favorite posts for a user.
|
||||
return c.GetNFavoritesForUser(math.MaxInt, favoriteBuilder)
|
||||
}
|
||||
|
||||
// GetFavoritesForUserWithTags returns a posts builder for a user's favorites with specific tags.
|
||||
func (c *Client) GetFavoritesForUserWithTags(username string, tags string) builder.PostsBuilder {
|
||||
func (c *Client) GetFavoritesForUserWithTags(username string, tags string) basic.PostsBuilder {
|
||||
// Returns a posts builder for a user's favorites with specific tags.
|
||||
favoritesBuilder := builder.NewGetPostsBuilder(c.RequestContext).Tags(fmt.Sprintf("fav:%s %s", username, tags))
|
||||
favoritesBuilder := basic.NewGetPostsBuilder(c.RequestContext).Tags(fmt.Sprintf("fav:%s %s", username, tags))
|
||||
return favoritesBuilder
|
||||
}
|
||||
|
||||
// GetPostByID returns a post builder for a specific post ID.
|
||||
func (c *Client) GetPostByID(id model.PostID) builder.PostBuilder {
|
||||
func (c *Client) GetPostByID(id model.PostID) basic.PostBuilder {
|
||||
// Returns a post builder for a specific post ID.
|
||||
return builder.NewGetPostBuilder(c.RequestContext).SetPostID(id)
|
||||
return basic.NewGetPostBuilder(c.RequestContext).SetPostID(id)
|
||||
}
|
||||
|
||||
// GetPosts returns a posts builder for general post queries.
|
||||
func (c *Client) GetPosts() builder.PostsBuilder {
|
||||
func (c *Client) GetPosts() basic.PostsBuilder {
|
||||
// Returns a posts builder for general post queries.
|
||||
return builder.NewGetPostsBuilder(c.RequestContext)
|
||||
return basic.NewGetPostsBuilder(c.RequestContext)
|
||||
}
|
||||
|
||||
// GetNPosts retrieves a specified number of posts.
|
||||
func (c *Client) GetNPosts(n int, postBuilder builder.PostsBuilder) ([]model.Post, error) {
|
||||
func (c *Client) GetNPosts(n int, postBuilder basic.PostsBuilder) ([]model.Post, error) {
|
||||
// Retrieves a specified number of posts using the provided post builder.
|
||||
if n < utils.E621_MAX_POST_COUNT {
|
||||
postBuilder.SetLimit(n)
|
||||
@ -246,18 +246,18 @@ func (c *Client) GetNPosts(n int, postBuilder builder.PostsBuilder) ([]model.Pos
|
||||
}
|
||||
|
||||
// GetAllPosts retrieves all available posts using the provided post builder.
|
||||
func (c *Client) GetAllPosts(postBuilder builder.PostsBuilder) ([]model.Post, error) {
|
||||
func (c *Client) GetAllPosts(postBuilder basic.PostsBuilder) ([]model.Post, error) {
|
||||
// Retrieves all available posts using the provided post builder.
|
||||
return c.GetNPosts(math.MaxInt, postBuilder)
|
||||
}
|
||||
|
||||
func (c *Client) GetLatestPoolsDBExportDataAsBytes() (string, []byte, error) {
|
||||
dbExportFileNameList, err := builder.NewGetDBExportListBuilder(c.RequestContext).Execute()
|
||||
dbExportFileNameList, err := basic.NewGetDBExportListBuilder(c.RequestContext).Execute()
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
|
||||
getDBExportFile := builder.NewGetDBExportFileBuilder(c.RequestContext)
|
||||
getDBExportFile := basic.NewGetDBExportFileBuilder(c.RequestContext)
|
||||
|
||||
filter := func(s string) bool { return strings.HasPrefix(s, "pools") }
|
||||
filteredFileNameList := utils.SliceFilter(dbExportFileNameList, filter)
|
||||
@ -323,12 +323,12 @@ func (c *Client) GetLatestPoolsDBExportDataAsStruct() ([]*model.Pool, error) {
|
||||
|
||||
func (c *Client) GetLatestPostsDBExportDataAsBytes() (string, []byte, error) {
|
||||
log.Println("Please wait while the download is in progress for the post export... (file over 1GB) ")
|
||||
dbExportFileNameList, err := builder.NewGetDBExportListBuilder(c.RequestContext).Execute()
|
||||
dbExportFileNameList, err := basic.NewGetDBExportListBuilder(c.RequestContext).Execute()
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
|
||||
getDBExportFile := builder.NewGetDBExportFileBuilder(c.RequestContext)
|
||||
getDBExportFile := basic.NewGetDBExportFileBuilder(c.RequestContext)
|
||||
|
||||
filter := func(s string) bool { return strings.HasPrefix(s, "posts") }
|
||||
filteredFileNameList := utils.SliceFilter(dbExportFileNameList, filter)
|
||||
|
Reference in New Issue
Block a user