Created
November 29, 2012 18:56
-
-
Save drewkerrigan/4171112 to your computer and use it in GitHub Desktop.
splatted report endpoint
This file contains hidden or 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
get "/admin/reports/*_metrics.csv" do |operation| | |
endpoint = Att::API::Internal::Metrics.new(Server.setting(:api_uri), @app, @type) | |
report = "Date of Report," | |
report += "Developer Registration Date," | |
report += "Developer Id," | |
report += "Developer Email," | |
report += "Developer Organization," | |
report += "Developer CTN," | |
report += "AT&T Wireless Customer," | |
report += "Application Name," | |
report += "Application ID," | |
report += "Application Status," | |
if operation == "read" | |
metrics = MultiJson.decode(endpoint.get_read_metrics(@from, @to)) | |
report += "Data Source Name," | |
report += "Data Source ID," | |
report += "Data Source Owner ID," | |
report += "API Usage\n" | |
else | |
metrics = MultiJson.decode(endpoint.get_write_metrics()) | |
report += "Storage Used\n" | |
end | |
metrics.each { |metric| | |
developer_user = User.find(metric["key"]["developer"]) | |
developer = Developer.find(metric["key"]["developer"]) | |
application = Application.find(metric["key"]["application_name"]) | |
developer_org = "none" | |
developer_org = developer.company unless developer.company.nil? | |
developer_ctn = "none" | |
developer_ctn = developer.identity.mobile_number unless developer.identity.mobile_number.nil? | |
report += Time.now.strftime("%m/%d/%Y") + "," | |
report += developer.created_at.strftime("%m/%d/%Y") + "," | |
report += developer_user.id + ',' | |
report += developer_user.email + ',' | |
report += developer_org + "," | |
report += developer_ctn + "," | |
report += "?" + "," | |
report += application.display_name + "," | |
report += metric["key"]["application_id"] + "," | |
report += application.app_status + "," | |
if operation == "read" | |
datasource = Application.find(metric["key"]["datasource_name"]) | |
datasource_owner = "none" | |
datasource_owner = datasource.developer.company unless datasource.developer.company.nil? | |
datasource_owner = datasource.organization unless datasource.organization.nil? | |
report += datasource.display_name + "," | |
report += metric["key"]["datasource_id"] + "," | |
report += datasource_owner + "," | |
end | |
report += number_to_human_size(metric["sum"]) + "\n" | |
} | |
headers "Content-Disposition" => "attachment;filename=#{params[:operation]}_metrics_#{@to}_#{@from}.csv", | |
"Content-Type" => "application/octet-stream" unless @noattach | |
report | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment