Move functions into their own, separate files & add docs

This commit is contained in:
bytedream 2022-06-21 21:15:49 +02:00
parent d1859b4c25
commit ec872d8c86
12 changed files with 681 additions and 638 deletions

View file

@ -3,10 +3,40 @@ package crunchyroll
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
"time"
)
// Account returns information about the currently logged in crunchyroll account.
func (c *Crunchyroll) Account() (*Account, error) {
resp, err := c.request("https://beta.crunchyroll.com/accounts/v1/me", http.MethodGet)
if err != nil {
return nil, err
}
defer resp.Body.Close()
account := &Account{
crunchy: c,
}
if err = json.NewDecoder(resp.Body).Decode(&account); err != nil {
return nil, fmt.Errorf("failed to parse 'me' response: %w", err)
}
resp, err = c.request("https://beta.crunchyroll.com/accounts/v1/me/profile", http.MethodGet)
if err != nil {
return nil, err
}
defer resp.Body.Close()
if err = json.NewDecoder(resp.Body).Decode(&account); err != nil {
return nil, fmt.Errorf("failed to parse 'profile' response: %w", err)
}
return account, nil
}
// Account contains information about a crunchyroll account.
type Account struct {
crunchy *Crunchyroll