GetApplication returns a single application by its ID.
(accessToken, appID string)
| 269 | |
| 270 | // GetApplication returns a single application by its ID. |
| 271 | func (c *Client) GetApplication(accessToken, appID string) (*Application, error) { |
| 272 | req, err := http.NewRequest( |
| 273 | http.MethodGet, |
| 274 | c.APIURL+"/1/application/"+url.PathEscape(appID), |
| 275 | nil, |
| 276 | ) |
| 277 | if err != nil { |
| 278 | return nil, err |
| 279 | } |
| 280 | c.setAPIHeaders(req, accessToken) |
| 281 | |
| 282 | resp, err := c.client.Do(req) |
| 283 | if err != nil { |
| 284 | return nil, fmt.Errorf("get application request failed: %w", err) |
| 285 | } |
| 286 | defer resp.Body.Close() |
| 287 | |
| 288 | if resp.StatusCode == http.StatusUnauthorized { |
| 289 | return nil, ErrSessionExpired |
| 290 | } |
| 291 | if resp.StatusCode != http.StatusOK { |
| 292 | return nil, fmt.Errorf("get application failed with status: %d", resp.StatusCode) |
| 293 | } |
| 294 | |
| 295 | var singleResp SingleApplicationResponse |
| 296 | if err := json.NewDecoder(resp.Body).Decode(&singleResp); err != nil { |
| 297 | return nil, fmt.Errorf("failed to parse application response: %w", err) |
| 298 | } |
| 299 | |
| 300 | app := singleResp.Data.toApplication() |
| 301 | return &app, nil |
| 302 | } |
| 303 | |
| 304 | // CreateApplication creates a new application for the authenticated user. |
| 305 | func (c *Client) CreateApplication(accessToken, region, name string) (*Application, error) { |