feat: add support for archive endpoint

This commit is contained in:
2022-09-15 23:30:16 +01:00
parent 3f46417c3b
commit afb6594729

46
archive.go Normal file
View File

@@ -0,0 +1,46 @@
package midjourney
import (
"context"
"encoding/json"
"fmt"
"net/http"
"net/url"
"time"
)
func (c *Client) ArchiveDay(
ctx context.Context,
date time.Time,
) (jobIDs []string, err error) {
u := &url.URL{
Path: "app/archive/day/",
RawQuery: url.Values{
"day": []string{date.Format("2")},
"month": []string{date.Format("1")},
"year": []string{date.Format("2006")},
}.Encode(),
}
req, err := http.NewRequestWithContext(ctx, http.MethodGet, u.String(), nil)
if err != nil {
return nil, err
}
resp, err := c.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("%w: %s", ErrResponseStatus, resp.Status)
}
err = json.NewDecoder(resp.Body).Decode(&jobIDs)
if err != nil {
return nil, err
}
return jobIDs, nil
}