Commit ded7ef77ec16b23ac42115ee1641f1ead00e2e5e
1 parent
c069a89f
Exists in
staging
and in
4 other branches
add people response
Showing
1 changed file
with
67 additions
and
0 deletions
Show diff stats
| @@ -0,0 +1,67 @@ | @@ -0,0 +1,67 @@ | ||
| 1 | +module API | ||
| 2 | + module V1 | ||
| 3 | + class People < Grape::API | ||
| 4 | + before { detect_stuff_by_domain } | ||
| 5 | + before { authenticate! } | ||
| 6 | + | ||
| 7 | + resource :people 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 /people?from=2013-04-04-14:41:43&until=2014-04-04-14:41:43&limit=10 | ||
| 18 | + # GET /people?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 | + people = environment.people.send("#{params.key?(:oldest) ? 'older_than' : 'newer_than'}", params[:reference_id]).find(:all, :conditions => conditions, :limit => limit, :order => "created_at DESC") | ||
| 27 | + else | ||
| 28 | + people = environment.people.find(:all, :conditions => conditions, :limit => limit, :order => "created_at DESC") | ||
| 29 | + end | ||
| 30 | + present people, :with => Entities::Person | ||
| 31 | + end | ||
| 32 | + | ||
| 33 | + | ||
| 34 | + segment '/:person_id' do | ||
| 35 | + | ||
| 36 | + desc "Return the person information" | ||
| 37 | + get do | ||
| 38 | + present environment.people.find(params[:person_id]), :with => Entities::Person | ||
| 39 | + end | ||
| 40 | + | ||
| 41 | + resource '/communities' do | ||
| 42 | + desc "Return all communities of person" | ||
| 43 | + get do | ||
| 44 | + person = environment.people.find(params[:person_id]) | ||
| 45 | + conditions = make_conditions_with_parameter(params) | ||
| 46 | + | ||
| 47 | + if params[:reference_id] | ||
| 48 | + communities = person.communities.send("#{params.key?(:oldest) ? 'older_than' : 'newer_than'}", params[:reference_id]).find(:all, :conditions => conditions, :limit => limit, :order => "created_at DESC") | ||
| 49 | + else | ||
| 50 | + communities = person.communities.find(:all, :conditions => conditions, :limit => limit, :order => "created_at DESC") | ||
| 51 | + end | ||
| 52 | + present communities, :with => Entities::Community | ||
| 53 | + end | ||
| 54 | + | ||
| 55 | + desc "Return all communities of person" | ||
| 56 | + get '/:id' do | ||
| 57 | + person = environment.people.find(params[:person_id]) | ||
| 58 | + present person.communities.find(params[:id]), :with => Entities::Community | ||
| 59 | + end | ||
| 60 | + end | ||
| 61 | + end | ||
| 62 | + | ||
| 63 | + end | ||
| 64 | + | ||
| 65 | + end | ||
| 66 | + end | ||
| 67 | +end |