Module: ApiAdaptor

Defined in:
lib/api_adaptor.rb,
lib/api_adaptor/base.rb,
lib/api_adaptor/headers.rb,
lib/api_adaptor/version.rb,
lib/api_adaptor/response.rb,
lib/api_adaptor/variables.rb,
lib/api_adaptor/exceptions.rb,
lib/api_adaptor/json_client.rb,
lib/api_adaptor/null_logger.rb,
lib/api_adaptor/list_response.rb

Overview

ApiAdaptor provides a framework for building JSON API clients with minimal boilerplate.

It handles common patterns like request/response parsing, authentication, redirect handling, pagination, and error management, allowing you to focus on your API's specific logic.

Examples:

Building a simple API client

class MyApiClient < ApiAdaptor::Base
  def initialize
    super("https://api.example.com")
  end

  def get_user(id)
    get_json("/users/#{id}")
  end

  def create_user(data)
    post_json("/users", data)
  end
end

client = MyApiClient.new
user = client.get_user(123)

Using JSONClient directly

client = ApiAdaptor::JSONClient.new(bearer_token: "abc123")
response = client.get_json("https://api.example.com/data")
puts response["items"]

See Also:

Defined Under Namespace

Modules: ExceptionHandling, Variables Classes: Base, BaseError, EndpointNotFound, Error, HTTPBadGateway, HTTPBadRequest, HTTPClientError, HTTPConflict, HTTPErrorResponse, HTTPForbidden, HTTPGatewayTimeout, HTTPGone, HTTPIntermittentClientError, HTTPIntermittentServerError, HTTPInternalServerError, HTTPNotFound, HTTPPayloadTooLarge, HTTPServerError, HTTPTooManyRequests, HTTPUnauthorized, HTTPUnavailable, HTTPUnprocessableContent, HTTPUnprocessableEntity, Headers, InvalidUrl, JsonClient, ListResponse, NullLogger, RedirectLocationMissing, Response, SocketErrorException, TimedOutException, TooManyRedirects

Constant Summary collapse

VERSION =
"1.0.0"