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/endpoints/post.go
SoXX 9669eb8ddf refactor: removed code duplication
Signed-off-by: SoXX <soxx@fenpa.ws>
2023-11-15 14:02:15 +01:00

35 lines
1.3 KiB
Go

package endpoints
import (
"fmt"
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
)
// GetPost retrieves a single post by its ID from the e621 API.
//
// Parameters: // - requestContext: The context for the API request, including the host, user agent, username, and API key.
// - ID: The ID of the post to retrieve.
//
// Returns:
// - model.Post: The retrieved post.
// - error: An error, if any, encountered during the API request or response handling.
func GetPost(requestContext model.RequestContext, ID string) (model.Post, error) {
endpoint := fmt.Sprintf("posts/%s.json", ID)
return getRequest[model.Post](requestContext, endpoint, nil)
}
// GetPosts retrieves a list of posts from the e621 API based on query parameters.
//
// Parameters:
// - requestContext: The context for the API request, including the host, user agent, username, and API key.
// - query: A map containing additional query parameters for the API request.
//
// Returns:
// - []model.Post: A slice of posts.
// - error: An error, if any, encountered during the API request or response handling.
func GetPosts(requestContext model.RequestContext, query map[string]string) ([]model.Post, error) {
endpoint := "posts.json"
data, err := getRequest[model.PostResponse](requestContext, endpoint, query)
return data.Posts, err
}