Commit 50224f9e312feedf027bd9fdfaf4a5491966bddf
1 parent
5b4c64ce
Exists in
master
and in
1 other branch
add site_stats API call
Showing
4 changed files
with
27 additions
and
0 deletions
Show diff stats
CHANGELOG.md
app/controllers/questions_controller.rb
... | ... | @@ -326,6 +326,21 @@ class QuestionsController < InheritedResources::Base |
326 | 326 | update! |
327 | 327 | end |
328 | 328 | |
329 | + def site_stats | |
330 | + results = Question.connection.select_one("SELECT COUNT(*) as total_questions, SUM(votes_count) as votes_count, SUM(choices_count) choices_count FROM questions where site_id = #{current_user.id}") | |
331 | + results.each do |key, value| | |
332 | + results[key] = value.to_i | |
333 | + end | |
334 | + respond_to do |format| | |
335 | + format.xml { | |
336 | + render :xml => results.to_xml | |
337 | + } | |
338 | + format.js{ | |
339 | + render :json => results.to_json | |
340 | + } | |
341 | + end | |
342 | + end | |
343 | + | |
329 | 344 | def index |
330 | 345 | |
331 | 346 | counts = {} | ... | ... |
config/routes.rb
... | ... | @@ -14,6 +14,7 @@ ActionController::Routing::Routes.draw do |map| |
14 | 14 | :export => :post} , |
15 | 15 | :collection => {:all_num_votes_by_visitor_id => :get, |
16 | 16 | :all_object_info_totals_by_date => :get, |
17 | + :site_stats => :get, | |
17 | 18 | :object_info_totals_by_question_id => :get, |
18 | 19 | :recent_votes_by_question_id => :get} do |question| |
19 | 20 | question.resources :prompts, :only => :show, | ... | ... |
spec/integration/questions_spec.rb
... | ... | @@ -11,6 +11,16 @@ describe "Questions" do |
11 | 11 | end |
12 | 12 | end |
13 | 13 | |
14 | + describe "GET 'site_stats'" do | |
15 | + it "should return site_stats" do | |
16 | + Factory.create(:vote, :question => @questions.first) | |
17 | + get_auth site_stats_questions_path(:format => 'xml') | |
18 | + response.should be_success | |
19 | + response.body.should have_tag("total-questions", :text => @questions.count) | |
20 | + response.body.should have_tag("votes-count", :text => 1) | |
21 | + end | |
22 | + end | |
23 | + | |
14 | 24 | describe "GET 'median_votes_per_session'" do |
15 | 25 | it "should return the median" do |
16 | 26 | Factory.create(:vote, :question => @questions.first) | ... | ... |