Project

apicake

0.01
Low commit activity in last 3 years
A long-lived project that still receives updates
Build Dynamic API Wrappers
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

>= 0
>= 0
~> 0.3
~> 0.20
 Project Readme

API Cake - Build Dynamic API Wrappers

Gem Version Build Status Maintainability


This gem allows you to easily build rich API wrappers with minimal code.

It is HTTParty with a Cake.


Install

$ gem install apicake

Or with bundler:

gem 'apicake'

TL;DR

Turn this hypothetical API URL:

http://api.recipes.com/cakes?layers=3 

To this:

recipes = Recipes.new
recipes.cakes layers:3

Using this code only:

class Recipes < APICake::Base
  base_uri 'api.recipes.com'
end

Features

  • Uses HTTParty
  • Built in caching
  • Built in save to file
  • Built in response parsing (part of HTTParty)
  • Built in convert and save to CSV
  • Designed for GET-only APIs (e.g., data services)

Usage

Create a class and inherit from APICake::Base.

This class automatically includes HTTParty, so you can do whatever you do in HTTParty. In addition, the APICake::Base class defines a method_missing method, so any call to an undefined method, will simply be converted to a URL.

For example:

class Recipes << APICake::Base
  base_uri 'api.recipes.com/v1'
end

recipes = Recipes.new

# This will access http://api.recipes.com/v1/cakes
recipes.cakes

# This will access http://api.recipes.com/v1/cakes/chocolate
recipes.cakes 'chocolate'

# This will access http://api.recipes.com/v1/cakes/chocolate?layers=3
recipes.cakes 'chocolate', layers: 3

See the Examples folder for more examples.

Caching

APICake uses Lightly for caching. By default, cached objects are stored in the ./cache directory for 3600 seconds.

See the caching example.

Method Reference

For a detailed explanation of the services and methods you get when inheriting from APICake::Base, see the class documentation.

Real World Examples

These gems use APICake: