api.rb
2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
class GamificationPlugin::API < Grape::API
resource :gamification_plugin do
get 'badges' do
environment.gamification_plugin_badges.group('gamification_plugin_badges.name').count
end
resource :my do
get 'badges' do
authenticate!
present current_person.badges, :with => Noosfero::API::Entities::Badge
end
get 'points' do
authenticate!
{points: current_person.points}
end
get 'points_by_type' do
authenticate!
{points: current_person.points_by_type(params[:type]) }
end
get 'points_by_profile' do
authenticate!
{points: current_person.points_by_profile(params[:profile]) }
end
get 'points_out_of_profiles' do
authenticate!
{points: current_person.points_out_of_profiles }
end
get 'level' do
authenticate!
{:level => current_person.level, :percent => current_person.gamification_plugin_level_percent, :score => current_person.points}
end
end
resource :people do
get ':id/badges' do
person = environment.people.visible_for_person(current_person).find_by_id(params[:id])
return not_found! if person.blank?
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/points_by_type' do
person = environment.people.visible_for_person(current_person).find_by_id(params[:id])
return not_found! if person.blank?
{points: person.points_by_type(params[:type]) }
end
get ':id/points_by_profile' do
person = environment.people.visible_for_person(current_person).find_by_id(params[:id])
return not_found! if person.blank?
{points: person.points_by_profile(params[:profile]) }
end
get ':id/points_out_of_profiles' do
person = environment.people.visible_for_person(current_person).find_by_id(params[:id])
return not_found! if person.blank?
{points: person.points_out_of_profiles }
end
get ':id/level' do
person = environment.people.visible_for_person(current_person).find_by_id(params[:id])
return not_found! if person.blank?
{:level => person.level, :percent => person.gamification_plugin_level_percent}
end
end
end
end