Commit 2cf8abddebceb67290ed54c06001c274b7ea2fd7
1 parent
eb6c6b27
Exists in
staging
and in
4 other branches
adding category endpoint
Showing
2 changed files
with
25 additions
and
0 deletions
Show diff stats
lib/api/api.rb
| @@ -0,0 +1,24 @@ | @@ -0,0 +1,24 @@ | ||
| 1 | +module API | ||
| 2 | + module V1 | ||
| 3 | + class Categories < Grape::API | ||
| 4 | + before { detect_stuff_by_domain } | ||
| 5 | + before { authenticate! } | ||
| 6 | + | ||
| 7 | + resource :categories do | ||
| 8 | + | ||
| 9 | + get do | ||
| 10 | + type = params[:category_type] | ||
| 11 | + categories = type.nil? ? environment.categories : environment.categories.find(:all, :conditions => {:type => type}) | ||
| 12 | + present categories, :with => Entities::Category | ||
| 13 | + end | ||
| 14 | + | ||
| 15 | + desc "Return the category by id" | ||
| 16 | + get ':id' do | ||
| 17 | + present environment.categories.find(params[:id]), :with => Entities::Category | ||
| 18 | + end | ||
| 19 | + | ||
| 20 | + end | ||
| 21 | + | ||
| 22 | + end | ||
| 23 | + end | ||
| 24 | +end |