Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoene committed Sep 17, 2014
1 parent 1442ae5 commit 2c91fdb
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
language: ruby
rvm:
- 1.9.3
- 2.0.0
- 2.1.2
24 changes: 13 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Frenchy

Frenchy is a thing for turning HTTP JSON API endpoints into Rails-ish model objects. It deals with making requests, converting responses, type conversion, struct nesting, model decorating and instrumentation.
[![Gem Version](https://badge.fury.io/rb/frenchy.png)](https://rubygems.org/gems/frenchy) [![Build Status](https://travis-ci.org/jcoene/frenchy.png)](https://travis-ci.org/jcoene/frenchy) [![Coverage Status](https://coveralls.io/repos/jcoene/frenchy/badge.png?branch=master)](https://coveralls.io/r/jcoene/frenchy)

Frenchy is an opinionated modeling framework for consuming HTTP+JSON API endpoints as ActiveModel-like objects. It deals with making requests, converting responses, type conversion, struct nesting, model decorating and instrumentation. Frenchy is used in production at [Dotabuff](http://dotabuff.com) serving millions of requests per day.

## Installation

Expand All @@ -10,11 +12,11 @@ Add this line to your application's Gemfile:

And then execute:

$ bundle
$ bundle install

## Usage

Frenchy supports multiple back-end services, you should register them in an initializer:
Frenchy supports multiple back-end services. If you're using Rails, register them in an initializer:

```ruby
# config/initializer/frenchy.rb
Expand All @@ -34,7 +36,7 @@ class Player
# Declare which service the model belongs to and specify your named API endpoints
resource service: "dodgeball", endpoints: {
one: { path: "/v1/players/:id" },
many: { path: "/v1/players", many: true },
many: { path: "/v1/players", many: true },
team: { path: "/v1/teams/:team_id/players", many: true }
}

Expand All @@ -43,23 +45,23 @@ class Player

# Define fields which create named attributes and deal with typecasting.
# Valid built-in types: string, integer, float, bool, time, array, hash
field :id, type: "integer"
field :name, type: "string"
field :win_rate, type: "float"
field :free_agent, type: "bool"
field :id, type: "integer"
field :name, type: "string"
field :win_rate, type: "float"
field :free_agent, type: "bool"

# You can also supply types of any class that can be instantiated by sending
# a hash of attributes to the "new" class method. If you specify the "many"
# option, we'll expect that the server returns an array and will properly treat
# the response as a collection.
field :nicknames, type: "nickname", many: true
field :nicknames, type: "nickname", many: true
end

class Nickname
include Frenchy::Model

field :name, type: "string"
field :insulting, type: "bool"
field :name, type: "string"
field :insulting, type: "bool"
end

# GET /v1/players/1
Expand Down
1 change: 1 addition & 0 deletions frenchie.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "guard-rspec"
spec.add_development_dependency "rake"
spec.add_development_dependency "rspec"
spec.add_development_dependency "coveralls"
spec.add_development_dependency "activesupport", ">= 3.0"
spec.add_development_dependency "activemodel", ">= 3.0"
end
3 changes: 3 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
require "coveralls"
Coveralls.wear!

require "frenchy"

RSpec.configure do |config|
Expand Down

0 comments on commit 2c91fdb

Please sign in to comment.