From 54a1e6d42e071b8edf8ba60f37b2adade21841ea Mon Sep 17 00:00:00 2001 From: Victor Costa Date: Tue, 12 Jan 2016 18:45:59 -0300 Subject: [PATCH] api: add endpoint for profiles --- lib/noosfero/api/api.rb | 1 + lib/noosfero/api/v1/articles.rb | 2 +- lib/noosfero/api/v1/profiles.rb | 24 ++++++++++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 lib/noosfero/api/v1/profiles.rb diff --git a/lib/noosfero/api/api.rb b/lib/noosfero/api/api.rb index b47aa58..a31a818 100644 --- a/lib/noosfero/api/api.rb +++ b/lib/noosfero/api/api.rb @@ -55,6 +55,7 @@ module Noosfero mount V1::Search mount V1::Contacts mount V1::Boxes + mount V1::Profiles mount Session diff --git a/lib/noosfero/api/v1/articles.rb b/lib/noosfero/api/v1/articles.rb index 6c1ae50..69e4ee5 100644 --- a/lib/noosfero/api/v1/articles.rb +++ b/lib/noosfero/api/v1/articles.rb @@ -260,7 +260,7 @@ module Noosfero end - kinds = %w[community person enterprise] + kinds = %w[profile community person enterprise] kinds.each do |kind| resource kind.pluralize.to_sym do segment "/:#{kind}_id" do diff --git a/lib/noosfero/api/v1/profiles.rb b/lib/noosfero/api/v1/profiles.rb new file mode 100644 index 0000000..e203070 --- /dev/null +++ b/lib/noosfero/api/v1/profiles.rb @@ -0,0 +1,24 @@ +module Noosfero + module API + module V1 + class Profiles < Grape::API + before { authenticate! } + + resource :profiles do + + get do + profiles = select_filtered_collection_of(environment, 'profiles', params) + profiles = profiles.visible_for_person(current_person) if profiles.respond_to?(:visible_for_person) + profiles = profiles.by_location(params) # Must be the last. May return Exception obj. + present profiles, :with => Entities::Profile, :current_person => current_person + end + + get ':id' do + profile = environment.profiles.visible_for_person(current_person).find_by_id(params[:id]) + present profile, :with => Entities::Profile, :current_person => current_person + end + end + end + end + end +end -- libgit2 0.21.2