Project

jeckle

0.01
No commit activity in last 3 years
No release in over 3 years
There's a lot of open issues
Simple module for building client APIs
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 1.6
= 3.1.0
>= 0
~> 3.2

Runtime

 Project Readme

Jeckle

Build Status Code Climate Test Coverage

Wrap APIs with easiness and flexibility.

Jeckle

Heckle usually refers to Jeckle familiarly, as "chum" or "pal", while Jeckle often calls Heckle "old chap", "old thing", "old boy" or "old featherhead", indicating a close friendship between them.

Extracted from Wikipedia

Let third party APIs be Heckle for your app's Jeckle.

Installation

Add this line to your application's Gemfile:

gem 'jeckle'

And then execute:

$ bundle

Usage

Configuring an API

Let's say you'd like to connect your app to Dribbble.com - a community of designers sharing screenshots of their work, process, and projects.

First, you would need to configure the API:

Jeckle.configure do |config|
  config.register :dribbble do |api|
    api.base_uri = 'http://api.dribbble.com'
    api.middlewares do
      response :json
    end
  end
end

Mapping resources

Following the previous example, Dribbble.com consists of pieces of web designers work called "Shots". Each shot has the attributes id, name, url and image_url. A Jeckle resource representing Dribbble's shots would be something like this:

class Shot
  include Jeckle::Resource

  api :dribbble

  attribute :id, Integer
  attribute :name, String
  attribute :url, String
  attribute :image_url, String
end

Fetching data

The resource class allows us to search shots through HTTP requests to the API, based on the provided information. For example, we can find a specific shot by providing its id to the find method:

# GET http://api.dribbble.com/shots/1600459
shot = Shot.find 1600459

That will return a Shot instance, containing the shot info:

shot.id
=> 1600459

shot.name
=> "Daryl Heckle And Jeckle Oates"

shot.image_url
=> "https://d13yacurqjgara.cloudfront.net/users/85699/screenshots/1600459/daryl_heckle_and_jeckle_oates-dribble.jpg"

You can also look for many shots matching one or more attributes, by using the search method:

# GET http://api.dribbble.com/shots?name=avengers
shots = Shot.search name: 'avengers'

Attribute Aliasing

Sometimes you want to call the API's attributes something else, either because their names aren't very concise or because they're out of you app's convention. If that's the case, you can add an as option:

attribute :thumbnailSize, String, as: :thumbnail_size

Both mapping will work:

shot.thumbnailSize
=> "50x50"

shot.thumbnail_size
=> "50x50"

We're all set! Now we can expand the mapping of our API, e.g to add ability to search Dribbble Designer directory by adding Designer class, or we can expand the original mapping of Shot class to include more attributes, such as tags or comments.

Examples

You can see more examples here: https://github.com/tomas-stefano/jeckle/tree/master/examples

Roadmap

Follow GitHub's milestones