add action items menu

This commit is contained in:
juancwu 2026-01-21 21:27:08 +00:00
commit 4266bfbfc2
5 changed files with 172 additions and 20 deletions

View file

@ -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
}