Commit 54a1e6d42e071b8edf8ba60f37b2adade21841ea
1 parent
12f96cd5
Exists in
staging
and in
3 other branches
api: add endpoint for profiles
Showing
3 changed files
with
26 additions
and
1 deletions
Show diff stats
lib/noosfero/api/api.rb
lib/noosfero/api/v1/articles.rb
| @@ -260,7 +260,7 @@ module Noosfero | @@ -260,7 +260,7 @@ module Noosfero | ||
| 260 | 260 | ||
| 261 | end | 261 | end |
| 262 | 262 | ||
| 263 | - kinds = %w[community person enterprise] | 263 | + kinds = %w[profile community person enterprise] |
| 264 | kinds.each do |kind| | 264 | kinds.each do |kind| |
| 265 | resource kind.pluralize.to_sym do | 265 | resource kind.pluralize.to_sym do |
| 266 | segment "/:#{kind}_id" do | 266 | segment "/:#{kind}_id" do |
| @@ -0,0 +1,24 @@ | @@ -0,0 +1,24 @@ | ||
| 1 | +module Noosfero | ||
| 2 | + module API | ||
| 3 | + module V1 | ||
| 4 | + class Profiles < Grape::API | ||
| 5 | + before { authenticate! } | ||
| 6 | + | ||
| 7 | + resource :profiles do | ||
| 8 | + | ||
| 9 | + get do | ||
| 10 | + profiles = select_filtered_collection_of(environment, 'profiles', params) | ||
| 11 | + profiles = profiles.visible_for_person(current_person) if profiles.respond_to?(:visible_for_person) | ||
| 12 | + profiles = profiles.by_location(params) # Must be the last. May return Exception obj. | ||
| 13 | + present profiles, :with => Entities::Profile, :current_person => current_person | ||
| 14 | + end | ||
| 15 | + | ||
| 16 | + get ':id' do | ||
| 17 | + profile = environment.profiles.visible_for_person(current_person).find_by_id(params[:id]) | ||
| 18 | + present profile, :with => Entities::Profile, :current_person => current_person | ||
| 19 | + end | ||
| 20 | + end | ||
| 21 | + end | ||
| 22 | + end | ||
| 23 | + end | ||
| 24 | +end |