35 lines
1.3 KiB
Go
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
|
|
}
|