Commit cdd1f702fef8c26321fb6855a774cddb25f71f0b

Authored by Caio Almeida
1 parent a766ba55

Ticket #85: Adding API endpoint to retrieve tags from a person

plugins/person_tags/lib/person_tags_plugin.rb
... ... @@ -15,4 +15,8 @@ class PersonTagsPlugin < Noosfero::Plugin
15 15 def profile_editor_extras
16 16 expanded_template('profile-editor-extras.html.erb').html_safe
17 17 end
  18 +
  19 + def self.api_mount_points
  20 + [PersonTagsPlugin::API]
  21 + end
18 22 end
... ...
plugins/person_tags/lib/person_tags_plugin/api.rb 0 → 100644
... ... @@ -0,0 +1,9 @@
  1 +class PersonTagsPlugin::API < Grape::API
  2 + resource :people do
  3 + get ':id/tags' do
  4 + person = environment.people.visible.find_by(id: params[:id])
  5 + return not_found! if person.blank?
  6 + present person.interest_list
  7 + end
  8 + end
  9 +end
... ...
plugins/person_tags/test/unit/api_test.rb 0 → 100644
... ... @@ -0,0 +1,27 @@
  1 +require_relative '../test_helper'
  2 +require_relative '../../../../test/api/test_helper'
  3 +
  4 +class APITest < ActiveSupport::TestCase
  5 +
  6 + def setup
  7 + create_and_activate_user
  8 + environment.enable_plugin(PersonTagsPlugin)
  9 + end
  10 +
  11 + should 'return tags for a person' do
  12 + person = create_user('person').person
  13 + person.interest_list.add('linux')
  14 + person.save!
  15 + person.reload
  16 + get "/api/v1/people/#{person.id}/tags?#{params.to_query}"
  17 + json = JSON.parse(last_response.body)
  18 + assert_equal ['linux'], json
  19 + end
  20 +
  21 + should 'return empty list if person has no tags' do
  22 + person = create_user('person').person
  23 + get "/api/v1/people/#{person.id}/tags?#{params.to_query}"
  24 + json = JSON.parse(last_response.body)
  25 + assert_equal [], json
  26 + end
  27 +end
... ...