GetUser returns account-level information for the authenticated user
(accessToken string)
| 435 | |
| 436 | // GetUser returns account-level information for the authenticated user |
| 437 | func (c *Client) GetUser(accessToken string) (*DashboardUser, error) { |
| 438 | req, err := http.NewRequest(http.MethodGet, c.APIURL+"/1/user", nil) |
| 439 | if err != nil { |
| 440 | return nil, err |
| 441 | } |
| 442 | c.setAPIHeaders(req, accessToken) |
| 443 | |
| 444 | resp, err := c.client.Do(req) |
| 445 | if err != nil { |
| 446 | return nil, fmt.Errorf("Couldn't get your account details: %w", err) |
| 447 | } |
| 448 | defer resp.Body.Close() |
| 449 | |
| 450 | if resp.StatusCode == http.StatusUnauthorized { |
| 451 | return nil, ErrSessionExpired |
| 452 | } |
| 453 | if resp.StatusCode != http.StatusOK { |
| 454 | return nil, fmt.Errorf("Couldn't get your account details: %d", resp.StatusCode) |
| 455 | } |
| 456 | |
| 457 | var userResp userResponse |
| 458 | if err := json.NewDecoder(resp.Body).Decode(&userResp); err != nil { |
| 459 | return nil, fmt.Errorf("Couldn't get your account details: %w", err) |
| 460 | } |
| 461 | |
| 462 | user := userResp.toUser() |
| 463 | return &user, nil |
| 464 | } |
| 465 | |
| 466 | // ChangeApplicationPlan changes the plan of an application |
| 467 | func (c *Client) ChangeApplicationPlan(accessToken, appID, plan string) (*Application, error) { |