mirror of
https://github.com/crunchy-labs/crunchy-cli.git
synced 2026-01-21 12:12:00 -06:00
Move functions into their own, separate files & add docs
This commit is contained in:
parent
d1859b4c25
commit
ec872d8c86
12 changed files with 681 additions and 638 deletions
30
account.go
30
account.go
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue