diff --git a/lib/gamification_plugin/api.rb b/lib/gamification_plugin/api.rb index ab36381..757ea9b 100644 --- a/lib/gamification_plugin/api.rb +++ b/lib/gamification_plugin/api.rb @@ -6,7 +6,7 @@ class GamificationPlugin::API < Grape::API environment.gamification_plugin_badges.group(:name).count end - resource :my do + resource :my do get 'badges' do authenticate! present current_person.badges, :with => Noosfero::API::Entities::Badge @@ -16,6 +16,11 @@ class GamificationPlugin::API < Grape::API authenticate! {:level => current_person.level, :percent => current_person.gamification_plugin_level_percent, :score => current_person.points} end + + get 'points' do + authenticate! + {points: current_person.points} + end end resource :people do @@ -25,6 +30,12 @@ class GamificationPlugin::API < Grape::API present person.badges end + get ':id/points' do + person = environment.people.visible_for_person(current_person).find_by_id(params[:id]) + return not_found! if person.blank? + {:points => person.points} + end + get ':id/level' do person = environment.people.visible_for_person(current_person).find_by_id(params[:id]) return not_found! if person.blank? diff --git a/lib/merit/point_rules.rb b/lib/merit/point_rules.rb index 71a5c32..2dfbde0 100644 --- a/lib/merit/point_rules.rb +++ b/lib/merit/point_rules.rb @@ -3,90 +3,100 @@ module Merit include Merit::PointRulesMethods AVAILABLE_RULES = { - :comment_author => { - :action => 'comment#create', - :undo_action => 'comment#destroy', - :to => :author, - :value => 1, - :description => _('Comment author'), - :default_weight => 150 + comment_author: { + action: 'comment#create', + undo_action: 'comment#destroy', + to: :author, + value: 1, + description: _('Comment author'), + default_weight: 150 }, - :comment_article_author => { - :action => 'comment#create', - :undo_action => 'comment#destroy', - :to => lambda {|comment| comment.source.author}, - :value => 1, - :description => _('Article author of a comment'), - :default_weight => 50 + comment_article_author: { + action: 'comment#create', + undo_action: 'comment#destroy', + to: lambda {|comment| comment.source.author}, + value: 1, + description: _('Article author of a comment'), + default_weight: 50 }, - :comment_article => { - :action => 'comment#create', - :undo_action => 'comment#destroy', - :to => lambda {|comment| comment.source}, - :value => 1, - :description => _('Source article of a comment'), - :default_weight => 50 + comment_article: { + action: 'comment#create', + undo_action: 'comment#destroy', + to: lambda {|comment| comment.source}, + value: 1, + description: _('Source article of a comment'), + default_weight: 50 }, - :comment_community => { - :action => 'comment#create', - :undo_action => 'comment#destroy', - :to => lambda {|comment| comment.profile}, - :value => 1, - :description => _('Article community of a comment'), - :default_weight => 50, - :condition => lambda {|target| target.profile.community? } + comment_community: { + action: 'comment#create', + undo_action: 'comment#destroy', + to: lambda {|comment| comment.profile}, + value: 1, + description: _('Article community of a comment'), + default_weight: 50, + condition: lambda {|target| target.profile.community? } }, - :article_author => { - :action => 'article#create', - :undo_action => 'article#destroy', - :to => :author, - :value => 1, - :description => _('Article author'), - :default_weight => 500 + article_author: { + action: 'article#create', + undo_action: 'article#destroy', + to: :author, + value: 1, + description: _('Article author'), + default_weight: 500 }, - :article_community => { - :action => 'article#create', - :undo_action => 'article#destroy', - :to => :profile, - :value => 1, - :description => _('Article community'), - :default_weight => 600, - :condition => lambda {|target| target.profile.community? } + article_community: { + action: 'article#create', + undo_action: 'article#destroy', + to: :profile, + value: 1, + description: _('Article community'), + default_weight: 600, + condition: lambda {|target| target.profile.community? } }, - :vote_voteable_author => { - :action => 'vote#create', - :undo_action => 'vote#destroy', - :to => lambda {|vote| vote.voteable.author}, - :profile => lambda {|vote| vote.voteable.profile}, - :value => lambda {|vote| vote.vote}, - :description => _('Author of a voted content'), - :default_weight => 50, + vote_voteable_author: { + action: 'vote#create', + undo_action: 'vote#destroy', + to: lambda {|vote| vote.voteable.author}, + profile: lambda {|vote| vote.voteable.profile}, + value: lambda {|vote| vote.vote}, + description: _('Author of a voted content'), + default_weight: 50, }, - :vote_voteable => { - :action => 'vote#create', - :undo_action => 'vote#destroy', - :to => lambda {|vote| vote.voteable}, - :profile => lambda {|vote| vote.voteable.profile}, - :value => lambda {|vote| vote.vote}, - :description => _('Voted content'), - :default_weight => 50 + vote_voteable: { + action: 'vote#create', + undo_action: 'vote#destroy', + to: lambda {|vote| vote.voteable}, + profile: lambda {|vote| vote.voteable.profile}, + value: lambda {|vote| vote.vote}, + description: _('Voted content'), + default_weight: 50 }, - :vote_voter => { - :action => 'vote#create', - :undo_action => 'vote#destroy', - :to => lambda {|vote| vote.voter}, - :value => lambda {|vote| 1}, - :description => _('Voter'), - :default_weight => 10 + vote_voter: { + action: 'vote#create', + undo_action: 'vote#destroy', + to: lambda {|vote| vote.voter}, + value: lambda {|vote| 1}, + description: _('Voter'), + default_weight: 10 }, - :friends => { - :action => 'friendship#create', - :undo_action => 'friendship#destroy', - :to => lambda {|friendship| friendship.person}, - :value => 1, - :description => _('Friends'), - :default_weight => 5 + friends: { + action: 'friendship#create', + undo_action: 'friendship#destroy', + to: lambda {|friendship| friendship.person}, + value: 1, + description: _('Friends'), + default_weight: 5 }, + profile_completion: { + action: ['account#create', 'account#update'], + undo_action: 'account#destroy', + to: lambda {|user| user.person}, + value: 1, + description: _('Profile Completion'), + default_weight: 5, + model_name: "User", + condition: lambda {|user| user.person.profile_completion_score_condition } + } } def weight(category) @@ -110,7 +120,7 @@ module Merit AVAILABLE_RULES.each do |category, setting| [setting[:action], setting[:undo_action]].compact.zip([1, -1]).each do |action, signal| - score lambda {|target| signal * calculate_score(target, category, setting[:value])}, :on => action, :to => setting[:to], :category => category do |target| + score lambda {|target| signal * calculate_score(target, category, setting[:value])}, on: action, to: setting[:to], category: category do |target| condition(setting, target) end end -- libgit2 0.21.2