feat: finished low level implementation of DMs
This commit is contained in:
parent
467c951720
commit
5c9266edb5
@ -3,9 +3,11 @@ package endpoints
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
"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"
|
||||||
"net/http"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetDmail(requestContext model.RequestContext, ID int) (model.DMail, error) {
|
func GetDmail(requestContext model.RequestContext, ID int) (model.DMail, error) {
|
||||||
@ -80,7 +82,33 @@ func DeleateDmail(requestContext model.RequestContext, ID int) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetDmails(requestContext model.RequestContext, query map[string]string) ([]model.DMail, error) {
|
func MarkAsReadDmail(requestContext model.RequestContext, ID int) error {
|
||||||
|
// Create a new HTTP GET request to fetch the post information.
|
||||||
|
r, err := http.NewRequest("PUT", fmt.Sprintf("%s/dmails/%d/mark_as_read.json", requestContext.Host, ID), nil)
|
||||||
|
log.Print(r.URL)
|
||||||
|
|
||||||
|
r.Header.Set("User-Agent", requestContext.UserAgent)
|
||||||
|
r.Header.Add("Accept", "application/json")
|
||||||
|
r.SetBasicAuth(requestContext.Username, requestContext.APIKey)
|
||||||
|
|
||||||
|
// Send the request using the provided http.Client.
|
||||||
|
resp, err := requestContext.Client.Do(r)
|
||||||
|
if err != nil {
|
||||||
|
// Log the error and return an empty Post struct and the error.
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if the HTTP response status code indicates success (2xx range).
|
||||||
|
if resp.StatusCode < 200 || resp.StatusCode > 300 {
|
||||||
|
// If the status code is outside the 2xx range, return an error based on the status code.
|
||||||
|
return utils.StatusCodesToError(resp.StatusCode)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return the post information and no error (nil).
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetAllDmails(requestContext model.RequestContext, query map[string]string) ([]model.DMail, error) {
|
||||||
// Create a new HTTP GET request.
|
// Create a new HTTP GET request.
|
||||||
r, err := http.NewRequest("GET", fmt.Sprintf("%s/dmails.json", requestContext.Host), nil)
|
r, err := http.NewRequest("GET", fmt.Sprintf("%s/dmails.json", requestContext.Host), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -125,7 +153,7 @@ func GetDmails(requestContext model.RequestContext, query map[string]string) ([]
|
|||||||
return postResponse, nil
|
return postResponse, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func ReadAllDmails(requestContext model.RequestContext) error {
|
func MarkAsReadAllDmails(requestContext model.RequestContext) error {
|
||||||
// Create a new HTTP GET request to fetch the post information.
|
// Create a new HTTP GET request to fetch the post information.
|
||||||
r, err := http.NewRequest("PUT", fmt.Sprintf("%s/dmails/mark_all_as_read.json", requestContext.Host), nil)
|
r, err := http.NewRequest("PUT", fmt.Sprintf("%s/dmails/mark_all_as_read.json", requestContext.Host), nil)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user