-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
320 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
module Admin | ||
class StatsController < ApplicationController | ||
|
||
include Admin::Authenticatable | ||
|
||
swagger_path '/admin/stats/{year}/{month}' do | ||
operation :get do | ||
key :description, 'Returns a CSV with various show and track statistics.' | ||
key :tags, [:stats, :admin] | ||
key :produces, ['text/csv'] | ||
|
||
parameter name: :year, | ||
in: :path, | ||
description: 'The four-digit year to get the stats for.', | ||
required: true, | ||
type: :integer | ||
parameter name: :month, | ||
in: :path, | ||
description: 'Optional two-digit month to get the stats for.', | ||
required: true, # false, actually. Swagger path params must be required. | ||
type: :integer | ||
|
||
response 200 do | ||
key :description, | ||
'CSV with header row, overall row and one row for each show ' \ | ||
'that was broadcasted in the given period.' | ||
schema do | ||
key :type, :string | ||
end | ||
end | ||
|
||
security jwt_token: [] | ||
end | ||
end | ||
|
||
def index | ||
send_data Stats::Csv.new(stats).generate, filename: filename | ||
end | ||
|
||
private | ||
|
||
def filename | ||
if params[:month] | ||
"stats_#{params[:year]}_#{params[:month].to_s.rjust(2, '0')}.csv" | ||
else | ||
"stats_#{params[:year]}.csv" | ||
end | ||
end | ||
|
||
def stats | ||
@stats ||= Stats.for(params[:year], params[:month]) | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.