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,7 +2,8 @@ module API | ||
2 | module Entities | 2 | module Entities |
3 | class Article < Grape::Entity | 3 | class Article < Grape::Entity |
4 | root 'articles', 'article' | 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 | expose :author do |article, options| | 8 | expose :author do |article, options| |
8 | { | 9 | { |
lib/api/v1/articles.rb
@@ -15,6 +15,9 @@ module API | @@ -15,6 +15,9 @@ module API | ||
15 | # | 15 | # |
16 | # Example Request: | 16 | # Example Request: |
17 | # GET /articles?from=2013-04-04-14:41:43&until=2014-04-04-14:41:43&limit=10&type=Blog | 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 | get do | 21 | get do |
19 | from_date = DateTime.parse(params[:from]) if params[:from] | 22 | from_date = DateTime.parse(params[:from]) if params[:from] |
20 | until_date = DateTime.parse(params[:until]) if params[:until] | 23 | until_date = DateTime.parse(params[:until]) if params[:until] |
@@ -30,19 +33,20 @@ module API | @@ -30,19 +33,20 @@ module API | ||
30 | conditions = {} | 33 | conditions = {} |
31 | conditions[:type] = params[:content_type] if params[:content_type] #FIXME validate type | 34 | conditions[:type] = params[:content_type] if params[:content_type] #FIXME validate type |
32 | conditions[:created_at] = begin_period...end_period | 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 | end | 37 | end |
35 | 38 | ||
39 | + desc "Return the article id" | ||
36 | get ':id' do | 40 | get ':id' do |
37 | - present environment.articles.find(params[:id]), :with => Entities::Article | 41 | + present environment.articles.find(params[:id]) |
38 | end | 42 | end |
39 | 43 | ||
40 | get ':id/children' do | 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 | end | 46 | end |
43 | 47 | ||
44 | get ':id/children/:child_id' do | 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 | end | 50 | end |
47 | 51 | ||
48 | 52 |