Commit 5a8f0041f4f2e214ba94e0d608eca45248c52b14
Committed by
Rodrigo Souto
1 parent
10899ba4
Exists in
api_tasks
and in
4 other branches
remove redundancy of use with param
Showing
2 changed files
with
10 additions
and
5 deletions
Show diff stats
lib/api/entities.rb
... | ... | @@ -2,7 +2,8 @@ module API |
2 | 2 | module Entities |
3 | 3 | class Article < Grape::Entity |
4 | 4 | root 'articles', 'article' |
5 | - expose :id, :name, :body, :created_at | |
5 | + expose :id, :body, :created_at | |
6 | + expose :title, :documentation => {:type => "String", :desc => "Title of the article"} | |
6 | 7 | |
7 | 8 | expose :author do |article, options| |
8 | 9 | { | ... | ... |
lib/api/v1/articles.rb
... | ... | @@ -15,6 +15,9 @@ module API |
15 | 15 | # |
16 | 16 | # Example Request: |
17 | 17 | # GET /articles?from=2013-04-04-14:41:43&until=2014-04-04-14:41:43&limit=10&type=Blog |
18 | +# desc 'Articles.', { | |
19 | +# :params => API::Entities::Article.documentation | |
20 | +# } | |
18 | 21 | get do |
19 | 22 | from_date = DateTime.parse(params[:from]) if params[:from] |
20 | 23 | until_date = DateTime.parse(params[:until]) if params[:until] |
... | ... | @@ -30,19 +33,20 @@ module API |
30 | 33 | conditions = {} |
31 | 34 | conditions[:type] = params[:content_type] if params[:content_type] #FIXME validate type |
32 | 35 | conditions[:created_at] = begin_period...end_period |
33 | - present environment.articles.find(:all, :conditions => conditions, :offset => (from_date.nil? ? 0 : 1), :limit => limit, :order => "created_at DESC"), :with => Entities::Article | |
36 | + present environment.articles.find(:all, :conditions => conditions, :offset => (from_date.nil? ? 0 : 1), :limit => limit, :order => "created_at DESC") | |
34 | 37 | end |
35 | 38 | |
39 | + desc "Return the article id" | |
36 | 40 | get ':id' do |
37 | - present environment.articles.find(params[:id]), :with => Entities::Article | |
41 | + present environment.articles.find(params[:id]) | |
38 | 42 | end |
39 | 43 | |
40 | 44 | get ':id/children' do |
41 | - present environment.articles.find(params[:id]).children, :with => Entities::Article | |
45 | + present environment.articles.find(params[:id]).children | |
42 | 46 | end |
43 | 47 | |
44 | 48 | get ':id/children/:child_id' do |
45 | - present environment.articles.find(params[:id]).children.find(params[:child_id]), :with => Entities::Article | |
49 | + present environment.articles.find(params[:id]).children.find(params[:child_id]) | |
46 | 50 | end |
47 | 51 | |
48 | 52 | ... | ... |