Commit 54a1e6d42e071b8edf8ba60f37b2adade21841ea

Authored by Victor Costa
1 parent 12f96cd5

api: add endpoint for profiles

lib/noosfero/api/api.rb
... ... @@ -55,6 +55,7 @@ module Noosfero
55 55 mount V1::Search
56 56 mount V1::Contacts
57 57 mount V1::Boxes
  58 + mount V1::Profiles
58 59  
59 60 mount Session
60 61  
... ...
lib/noosfero/api/v1/articles.rb
... ... @@ -260,7 +260,7 @@ module Noosfero
260 260  
261 261 end
262 262  
263   - kinds = %w[community person enterprise]
  263 + kinds = %w[profile community person enterprise]
264 264 kinds.each do |kind|
265 265 resource kind.pluralize.to_sym do
266 266 segment "/:#{kind}_id" do
... ...
lib/noosfero/api/v1/profiles.rb 0 → 100644
... ... @@ -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
... ...