Commit d782d26ba04a20fac32968cce9472e906dfedfdd

Authored by Caio Almeida
1 parent c279721d

API: adding tags endpoint

lib/noosfero/api/api.rb
... ... @@ -45,6 +45,7 @@ module Noosfero
45 45 mount V1::Enterprises
46 46 mount V1::Categories
47 47 mount V1::Tasks
  48 + mount V1::Tags
48 49 mount V1::Environments
49 50 mount Session
50 51  
... ...
lib/noosfero/api/entities.rb
... ... @@ -114,6 +114,11 @@ module Noosfero
114 114 expose :type
115 115 end
116 116  
  117 + class Tag < Entity
  118 + root 'tags', 'tag'
  119 + expose :name
  120 + end
  121 +
117 122 class Environment < Entity
118 123 expose :name
119 124 end
... ...
lib/noosfero/api/v1/tags.rb 0 → 100644
... ... @@ -0,0 +1,30 @@
  1 +module Noosfero
  2 + module API
  3 + module V1
  4 + class Tags < Grape::API
  5 + before { authenticate! }
  6 +
  7 + resource :articles do
  8 +
  9 + resource ':id/tags' do
  10 +
  11 + get do
  12 + article = find_article(environment.articles, params[:id])
  13 + present article.tag_list, :with => Entities::Tag
  14 + end
  15 +
  16 + desc "Add a tag to an article"
  17 + post do
  18 + article = find_article(environment.articles, params[:id])
  19 + article.tag_list=params[:tags]
  20 + article.save
  21 + present article.tag_list, :with => Entities::Tag
  22 + end
  23 +
  24 + end
  25 + end
  26 +
  27 + end
  28 + end
  29 + end
  30 +end
... ...