Class: Anthropic::Client::Standard
- Defined in:
- lib/anthropic/client/standard.rb
Overview
Provides a client for sending standard HTTP requests.
Class Method Summary collapse
-
.post(url, data, headers = {}) ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity.
Class Method Details
.post(url, data, headers = {}) ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/anthropic/client/standard.rb', line 9 def self.post(url, data, headers = {}) response = HTTPX.with( headers: { 'Content-Type' => 'application/json', 'x-api-key' => Anthropic.api_key, 'anthropic-version' => Anthropic.api_version }.merge(headers) ).post(url, json: data) response_data = build_response(response.body) case response.status when 200 response_data when 400 raise Anthropic::Client::InvalidRequestError, response_data when 401 raise Anthropic::Client::AuthenticationError, response_data when 403 raise Anthropic::Client::PermissionError, response_data when 404 raise Anthropic::Client::NotFoundError, response_data when 409 raise Anthropic::Client::ConflictError, response_data when 422 raise Anthropic::Client::UnprocessableEntityError, response_data when 429 raise Anthropic::Client::RateLimitError, response_data when 500 raise Anthropic::Client::ApiError, response_data when 529 raise Anthropic::Client::OverloadedError, response_data end end |