Project

apii

0.0
No commit activity in last 3 years
No release in over 3 years
This gem provides a generic API client to interact with any HTTP hypermedia APIs.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

 Project Readme

API wrapper

Description

This gem is a generic client for HTTP based APIs.

Installation

You can use this gem in your project by specifying it in your Gemfile:

gem "apii"

or simply install it via the CLI:

gem install apii

Usage

Create your own API client my inheriting from the Api::Client class and defining all mandatory defaults attributes in a Namespace::Default module as such:

module ExampleApi
  class Client < Api::Client
    # Include mandatory modules
    include Api::Configurable
    include Api::Connection
    include Api::Authentication
  end

  module Default
    API_ENDPOINT = "http://example.org".freeze

    class << self

      # Include mandatory module
      include Api::DefaultOptions

      def api_endpoint
        API_ENDPOINT
      end

    end
 end
end

Now get started requesting stuff from your api:

c = ExampleApi::Client.new
 => ...

c.root
 => "<!doctype html>\n..."

c.last_response.data == c.get("/")
 => true

c.get("/boom")
 raises Api::NotFound: #<Sawyer::Response:0x000000029bb908>

License

Code licensed under MIT-LICENSE