From 31ce4ce71164966da141f5dfb5812c20d99c8154 Mon Sep 17 00:00:00 2001 From: Leandro Nunes dos Santos Date: Mon, 26 May 2014 12:02:32 -0300 Subject: [PATCH] adding category endpoint --- lib/api/api.rb | 1 + lib/api/v1/categories.rb | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 0 deletions(-) create mode 100644 lib/api/v1/categories.rb diff --git a/lib/api/api.rb b/lib/api/api.rb index cb4535a..f460fb3 100644 --- a/lib/api/api.rb +++ b/lib/api/api.rb @@ -16,6 +16,7 @@ module API mount V1::Communities mount V1::People mount V1::Enterprises + mount V1::Categories mount Session end diff --git a/lib/api/v1/categories.rb b/lib/api/v1/categories.rb new file mode 100644 index 0000000..33f5514 --- /dev/null +++ b/lib/api/v1/categories.rb @@ -0,0 +1,24 @@ +module API + module V1 + class Categories < Grape::API + before { detect_stuff_by_domain } + before { authenticate! } + + resource :categories do + + get do + type = params[:category_type] + categories = type.nil? ? environment.categories : environment.categories.find(:all, :conditions => {:type => type}) + present categories, :with => Entities::Category + end + + desc "Return the category by id" + get ':id' do + present environment.categories.find(params[:id]), :with => Entities::Category + end + + end + + end + end +end -- libgit2 0.21.2