Commit 135c10f90f3957f2455b9ddcb6f8065e71dd30aa

Authored by Leandro Santos
2 parents 0c1c42cb 3dd2b47e

Merge branch 'api' into production

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
... ... @@ -72,6 +72,7 @@ module Noosfero
72 72 expose :hits
73 73 expose :start_date
74 74 expose :end_date
  75 + expose :tag_list
75 76 end
76 77  
77 78 class Article < ArticleBase
... ...
lib/noosfero/api/v1/articles.rb
... ... @@ -28,6 +28,35 @@ module Noosfero
28 28 article = find_article(environment.articles, params[:id])
29 29 present article, :with => Entities::Article, :fields => params[:fields]
30 30 end
  31 +
  32 + post ':id/report_abuse' do
  33 + article = find_article(environment.articles, params[:id])
  34 + profile = article.profile
  35 + begin
  36 + abuse_report = AbuseReport.new(:reason => params[:report_abuse])
  37 + if !params[:content_type].blank?
  38 + article = params[:content_type].constantize.find(params[:content_id])
  39 + abuse_report.content = article_reported_version(article)
  40 + end
  41 +
  42 + current_person.register_report(abuse_report, profile)
  43 +
  44 + if !params[:content_type].blank?
  45 + abuse_report = AbuseReport.find_by_reporter_id_and_abuse_complaint_id(current_person.id, profile.opened_abuse_complaint.id)
  46 + Delayed::Job.enqueue DownloadReportedImagesJob.new(abuse_report, article)
  47 + end
  48 +
  49 + {
  50 + :success => true,
  51 + :message => _('Your abuse report was registered. The administrators are reviewing your report.'),
  52 + }
  53 + rescue Exception => exception
  54 + #logger.error(exception.to_s)
  55 + render_api_error!(_('Your report couldn\'t be saved due to some problem. Please contact the administrator.'), 400)
  56 + end
  57 +
  58 + end
  59 +
31 60  
32 61 desc "Returns the total followers for the article"
33 62 get ':id/followers' do
... ... @@ -141,7 +170,7 @@ module Noosfero
141 170 article = find_article(community.articles, params[:id])
142 171 present article, :with => Entities::Article, :fields => params[:fields]
143 172 end
144   -
  173 +
145 174 # Example Request:
146 175 # POST api/v1/communites/:community_id/articles?private_token=234298743290432&article[name]=title&article[body]=body
147 176 post do
... ...
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
  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
  22 + end
  23 +
  24 + end
  25 + end
  26 +
  27 + end
  28 + end
  29 + end
  30 +end
... ...