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
|
package main
|
||||||
|
|
||||||
import (
|
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"
|
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -19,7 +19,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
log.Println("Getting a list of DB Exports: ")
|
log.Println("Getting a list of DB Exports: ")
|
||||||
getDBExportList := builder.NewGetDBExportListBuilder(requestContext)
|
getDBExportList := basic.NewGetDBExportListBuilder(requestContext)
|
||||||
dbExportFiles, err := getDBExportList.Execute()
|
dbExportFiles, err := getDBExportList.Execute()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
@ -35,7 +35,7 @@ func main() {
|
|||||||
exportFileName := dbExportFiles[0]
|
exportFileName := dbExportFiles[0]
|
||||||
log.Println("Downloading DB export")
|
log.Println("Downloading DB export")
|
||||||
log.Printf("File to download: %s", exportFileName)
|
log.Printf("File to download: %s", exportFileName)
|
||||||
getDBExportFile := builder.NewGetDBExportFileBuilder(requestContext)
|
getDBExportFile := basic.NewGetDBExportFileBuilder(requestContext)
|
||||||
|
|
||||||
rawFile, err := getDBExportFile.SetFile(exportFileName).Execute()
|
rawFile, err := getDBExportFile.SetFile(exportFileName).Execute()
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
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"
|
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
||||||
_ "github.com/joho/godotenv/autoload"
|
_ "github.com/joho/godotenv/autoload"
|
||||||
"log"
|
"log"
|
||||||
@ -23,7 +23,7 @@ func main() {
|
|||||||
log.Println("Getting favorites API user: ")
|
log.Println("Getting favorites API user: ")
|
||||||
|
|
||||||
// Call the GetFavorites function to retrieve favorite posts.
|
// Call the GetFavorites function to retrieve favorite posts.
|
||||||
getFavorites := builder.NewGetFavoritesBuilder(requestContext)
|
getFavorites := basic.NewGetFavoritesBuilder(requestContext)
|
||||||
posts, err := getFavorites.SetLimit(5).Execute()
|
posts, err := getFavorites.SetLimit(5).Execute()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
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"
|
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
||||||
_ "github.com/joho/godotenv/autoload"
|
_ "github.com/joho/godotenv/autoload"
|
||||||
"log"
|
"log"
|
||||||
@ -27,7 +27,7 @@ func main() {
|
|||||||
noteID := 36957 // Replace with the desired note's ID.
|
noteID := 36957 // Replace with the desired note's ID.
|
||||||
|
|
||||||
// Call the GetNote function to retrieve the specified note.
|
// Call the GetNote function to retrieve the specified note.
|
||||||
getNote := builder.NewGetNoteBuilder(requestContext)
|
getNote := basic.NewGetNoteBuilder(requestContext)
|
||||||
note, err := getNote.SetNoteID(noteID).Execute()
|
note, err := getNote.SetNoteID(noteID).Execute()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -42,7 +42,7 @@ func main() {
|
|||||||
log.Println("Getting a list of notes: ")
|
log.Println("Getting a list of notes: ")
|
||||||
|
|
||||||
// Call the GetNotes function to retrieve a list of notes based on the query parameters.
|
// 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()
|
notes, err := getNotes.SetLimit(5).Active(true).SearchInBody("furry").Execute()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
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"
|
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
||||||
_ "github.com/joho/godotenv/autoload"
|
_ "github.com/joho/godotenv/autoload"
|
||||||
"log"
|
"log"
|
||||||
@ -26,7 +26,7 @@ func main() {
|
|||||||
poolID := 36957 // Replace with the desired pool's ID.
|
poolID := 36957 // Replace with the desired pool's ID.
|
||||||
|
|
||||||
// Call the GetPool function to retrieve the specified pool.
|
// Call the GetPool function to retrieve the specified pool.
|
||||||
getPool := builder.NewGetPoolBuilder(requestContext)
|
getPool := basic.NewGetPoolBuilder(requestContext)
|
||||||
pool, err := getPool.ID(poolID).Execute()
|
pool, err := getPool.ID(poolID).Execute()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -41,7 +41,7 @@ func main() {
|
|||||||
log.Println("Getting a list of pools: ")
|
log.Println("Getting a list of pools: ")
|
||||||
|
|
||||||
// Call the GetPools function to retrieve a list of pools based on the query parameters.
|
// 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()
|
pools, err := getPools.SetLimit(5).Active(true).SearchDescription("mass effect").Execute()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
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"
|
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
||||||
_ "github.com/joho/godotenv/autoload"
|
_ "github.com/joho/godotenv/autoload"
|
||||||
"log"
|
"log"
|
||||||
@ -26,7 +26,7 @@ func main() {
|
|||||||
var postID model.PostID = 4353480 // Replace with the desired post's ID.
|
var postID model.PostID = 4353480 // Replace with the desired post's ID.
|
||||||
|
|
||||||
// Call the GetPost function to retrieve the specified post.
|
// Call the GetPost function to retrieve the specified post.
|
||||||
getPost := builder.NewGetPostBuilder(requestContext)
|
getPost := basic.NewGetPostBuilder(requestContext)
|
||||||
post, err := getPost.SetPostID(postID).Execute()
|
post, err := getPost.SetPostID(postID).Execute()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -41,7 +41,7 @@ func main() {
|
|||||||
log.Println("Getting a list of posts: ")
|
log.Println("Getting a list of posts: ")
|
||||||
|
|
||||||
// Call the GetPosts function to retrieve a list of posts based on the query parameters.
|
// 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()
|
posts, err := getPosts.SetLimit(5).Execute()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
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"
|
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
||||||
_ "github.com/joho/godotenv/autoload"
|
_ "github.com/joho/godotenv/autoload"
|
||||||
"log"
|
"log"
|
||||||
@ -26,7 +26,7 @@ func main() {
|
|||||||
tagID := 1530 // Replace with the desired tag's ID.
|
tagID := 1530 // Replace with the desired tag's ID.
|
||||||
|
|
||||||
// Call the GetTag function to retrieve the specified tag.
|
// Call the GetTag function to retrieve the specified tag.
|
||||||
getTag := builder.NewGetTagBuilder(requestContext)
|
getTag := basic.NewGetTagBuilder(requestContext)
|
||||||
tag, err := getTag.SetTagID(tagID).Execute()
|
tag, err := getTag.SetTagID(tagID).Execute()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -41,7 +41,7 @@ func main() {
|
|||||||
log.Println("Getting a list of tags: ")
|
log.Println("Getting a list of tags: ")
|
||||||
|
|
||||||
// Call the GetTags function to retrieve a list of tags based on the query parameters.
|
// 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()
|
tagList, err := getTags.SetLimit(5).Artist(false).Execute()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
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"
|
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
||||||
_ "github.com/joho/godotenv/autoload"
|
_ "github.com/joho/godotenv/autoload"
|
||||||
"log"
|
"log"
|
||||||
@ -26,7 +26,7 @@ func main() {
|
|||||||
username := "selloo" // Replace with the desired username.
|
username := "selloo" // Replace with the desired username.
|
||||||
|
|
||||||
// Call the GetUser function to retrieve the specified user.
|
// Call the GetUser function to retrieve the specified user.
|
||||||
userBuilder := builder.NewGetUserBuilder(requestContext)
|
userBuilder := basic.NewGetUserBuilder(requestContext)
|
||||||
user, err := userBuilder.SetUsername(username).Execute()
|
user, err := userBuilder.SetUsername(username).Execute()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -41,7 +41,7 @@ func main() {
|
|||||||
log.Println("Getting a list of users: ")
|
log.Println("Getting a list of users: ")
|
||||||
|
|
||||||
// Call the GetUsers function to retrieve a list of users based on the query parameters.
|
// 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()
|
userList, err := usersBuilder.SetLimit(5).Execute()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package builder
|
package basic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/endpoints"
|
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/endpoints"
|
@ -1,4 +1,4 @@
|
|||||||
package builder
|
package basic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/endpoints"
|
"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 (
|
import (
|
||||||
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
@ -1,4 +1,4 @@
|
|||||||
package builder
|
package basic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
@ -1,4 +1,4 @@
|
|||||||
package builder
|
package basic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
@ -1,4 +1,4 @@
|
|||||||
package builder
|
package basic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
@ -1,4 +1,4 @@
|
|||||||
package builder
|
package basic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
@ -1,4 +1,4 @@
|
|||||||
package builder
|
package basic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
@ -1,4 +1,4 @@
|
|||||||
package builder
|
package basic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
@ -1,4 +1,4 @@
|
|||||||
package builder
|
package basic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
@ -1,4 +1,4 @@
|
|||||||
package builder
|
package basic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
@ -1,4 +1,4 @@
|
|||||||
package builder
|
package basic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
@ -1,4 +1,4 @@
|
|||||||
package builder
|
package basic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
@ -1,4 +1,4 @@
|
|||||||
package builder
|
package basic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
@ -1,4 +1,4 @@
|
|||||||
package builder
|
package basic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
@ -1,4 +1,4 @@
|
|||||||
package builder
|
package basic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
@ -1,4 +1,4 @@
|
|||||||
package builder
|
package basic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
@ -1,4 +1,4 @@
|
|||||||
package builder
|
package basic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
@ -1,4 +1,4 @@
|
|||||||
package builder
|
package basic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
@ -1,4 +1,4 @@
|
|||||||
package builder
|
package basic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
@ -1,4 +1,4 @@
|
|||||||
package builder
|
package basic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
@ -1,4 +1,4 @@
|
|||||||
package builder
|
package basic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
@ -1,95 +1,130 @@
|
|||||||
package builder
|
package builder
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"fmt"
|
||||||
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/endpoints"
|
"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/model"
|
||||||
"strconv"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// FavoritesBuilder represents a builder for constructing queries to retrieve user's favorite posts.
|
|
||||||
type FavoritesBuilder interface {
|
type FavoritesBuilder interface {
|
||||||
// SetUserID sets the user ID for the query.
|
FromUsername(username string) FavoritesBuilder
|
||||||
SetUserID(userID model.UserID) FavoritesBuilder
|
FromUserID(userID model.UserID) FavoritesBuilder
|
||||||
// SetLimit sets the maximum number of favorite posts to retrieve.
|
WithTags(tags []string) FavoritesBuilder
|
||||||
SetLimit(limitFavorites int) FavoritesBuilder
|
Limit(amount 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)
|
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 {
|
func NewGetFavoritesBuilder(requestContext model.RequestContext) FavoritesBuilder {
|
||||||
return &getFavorites{
|
return &getFavorites{
|
||||||
requestContext: requestContext,
|
requestContext: requestContext,
|
||||||
query: make(map[string]string),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// getFavorites is an implementation of the FavoritesBuilder interface.
|
|
||||||
type getFavorites struct {
|
type getFavorites struct {
|
||||||
query map[string]string
|
|
||||||
requestContext model.RequestContext
|
requestContext model.RequestContext
|
||||||
|
user model.User
|
||||||
|
tags string
|
||||||
|
limit int
|
||||||
|
error error
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetUserID sets the user ID for the query.
|
func (g *getFavorites) FromUsername(username string) FavoritesBuilder {
|
||||||
//
|
user := model.User{Name: username}
|
||||||
// Parameters:
|
g.user = user
|
||||||
// - 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
|
return g
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetLimit sets the maximum number of favorite posts to retrieve.
|
func (g *getFavorites) FromUserID(userID model.UserID) FavoritesBuilder {
|
||||||
//
|
user := model.User{ID: userID}
|
||||||
// Parameters:
|
g.user = user
|
||||||
// - 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
|
return g
|
||||||
}
|
}
|
||||||
|
|
||||||
// Page sets the page number for paginated results.
|
func (g *getFavorites) WithTags(tagList []string) FavoritesBuilder {
|
||||||
//
|
tags := strings.Join(tagList, ",")
|
||||||
// Parameters:
|
g.tags = tags
|
||||||
// - 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
|
return g
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execute sends the constructed query and returns a slice of favorite posts and an error if any.
|
func (g *getFavorites) Limit(amount int) FavoritesBuilder {
|
||||||
//
|
g.limit = amount
|
||||||
// Returns:
|
return g
|
||||||
// - []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) {
|
func (g getFavorites) Execute() ([]model.Post, error) {
|
||||||
if g.requestContext.RateLimiter != nil {
|
var err error
|
||||||
err := g.requestContext.RateLimiter.Wait(context.Background())
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
favorites, err := endpoints.GetFavorites(g.requestContext, g.query)
|
|
||||||
if err != nil {
|
if g.user.ID != 0 {
|
||||||
return nil, err
|
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
|
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"
|
"compress/gzip"
|
||||||
"encoding/csv"
|
"encoding/csv"
|
||||||
"fmt"
|
"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/model"
|
||||||
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/utils"
|
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/utils"
|
||||||
"github.com/gocarina/gocsv"
|
"github.com/gocarina/gocsv"
|
||||||
@ -44,88 +44,88 @@ func NewClient(username string, apiKey string) Client {
|
|||||||
//
|
//
|
||||||
// Returns:
|
// Returns:
|
||||||
// - builder.UserBuilder: An instance of the UserBuilder.
|
// - builder.UserBuilder: An instance of the UserBuilder.
|
||||||
func (c *Client) GetUserBuilder() builder.UserBuilder {
|
func (c *Client) GetUserBuilder() basic.UserBuilder {
|
||||||
return builder.NewGetUserBuilder(c.RequestContext)
|
return basic.NewGetUserBuilder(c.RequestContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetUsersBuilder returns a UsersBuilder instance for creating and executing requests to retrieve multiple users' information from the e621 API.
|
// GetUsersBuilder returns a UsersBuilder instance for creating and executing requests to retrieve multiple users' information from the e621 API.
|
||||||
//
|
//
|
||||||
// Returns:
|
// Returns:
|
||||||
// - builder.UsersBuilder: An instance of the UsersBuilder.
|
// - builder.UsersBuilder: An instance of the UsersBuilder.
|
||||||
func (c *Client) GetUsersBuilder() builder.UsersBuilder {
|
func (c *Client) GetUsersBuilder() basic.UsersBuilder {
|
||||||
return builder.NewGetUsersBuilder(c.RequestContext)
|
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.
|
// GetFavoritesBuilder returns a FavoritesBuilder instance for creating and executing requests to retrieve a user's favorite posts from the e621 API.
|
||||||
//
|
//
|
||||||
// Returns:
|
// Returns:
|
||||||
// - builder.FavoritesBuilder: An instance of the FavoritesBuilder.
|
// - builder.FavoritesBuilder: An instance of the FavoritesBuilder.
|
||||||
func (c *Client) GetFavoritesBuilder() builder.FavoritesBuilder {
|
func (c *Client) GetFavoritesBuilder() basic.FavoritesBuilder {
|
||||||
return builder.NewGetFavoritesBuilder(c.RequestContext)
|
return basic.NewGetFavoritesBuilder(c.RequestContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetPostBuilder returns a PostBuilder instance for creating and executing requests to retrieve post information from the e621 API.
|
// GetPostBuilder returns a PostBuilder instance for creating and executing requests to retrieve post information from the e621 API.
|
||||||
//
|
//
|
||||||
// Returns:
|
// Returns:
|
||||||
// - builder.PostBuilder: An instance of the PostBuilder.
|
// - builder.PostBuilder: An instance of the PostBuilder.
|
||||||
func (c *Client) GetPostBuilder() builder.PostBuilder {
|
func (c *Client) GetPostBuilder() basic.PostBuilder {
|
||||||
return builder.NewGetPostBuilder(c.RequestContext)
|
return basic.NewGetPostBuilder(c.RequestContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetPostsBuilder returns a PostsBuilder instance for creating and executing requests to retrieve multiple posts' information from the e621 API.
|
// GetPostsBuilder returns a PostsBuilder instance for creating and executing requests to retrieve multiple posts' information from the e621 API.
|
||||||
//
|
//
|
||||||
// Returns:
|
// Returns:
|
||||||
// - builder.PostsBuilder: An instance of the PostsBuilder.
|
// - builder.PostsBuilder: An instance of the PostsBuilder.
|
||||||
func (c *Client) GetPostsBuilder() builder.PostsBuilder {
|
func (c *Client) GetPostsBuilder() basic.PostsBuilder {
|
||||||
return builder.NewGetPostsBuilder(c.RequestContext)
|
return basic.NewGetPostsBuilder(c.RequestContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetNoteBuilder returns a NoteBuilder instance for creating and executing requests to retrieve note information from the e621 API.
|
// GetNoteBuilder returns a NoteBuilder instance for creating and executing requests to retrieve note information from the e621 API.
|
||||||
//
|
//
|
||||||
// Returns:
|
// Returns:
|
||||||
// - builder.NoteBuilder: An instance of the NoteBuilder.
|
// - builder.NoteBuilder: An instance of the NoteBuilder.
|
||||||
func (c *Client) GetNoteBuilder() builder.NoteBuilder {
|
func (c *Client) GetNoteBuilder() basic.NoteBuilder {
|
||||||
return builder.NewGetNoteBuilder(c.RequestContext)
|
return basic.NewGetNoteBuilder(c.RequestContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetNotesBuilder returns a NotesBuilder instance for creating and executing requests to retrieve multiple notes' information from the e621 API.
|
// GetNotesBuilder returns a NotesBuilder instance for creating and executing requests to retrieve multiple notes' information from the e621 API.
|
||||||
//
|
//
|
||||||
// Returns:
|
// Returns:
|
||||||
// - builder.NotesBuilder: An instance of the NotesBuilder.
|
// - builder.NotesBuilder: An instance of the NotesBuilder.
|
||||||
func (c *Client) GetNotesBuilder() builder.NotesBuilder {
|
func (c *Client) GetNotesBuilder() basic.NotesBuilder {
|
||||||
return builder.NewGetNotesBuilder(c.RequestContext)
|
return basic.NewGetNotesBuilder(c.RequestContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetPoolBuilder returns a PoolBuilder instance for creating and executing requests to retrieve pool information from the e621 API.
|
// GetPoolBuilder returns a PoolBuilder instance for creating and executing requests to retrieve pool information from the e621 API.
|
||||||
//
|
//
|
||||||
// Returns:
|
// Returns:
|
||||||
// - builder.PoolBuilder: An instance of the PoolBuilder.
|
// - builder.PoolBuilder: An instance of the PoolBuilder.
|
||||||
func (c *Client) GetPoolBuilder() builder.PoolBuilder {
|
func (c *Client) GetPoolBuilder() basic.PoolBuilder {
|
||||||
return builder.NewGetPoolBuilder(c.RequestContext)
|
return basic.NewGetPoolBuilder(c.RequestContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetPoolsBuilder returns a PoolsBuilder instance for creating and executing requests to retrieve multiple pools' information from the e621 API.
|
// GetPoolsBuilder returns a PoolsBuilder instance for creating and executing requests to retrieve multiple pools' information from the e621 API.
|
||||||
//
|
//
|
||||||
// Returns:
|
// Returns:
|
||||||
// - builder.PoolsBuilder: An instance of the PoolsBuilder.
|
// - builder.PoolsBuilder: An instance of the PoolsBuilder.
|
||||||
func (c *Client) GetPoolsBuilder() builder.PoolsBuilder {
|
func (c *Client) GetPoolsBuilder() basic.PoolsBuilder {
|
||||||
return builder.NewGetPoolsBuilder(c.RequestContext)
|
return basic.NewGetPoolsBuilder(c.RequestContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetTagBuilder returns a TagBuilder instance for creating and executing requests to retrieve tag information from the e621 API.
|
// GetTagBuilder returns a TagBuilder instance for creating and executing requests to retrieve tag information from the e621 API.
|
||||||
//
|
//
|
||||||
// Returns:
|
// Returns:
|
||||||
// - builder.TagBuilder: An instance of the TagBuilder.
|
// - builder.TagBuilder: An instance of the TagBuilder.
|
||||||
func (c *Client) GetTagBuilder() builder.TagBuilder {
|
func (c *Client) GetTagBuilder() basic.TagBuilder {
|
||||||
return builder.NewGetTagBuilder(c.RequestContext)
|
return basic.NewGetTagBuilder(c.RequestContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetTagsBuilder returns a TagsBuilder instance for creating and executing requests to retrieve multiple tags' information from the e621 API.
|
// GetTagsBuilder returns a TagsBuilder instance for creating and executing requests to retrieve multiple tags' information from the e621 API.
|
||||||
//
|
//
|
||||||
// Returns:
|
// Returns:
|
||||||
// - builder.TagsBuilder: An instance of the TagsBuilder.
|
// - builder.TagsBuilder: An instance of the TagsBuilder.
|
||||||
func (c *Client) GetTagsBuilder() builder.TagsBuilder {
|
func (c *Client) GetTagsBuilder() basic.TagsBuilder {
|
||||||
return builder.NewGetTagsBuilder(c.RequestContext)
|
return basic.NewGetTagsBuilder(c.RequestContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetHost sets the API host for the client.
|
// 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.
|
// 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.
|
// 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.
|
// 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.
|
// 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.
|
// 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.
|
// 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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
favoritesBuilder := builder.NewGetFavoritesBuilder(c.RequestContext).SetUserID(user.ID)
|
favoritesBuilder := basic.NewGetFavoritesBuilder(c.RequestContext).SetUserID(user.ID)
|
||||||
return favoritesBuilder, nil
|
return favoritesBuilder, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetNFavoritesForUser retrieves a specified number of favorites for a user.
|
// 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.
|
// Retrieves a specified number of favorite posts for a user.
|
||||||
if n < utils.E621_MAX_POST_COUNT {
|
if n < utils.E621_MAX_POST_COUNT {
|
||||||
favoriteBuilder.SetLimit(n)
|
favoriteBuilder.SetLimit(n)
|
||||||
@ -192,32 +192,32 @@ func (c *Client) GetNFavoritesForUser(n int, favoriteBuilder builder.FavoritesBu
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetAllFavoritesForUser retrieves all favorites for a user.
|
// 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.
|
// Retrieves all favorite posts for a user.
|
||||||
return c.GetNFavoritesForUser(math.MaxInt, favoriteBuilder)
|
return c.GetNFavoritesForUser(math.MaxInt, favoriteBuilder)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetFavoritesForUserWithTags returns a posts builder for a user's favorites with specific tags.
|
// 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.
|
// 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
|
return favoritesBuilder
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetPostByID returns a post builder for a specific post ID.
|
// 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.
|
// 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.
|
// 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.
|
// 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.
|
// 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.
|
// Retrieves a specified number of posts using the provided post builder.
|
||||||
if n < utils.E621_MAX_POST_COUNT {
|
if n < utils.E621_MAX_POST_COUNT {
|
||||||
postBuilder.SetLimit(n)
|
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.
|
// 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.
|
// Retrieves all available posts using the provided post builder.
|
||||||
return c.GetNPosts(math.MaxInt, postBuilder)
|
return c.GetNPosts(math.MaxInt, postBuilder)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) GetLatestPoolsDBExportDataAsBytes() (string, []byte, error) {
|
func (c *Client) GetLatestPoolsDBExportDataAsBytes() (string, []byte, error) {
|
||||||
dbExportFileNameList, err := builder.NewGetDBExportListBuilder(c.RequestContext).Execute()
|
dbExportFileNameList, err := basic.NewGetDBExportListBuilder(c.RequestContext).Execute()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", nil, err
|
return "", nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
getDBExportFile := builder.NewGetDBExportFileBuilder(c.RequestContext)
|
getDBExportFile := basic.NewGetDBExportFileBuilder(c.RequestContext)
|
||||||
|
|
||||||
filter := func(s string) bool { return strings.HasPrefix(s, "pools") }
|
filter := func(s string) bool { return strings.HasPrefix(s, "pools") }
|
||||||
filteredFileNameList := utils.SliceFilter(dbExportFileNameList, filter)
|
filteredFileNameList := utils.SliceFilter(dbExportFileNameList, filter)
|
||||||
@ -323,12 +323,12 @@ func (c *Client) GetLatestPoolsDBExportDataAsStruct() ([]*model.Pool, error) {
|
|||||||
|
|
||||||
func (c *Client) GetLatestPostsDBExportDataAsBytes() (string, []byte, 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) ")
|
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 {
|
if err != nil {
|
||||||
return "", nil, err
|
return "", nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
getDBExportFile := builder.NewGetDBExportFileBuilder(c.RequestContext)
|
getDBExportFile := basic.NewGetDBExportFileBuilder(c.RequestContext)
|
||||||
|
|
||||||
filter := func(s string) bool { return strings.HasPrefix(s, "posts") }
|
filter := func(s string) bool { return strings.HasPrefix(s, "posts") }
|
||||||
filteredFileNameList := utils.SliceFilter(dbExportFileNameList, filter)
|
filteredFileNameList := utils.SliceFilter(dbExportFileNameList, filter)
|
||||||
|
Reference in New Issue
Block a user