diff --git a/lib/api/api.rb b/lib/api/api.rb index 509b08c..8f7ea97 100644 --- a/lib/api/api.rb +++ b/lib/api/api.rb @@ -9,7 +9,7 @@ module API content_type :txt, "text/plain" helpers APIHelpers - + mount V1::Articles mount V1::Comments mount V1::Users diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb index 8fb1e39..126a442 100644 --- a/lib/api/helpers.rb +++ b/lib/api/helpers.rb @@ -168,7 +168,7 @@ module API private - def default_limit + def default_limit 20 end diff --git a/lib/api/v1/articles.rb b/lib/api/v1/articles.rb index 207dbf0..cb1b0db 100644 --- a/lib/api/v1/articles.rb +++ b/lib/api/v1/articles.rb @@ -3,7 +3,7 @@ module API class Articles < Grape::API before { detect_stuff_by_domain } before { authenticate! } - + resource :articles do # Collect comments from articles @@ -19,18 +19,18 @@ module API # :params => API::Entities::Article.documentation # } get do - + conditions = make_conditions_with_parameter(params) - + if params[:reference_id] articles = environment.articles.send("#{params.key?(:oldest) ? 'older_than' : 'newer_than'}", params[:reference_id]).find(:all, :conditions => conditions, :limit => limit, :order => "created_at DESC") else articles = environment.articles.find(:all, :conditions => conditions, :limit => limit, :order => "created_at DESC") end - present articles, :with => Entities::Article + present articles, :with => Entities::Article end - - desc "Return the article id" + + desc "Return the article id" get ':id' do present environment.articles.find(params[:id]), :with => Entities::Article end @@ -45,7 +45,7 @@ module API else articles = environment.articles.find(params[:id]).children.find(:all, :conditions => conditions, :limit => limit, :order => "created_at DESC") end - present articles, :with => Entities::Article + present articles, :with => Entities::Article end get ':id/children/:child_id' do @@ -54,7 +54,7 @@ module API end - + end end end diff --git a/lib/api/v1/comments.rb b/lib/api/v1/comments.rb index 76509b9..5e29520 100644 --- a/lib/api/v1/comments.rb +++ b/lib/api/v1/comments.rb @@ -1,10 +1,10 @@ module API module V1 class Comments < Grape::API - + before { detect_stuff_by_domain } before { authenticate! } - + resource :articles do # Collect comments from articles # @@ -27,18 +27,18 @@ module API present comments, :with => Entities::Comment end - + get ":id/comments/:comment_id" do present environment.articles.find(params[:id]).comments.find(params[:comment_id]), :with => Entities::Comment end - + # Example Request: # POST api/v1/articles/12/comments?private_toke=234298743290432&body=new comment post ":id/comments" do present environment.articles.find(params[:id]).comments.create(:author => current_person, :body => params[:body]), :with => Entities::Comment end end - + end end end diff --git a/lib/api/v1/users.rb b/lib/api/v1/users.rb index 31a145c..6113b7e 100644 --- a/lib/api/v1/users.rb +++ b/lib/api/v1/users.rb @@ -1,23 +1,23 @@ module API module V1 class Users < Grape::API - + before { authenticate! } - + resource :users do - + #FIXME make the pagination #FIXME put it on environment context get do present User.all, :with => Entities::User end - + get ":id" do present User.find(params[:id]), :with => Entities::User end - + end - + end end end -- libgit2 0.21.2