From 5a8f0041f4f2e214ba94e0d608eca45248c52b14 Mon Sep 17 00:00:00 2001 From: Leandro Nunes dos Santos Date: Mon, 7 Apr 2014 22:56:07 -0300 Subject: [PATCH] remove redundancy of use with param --- lib/api/entities.rb | 3 ++- lib/api/v1/articles.rb | 12 ++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 5e18c3a..8ff1a97 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -2,7 +2,8 @@ module API module Entities class Article < Grape::Entity root 'articles', 'article' - expose :id, :name, :body, :created_at + expose :id, :body, :created_at + expose :title, :documentation => {:type => "String", :desc => "Title of the article"} expose :author do |article, options| { diff --git a/lib/api/v1/articles.rb b/lib/api/v1/articles.rb index 0ba7d35..9543b28 100644 --- a/lib/api/v1/articles.rb +++ b/lib/api/v1/articles.rb @@ -15,6 +15,9 @@ module API # # Example Request: # GET /articles?from=2013-04-04-14:41:43&until=2014-04-04-14:41:43&limit=10&type=Blog +# desc 'Articles.', { +# :params => API::Entities::Article.documentation +# } get do from_date = DateTime.parse(params[:from]) if params[:from] until_date = DateTime.parse(params[:until]) if params[:until] @@ -30,19 +33,20 @@ module API conditions = {} conditions[:type] = params[:content_type] if params[:content_type] #FIXME validate type conditions[:created_at] = begin_period...end_period - present environment.articles.find(:all, :conditions => conditions, :offset => (from_date.nil? ? 0 : 1), :limit => limit, :order => "created_at DESC"), :with => Entities::Article + present environment.articles.find(:all, :conditions => conditions, :offset => (from_date.nil? ? 0 : 1), :limit => limit, :order => "created_at DESC") end + desc "Return the article id" get ':id' do - present environment.articles.find(params[:id]), :with => Entities::Article + present environment.articles.find(params[:id]) end get ':id/children' do - present environment.articles.find(params[:id]).children, :with => Entities::Article + present environment.articles.find(params[:id]).children end get ':id/children/:child_id' do - present environment.articles.find(params[:id]).children.find(params[:child_id]), :with => Entities::Article + present environment.articles.find(params[:id]).children.find(params[:child_id]) end -- libgit2 0.21.2