Commit 6459ecda702659e9fcdaff6f0a7c8940c464fc4b
Committed by
Rodrigo Souto
1 parent
ca94a655
Exists in
master
and in
29 other branches
add enterprise response
Showing
1 changed file
with
42 additions
and
0 deletions
Show diff stats
| @@ -0,0 +1,42 @@ | @@ -0,0 +1,42 @@ | ||
| 1 | +module API | ||
| 2 | + module V1 | ||
| 3 | + class Enterprises < Grape::API | ||
| 4 | + before { detect_stuff_by_domain } | ||
| 5 | + before { authenticate! } | ||
| 6 | + | ||
| 7 | + resource :enterprises 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 /enterprises?from=2013-04-04-14:41:43&until=2014-04-04-14:41:43&limit=10 | ||
| 18 | + # GET /enterprises?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 | + enterprises = environment.enterprises.send("#{params.key?(:oldest) ? 'older_than' : 'newer_than'}", params[:reference_id]).find(:all, :conditions => conditions, :limit => limit, :order => "created_at DESC") | ||
| 27 | + else | ||
| 28 | + enterprises = environment.enterprises.find(:all, :conditions => conditions, :limit => limit, :order => "created_at DESC") | ||
| 29 | + end | ||
| 30 | + present enterprises, :with => Entities::Enterprise | ||
| 31 | + end | ||
| 32 | + | ||
| 33 | + desc "Return the article id" | ||
| 34 | + get ':id' do | ||
| 35 | + present environment.enterprises.find(params[:id]), :with => Entities::Enterprise | ||
| 36 | + end | ||
| 37 | + | ||
| 38 | + end | ||
| 39 | + | ||
| 40 | + end | ||
| 41 | + end | ||
| 42 | +end |