Commit 31a15be1a17b1bf41357a0a4bf9faed9cacfe6c1

Authored by Leandro Santos
Committed by Rodrigo Souto
1 parent 55d792ba

add community response

Showing 1 changed file with 42 additions and 0 deletions   Show diff stats
lib/api/v1/communities.rb 0 → 100644
... ... @@ -0,0 +1,42 @@
  1 +module API
  2 + module V1
  3 + class Communities < Grape::API
  4 + before { detect_stuff_by_domain }
  5 + before { authenticate! }
  6 +
  7 + resource :communities do
  8 +
  9 + # Collect comments from articles
  10 + #
  11 + # Parameters:
  12 + # from - date where the search will begin. If nothing is passed the default date will be the date of the first article created
  13 + # oldest - Collect the oldest comments from reference_id comment. If nothing is passed the newest comments are collected
  14 + # limit - amount of comments returned. The default value is 20
  15 + #
  16 + # Example Request:
  17 + # GET /communities?from=2013-04-04-14:41:43&until=2014-04-04-14:41:43&limit=10
  18 + # GET /communities?reference_id=10&limit=10&oldest
  19 +# desc 'Articles.', {
  20 +# :params => API::Entities::Article.documentation
  21 +# }
  22 + get do
  23 + conditions = make_conditions_with_parameter(params)
  24 +
  25 + if params[:reference_id]
  26 + communities = environment.communities.send("#{params.key?(:oldest) ? 'older_than' : 'newer_than'}", params[:reference_id]).find(:all, :conditions => conditions, :limit => limit, :order => "created_at DESC")
  27 + else
  28 + communities = environment.communities.find(:all, :conditions => conditions, :limit => limit, :order => "created_at DESC")
  29 + end
  30 + present communities, :with => Entities::Community
  31 + end
  32 +
  33 + desc "Return the article id"
  34 + get ':id' do
  35 + present environment.communities.find(params[:id]), :with => Entities::Community
  36 + end
  37 +
  38 + end
  39 +
  40 + end
  41 + end
  42 +end
... ...