package e621
import (
"e621_to_neo4j/e621/models"
"fmt"
"io"
"net/http"
"time"
)
// GetUserInfo retrieves the users information from e621 API.
func (c *Client) GetUserInfo(user string) (models.E621User, error) {
var e621User models.E621User
time.Sleep(2 * time.Second)
url := fmt.Sprintf("%s/users/%s.json", baseURL, user)
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return e621User, err
}
req.Header.Set("User-Agent", "FavGetter (by Selloo)")
req.Header.Add("Accept", "application/json")
req.SetBasicAuth(c.username, c.apiKey)
resp, err := c.client.Do(req)
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if resp.StatusCode != http.StatusOK {
return e621User, fmt.Errorf("failed to retrieve posts: %s", resp.Status)
e621User, err = models.UnmarshalE621User(body)
return e621User, nil