Permalink
Browse files

Added support for opt-in reports and downloading instead of displayin…

…g in table.
  • Loading branch information...
1 parent ca1db65 commit d707b3a680ce85b2f09c7dbe8de1600c10f748f3 @carsonmcdonald committed Jul 27, 2012
View
13 lib/cupertino/itunes_connect.rb
@@ -2,19 +2,6 @@
module Cupertino
module ITunesConnect
-
- class SalesSummaryReport < Struct.new(:provider, :provider_country, :sku, :developer, :title, :version, :product_type_identifier, :units, :developer_proceeds, :begin_date, :end_date, :customer_currency, :country_code, :currency_of_proceeds, :apple_identifier, :customer_price, :promo_code, :parent_identifier, :subscription, :period)
- def to_s
- "#{self.sku} - #{self.title}"
- end
- end
-
- class SalesOptInReport < Struct.new(:first_name, :last_name, :email_address, :postal_code, :apple_identifier, :start_date, :end_date)
- def to_s
- "#{self.name}"
- end
- end
-
class UnsuccessfulAuthenticationError < RuntimeError; end
end
end
View
72 lib/cupertino/itunes_connect/commands/report.rb
@@ -2,47 +2,71 @@
require 'security'
command :'itc:salessummaryreport' do |c|
- c.syntax = 'ios itc:salessummaryreport <vendorid> <Daily|Weekly> <date_yyyymmdd>'
+ c.syntax = 'ios itc:salessummaryreport <vendorid> <Daily|Weekly> <date_yyyymmdd> [output file]'
c.summary = 'Retrieves the sales summary report for the given app and date'
c.description = ''
c.action do |args, options|
ipw = Security::InternetPassword.find(:server => Cupertino::ITC_HOSTNAME)
username, password = ipw.attributes['acct'], ipw.password if ipw
- say_error "Missing arguments, expected <vendorid> <Daily|Weekly> <date_yyyymmdd>" and abort if args.nil? or args.length < 3
+ say_error "Missing arguments, expected <vendorid> <Daily|Weekly> <date_yyyymmdd> [output file]" and abort if args.nil? or args.length < 3
username ||= ask "Username:"
password ||= pw "Password:"
itca = ITCAutoingest::ITCAutoingest.new(username, password, args[0])
- report = itca.send("#{args[1].downcase}_sales_summary_report", args[2])
+ if args.length == 4
+ File.open(args[3], 'w') do |f|
+ f.write(itca.send("#{args[1].downcase}_sales_summary_raw", args[2]))
+ end
+ else
+ report = itca.send("#{args[1].downcase}_sales_summary_report", args[2])
- if report[:error].nil?
- if report[:report].size == 0
- puts "Nothing to report."
- else
- table = Terminal::Table.new :title => "Sales Summary Report" do |t|
- headers = []
- report[:report][0].keys.each do |header|
- headers << "#{header}"
- end
- t << headers
- t << :separator
-
- report[:report].each do |rv|
- row = []
- rv.values.each do |cv|
- row << "#{cv}"
- end
- t << row
- end
+ if report[:error].nil?
+ if report[:report].size == 0
+ puts "Nothing to report."
+ else
+ puts hasharray_to_table(report[:report], "Sales Summary Report")
end
+ else
+ say_error report[:error]
+ end
+ end
+ end
+end
+
+command :'itc:salesoptinreport' do |c|
+ c.syntax = 'ios itc:salesoptinreport <vendorid> <Daily|Weekly> <date_yyyymmdd> [output file]'
+ c.summary = 'Retrieves the sales opt-in report for the given app and date'
+ c.description = ''
- puts table
+ c.action do |args, options|
+ ipw = Security::InternetPassword.find(:server => Cupertino::ITC_HOSTNAME)
+ username, password = ipw.attributes['acct'], ipw.password if ipw
+
+ say_error "Missing arguments, expected <vendorid> <Daily|Weekly> <date_yyyymmdd> [output file]" and abort if args.nil? or args.length < 3
+
+ username ||= ask "Username:"
+ password ||= pw "Password:"
+
+ itca = ITCAutoingest::ITCAutoingest.new(username, password, args[0])
+ if args.length == 4
+ File.open(args[3], 'w') do |f|
+ f.write(itca.send("#{args[1].downcase}_sales_optin_raw", args[2]))
end
else
- say_error report[:error]
+ report = itca.send("#{args[1].downcase}_sales_optin_report", args[2])
+
+ if report[:error].nil?
+ if report[:report].size == 0
+ puts "Nothing to report."
+ else
+ puts hasharray_to_table(report[:report], "Sales Opt-In Report")
+ end
+ else
+ say_error report[:error]
+ end
end
end
end
View
26 lib/cupertino/itunes_connect/helpers.rb
@@ -3,6 +3,32 @@ module Commander::UI
alias :pw :password
end
+module Cupertino
+ module ProvisioningPortal
+ module Helpers
+ def hasharray_to_table(hav, title)
+ Terminal::Table.new :title => title do |t|
+ headers = []
+ hav[0].keys.each do |header|
+ headers << "#{header}"
+ end
+ t << headers
+ t << :separator
+
+ hav.each do |rv|
+ row = []
+ rv.values.each do |cv|
+ row << "#{cv}"
+ end
+ t << row
+ end
+ end
+ end
+ end
+ end
+end
+
+
class String
include Term::ANSIColor
end

0 comments on commit d707b3a

Please sign in to comment.