| 165 | } |
| 166 | |
| 167 | func (c *Client) FetchPricingBatch(requests BatchPricingRequest) (*BatchPricingApiResponse, error) { |
| 168 | endpoint := APIBaseURL + "/pricing/batch" |
| 169 | status, respBytes, err := c.post(endpoint, requests, true) |
| 170 | if err != nil { |
| 171 | return nil, fmt.Errorf("failed to connect to batch pricing API: %w", err) |
| 172 | } |
| 173 | if status == http.StatusNotFound { |
| 174 | return nil, nil |
| 175 | } |
| 176 | if status >= 300 { |
| 177 | return nil, fmt.Errorf("batch pricing request failed (%d): %s", status, string(respBytes)) |
| 178 | } |
| 179 | |
| 180 | var result BatchPricingApiResponse |
| 181 | if err := json.Unmarshal(respBytes, &result); err != nil { |
| 182 | preview := string(respBytes) |
| 183 | if len(preview) > 500 { |
| 184 | preview = preview[:500] |
| 185 | } |
| 186 | return nil, fmt.Errorf("failed to parse batch pricing response: %w (first 500 chars: %s)", err, preview) |
| 187 | } |
| 188 | return &result, nil |
| 189 | } |
| 190 | |
| 191 | // DownloadMetadataGz downloads /pricing/metadata and saves as metadata.json.gz. |
| 192 | func (c *Client) DownloadMetadataGz() error { |