Class: CopyAi::ResponseParser
- Inherits:
-
Object
- Object
- CopyAi::ResponseParser
- Defined in:
- lib/copy_ai/response_parser.rb
Constant Summary collapse
- ERROR_MAP =
{ 400 => BadRequest, 401 => Unauthorized, 403 => Forbidden, 404 => NotFound, 406 => NotAcceptable, 409 => ConnectionException, 410 => Gone, 413 => PayloadTooLarge, 422 => UnprocessableEntity, 500 => InternalServerError, 502 => BadGateway, 503 => ServiceUnavailable, 504 => GatewayTimeout }.freeze
- JSON_CONTENT_TYPE_REGEXP =
%r{application/json}
Instance Method Summary collapse
Instance Method Details
#parse(response:) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/copy_ai/response_parser.rb', line 37 def parse(response:) raise error(response) unless response.is_a?(Net::HTTPSuccess) return unless json?(response) JSON.parse(response.body) end |