add action items menu
This commit is contained in:
parent
4b92d2e7c4
commit
4266bfbfc2
5 changed files with 172 additions and 20 deletions
|
|
@ -25,3 +25,49 @@ func New(apiKey, secretKey string) *Client {
|
|||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Client) Ping() (*PingResponse, error) {
|
||||
reqBody := PingRequest{
|
||||
BaseRequest: BaseRequest{
|
||||
APIKey: c.APIKey,
|
||||
SecretAPIKey: c.SecretAPIKey,
|
||||
},
|
||||
}
|
||||
|
||||
var resp PingResponse
|
||||
err := c.post("/ping", reqBody, &resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
func (c *Client) post(endpoint string, body interface{}, target interface{}) error {
|
||||
jsonBody, err := json.Marshal(body)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to marshal request body: %w", err)
|
||||
}
|
||||
|
||||
req, err := http.NewRequest("POST", BaseURL+endpoint, bytes.NewBuffer(jsonBody))
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create request: %w", err)
|
||||
}
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
res, err := c.HTTPClient.Do(req)
|
||||
if err != nil {
|
||||
return fmt.Errorf("request failed: %w", err)
|
||||
}
|
||||
defer res.Body.Close()
|
||||
|
||||
if res.StatusCode >= 400 {
|
||||
return fmt.Errorf("API returned error status: %d", res.StatusCode)
|
||||
}
|
||||
|
||||
if err := json.NewDecoder(res.Body).Decode(target); err != nil {
|
||||
return fmt.Errorf("failed to decode response: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue