Permalink
Browse files

Expose metrics from cli (basic version)

  • Loading branch information...
1 parent 27ed0e1 commit b217daa9b98e23793f4bd51a48126956d57f2cdb @yacc committed Jun 25, 2013
Showing with 29 additions and 50 deletions.
  1. +2 −1 lib/stripemetrics/cli/commands/report.rb
  2. +27 −49 lib/stripemetrics/client/report.rb
View
3 lib/stripemetrics/cli/commands/report.rb
@@ -10,7 +10,8 @@
c.action do |global_options,options,args|
begin
say("<%= color('Gathering data from StripeMetrics ....', :yellow) %>")
- token = @client.print options, args
+ metrics = @client.get_metrics
+ token = @client.print metrics, options, args
rescue Stripemetrics::Client::AuthError
exit_now! "You need to authorize with StripeMetrics.com first!\nTry login in with this command:\nstripemetrics-cli login"
rescue Exception => e
View
76 lib/stripemetrics/client/report.rb
@@ -1,68 +1,46 @@
module Stripemetrics
class Client
module Report
- def report
- get('/v1/reports', :require_auth => true)
+
+ def get_metrics
+ response = get('/v1/metrics', :require_auth => true)
+ raise TargetError if response.status == 404
+ raise AuthError if response.status == 401
+ (response.status == 200) ? 'success' : 'failure'
+ response.body
end
- def print(options={},args={})
- puts options[:all]
+ def print(metrics, options={},args={})
table(:border => true) do
header
- active_users if (args.include?("churn") || options[:all])
- cancellations if (args.include?("active") || options[:all])
- charges if (args.include?("charges") || options[:all])
- end
+ metrics.each do |metric|
+ display_row(metric) if (args.include?(metric['_type']) || options[:all])
+ end
+ end
end
def header
row do
column('Metric', :width => 15)
- column('This month', :width => 10)
- column('Last month', :width => 10)
- column('% change', :width => 10)
- column('TSM', :width => 10)
- column('Average', :width => 10)
- column('Goal', :width => 10)
+ column('This month', :width => 11)
+ column('Last month', :width => 11)
+ column('% change', :width => 11)
+ column('TSM Average', :width => 11)
+ column('Goal', :width => 11)
end
end
- def cancellations
- row do
- column('churn')
- column('Caesar')
- column('Caesar')
- column('Caesar')
- column('Caesar')
- column('Caesar')
- column('Caesar')
- end
- end
- def active_users
- row do
- column('active')
- column('Caesar')
- column('Caesar')
- column('Caesar')
- column('Caesar')
- column('Caesar')
- column('Caesar')
- end
- end
- def charges
+
+ def display_row(metric)
row do
- column('charges')
- column('Caesar')
- column('Caesar')
- column('Caesar')
- column('Caesar')
- column('Caesar')
- column('Caesar')
- end
+ column(metric['name'])
+ column(metric['this_month'])
+ column(metric['last_month'])
+ column(metric['change'])
+ column(metric['tsm_avrg'])
+ column(metric['goal'])
+ end
end
+
end
end
end
-
-# Metric This month Last Month % change TSM Average Goal
-# Active Users 100,000 50,000 100% 125% 75%
-# Total User Base 500,000 400,000 25% 7% 10%

0 comments on commit b217daa

Please sign in to comment.