Skip to content
This repository has been archived by the owner on May 25, 2023. It is now read-only.

grape-entity has been moved into separate project #1

Merged
merged 3 commits into from
Mar 3, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.9.3-p194
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@ gem 'jquery-rails'
# To use debugger
# gem 'debugger'

gem 'grape'
gem 'grape'
gem 'grape-entity'
27 changes: 21 additions & 6 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ GEM
i18n (~> 0.6)
multi_json (~> 1.0)
arel (3.0.2)
backports (2.6.7)
builder (3.0.2)
coffee-rails (3.2.2)
coffee-script (>= 2.2.0)
Expand All @@ -37,15 +38,23 @@ GEM
coffee-script-source
execjs
coffee-script-source (1.3.3)
descendants_tracker (0.0.1)
erubis (2.7.0)
execjs (1.4.0)
multi_json (~> 1.0)
grape (0.2.1)
grape (0.2.6)
activesupport
builder
hashie (~> 1.2)
multi_json
multi_xml
multi_json (>= 1.3.2)
multi_xml (>= 0.5.2)
rack
rack-accept
rack-mount
virtus
grape-entity (0.2.0)
activesupport
multi_json (>= 1.3.2)
hashie (1.2.0)
hike (1.2.1)
i18n (0.6.1)
Expand All @@ -59,10 +68,12 @@ GEM
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.19)
multi_json (1.3.6)
multi_xml (0.5.1)
multi_json (1.5.0)
multi_xml (0.5.3)
polyglot (0.3.3)
rack (1.4.1)
rack (1.4.5)
rack-accept (0.4.5)
rack (>= 0.4)
rack-cache (1.2)
rack (>= 0.4)
rack-mount (0.8.3)
Expand Down Expand Up @@ -108,13 +119,17 @@ GEM
uglifier (1.3.0)
execjs (>= 0.3.0)
multi_json (~> 1.0, >= 1.0.2)
virtus (0.5.4)
backports (~> 2.6.1)
descendants_tracker (~> 0.0.1)

PLATFORMS
ruby

DEPENDENCIES
coffee-rails (~> 3.2.1)
grape
grape-entity
jquery-rails
rails (= 3.2.8)
sass-rails (~> 3.2.3)
Expand Down
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Blog API

This is an example application showing how to use [grape](https://github.com/intridea/grape) to create a simple API using entities.
This sample show cases how to create a simple API without authentication, caching, custom
This is an example application showing how to use
[grape](https://github.com/intridea/grape) to create a simple API using
entities from the newly-extracted grape-entity gem. This sample show
cases how to create a simple API without authentication, caching, custom
errors and such other things to build a robust public API.

I wrote the sample because I was unable to find a sample to cover the basics of grape.
Expand All @@ -14,7 +16,8 @@ sample may still work, but there is no guarantee.
1. Rails 3.2.8
2. ruby 1.9.3p194
3. OS X 10.8.1 (aka Mountain Lion)
4. Grape (0.2.1)
4. Grape (0.2.6)
5. Grape Entity (0.2.0)

## Setup

Expand Down
5 changes: 4 additions & 1 deletion app/api/blog/entities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@ module Entities
class Weblog < Grape::Entity
expose :title, :documentation => {:type => "string", :desc => "The title of the weblog"}
expose :description, :documentation => {:type => "string", :desc => "A description of the weblog"}
expose :id, :documentation => {:type => "integer", :desc => "The numeric id of the weblog"}
end

class Post < Grape::Entity
expose :title, :documentation => {:type => "string", :desc => "The title of the weblog"}
expose :body, :documentation => {:type => "string", :desc => "The body of the post"}
expose :id, :documentation => {:type => "integer", :desc => "The numeric id of the post"}
end

class Comment < Grape::Entity
expose :name, :documentation => {:type => "string", :desc => "The name of the commentor"}
expose :body, :documentation => {:type => "string", :desc => "The body of the post"}
expose :id, :documentation => {:type => "integer", :desc => "The numeric id of the post"}
end
end
end
end