2020-06-07 08:28:05 +00:00
|
|
|
class Api::V2::Accounts::ReportsController < Api::V1::Accounts::BaseController
|
2020-03-18 11:23:35 +00:00
|
|
|
def account
|
2020-06-07 08:28:05 +00:00
|
|
|
builder = V2::ReportBuilder.new(Current.account, account_report_params)
|
2020-03-18 11:23:35 +00:00
|
|
|
data = builder.build
|
|
|
|
render json: data
|
|
|
|
end
|
|
|
|
|
|
|
|
def account_summary
|
|
|
|
render json: account_summary_metrics
|
|
|
|
end
|
|
|
|
|
2020-11-16 14:11:52 +00:00
|
|
|
def agents
|
|
|
|
response.headers['Content-Type'] = 'text/csv'
|
|
|
|
response.headers['Content-Disposition'] = 'attachment; filename=agents_report.csv'
|
|
|
|
render layout: false, template: 'api/v2/accounts/reports/agents.csv.erb', format: 'csv'
|
|
|
|
end
|
|
|
|
|
|
|
|
def inboxes
|
|
|
|
response.headers['Content-Type'] = 'text/csv'
|
|
|
|
response.headers['Content-Disposition'] = 'attachment; filename=inboxes_report.csv'
|
|
|
|
render layout: false, template: 'api/v2/accounts/reports/inboxes.csv.erb', format: 'csv'
|
|
|
|
end
|
|
|
|
|
2020-03-18 11:23:35 +00:00
|
|
|
private
|
|
|
|
|
|
|
|
def account_summary_params
|
|
|
|
{
|
|
|
|
type: :account,
|
|
|
|
since: params[:since],
|
|
|
|
until: params[:until]
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def account_report_params
|
|
|
|
{
|
|
|
|
metric: params[:metric],
|
|
|
|
type: :account,
|
|
|
|
since: params[:since],
|
|
|
|
until: params[:until]
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def account_summary_metrics
|
2020-06-07 08:28:05 +00:00
|
|
|
builder = V2::ReportBuilder.new(Current.account, account_summary_params)
|
2020-03-18 11:23:35 +00:00
|
|
|
builder.summary
|
|
|
|
end
|
|
|
|
end
|