Added DMail support #5

Merged
fenpaws merged 11 commits from develop/dm into main 2024-07-11 11:58:03 +00:00
Showing only changes of commit d8eee5bc1b - Show all commits

View File

@ -1,81 +1,65 @@
package main package main
import ( import (
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/endpoints"
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
_ "github.com/joho/godotenv/autoload"
"log" "log"
"net/http" "net/http"
"os" "os"
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/endpoints"
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
_ "github.com/joho/godotenv/autoload"
) )
func main() { func main() {
// Define the request context with essential information.
requestContext := model.RequestContext{ requestContext := model.RequestContext{
Client: http.Client{}, Client: http.Client{},
Host: "https://e621.net", Host: "https://e621.net",
UserAgent: "Go-e621-SDK (@username)", UserAgent: "Go-e621-SDK (@username)",
Username: os.Getenv("API_USER"), // Replace with your username Username: os.Getenv("API_USER"),
APIKey: os.Getenv("API_KEY"), // Replace with your API key APIKey: os.Getenv("API_KEY"),
} }
// Log: Getting a single post. log.Println("Getting a DMail by ID:")
log.Println("Getting single dm: ") dmail, err := endpoints.GetDmail(requestContext, 1)
// Specify the post ID for retrieval.
dMailID := 2062973 // Replace with the desired post's ID.
// Call the GetPost function to retrieve the specified post.
dmail, err := endpoints.GetDmail(requestContext, dMailID)
if err != nil { if err != nil {
log.Println(err) log.Println(err)
} else { } else {
// Log the URL of the retrieved post.
log.Println(dmail.Body) log.Println(dmail.Body)
} }
log.Println("----------") log.Println("----------")
// Log: Getting a list of posts. log.Println("Deleting a DMail by ID:")
log.Println("Getting a list of posts: ") err = endpoints.DeleteDmail(requestContext, 1)
if err != nil {
log.Println(err)
}
log.Println("----------")
// Define query parameters for retrieving a list of posts. log.Println("Marking a DMail as read by ID:")
err = endpoints.MarkAsReadDmail(requestContext, 1)
if err != nil {
log.Println(err)
}
log.Println("----------")
log.Println("Getting all DMails:")
query := map[string]string{ query := map[string]string{
"title_matches": "test", "limit": "5",
} }
dmails, err := endpoints.GetAllDmails(requestContext, query)
// Call the GetPosts function to retrieve a list of posts based on the query parameters.
posts, err := endpoints.GetDmails(requestContext, query)
if err != nil { if err != nil {
log.Println(err) log.Println(err)
} else { } else {
// Log the number of posts retrieved. for _, dmail := range dmails {
log.Println(posts[0].Body) log.Println(dmail.Body)
}
} }
log.Println("----------") log.Println("----------")
log.Println("Mark all DMails as read: ") log.Println("Marking all DMails as read:")
err = endpoints.MarkAsReadAllDmails(requestContext)
// Call the ReadAllDmails function to set all DMails as read.
err = endpoints.ReadAllDmails(requestContext)
if err != nil { if err != nil {
log.Println(err) log.Println(err)
} else {
log.Println("read all posts")
}
log.Println("----------")
log.Println("Delete all DMails as read: ")
// Call the ReadAllDmails function to set all DMails as read.
err = endpoints.DeleateDmail(requestContext, dMailID)
if err != nil {
log.Println(err)
} else {
log.Println("DMail deleted")
} }
log.Println("----------") log.Println("----------")
} }