Skip to content

Commit

Permalink
Added ITC sales summary report as table output.
Browse files Browse the repository at this point in the history
  • Loading branch information
carsonmcdonald committed Jul 27, 2012
1 parent ff38849 commit ca1db65
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 1 deletion.
1 change: 1 addition & 0 deletions bin/ios
Expand Up @@ -19,3 +19,4 @@ program :help_formatter, :compact
default_command :help

require 'cupertino/provisioning_portal'
require 'cupertino/itunes_connect'
1 change: 1 addition & 0 deletions cupertino.gemspec
Expand Up @@ -20,6 +20,7 @@ Gem::Specification.new do |s|
s.add_dependency "term-ansicolor", "~> 1.0.7"
s.add_dependency "mechanize", "~> 2.5.1"
s.add_dependency "security", "~> 0.1.2"
s.add_dependency "itc-autoingest", "~> 1.0.2"

s.files = Dir["./**/*"].reject { |file| file =~ /\.\/(bin|log|pkg|script|spec|test|vendor)/ }
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
Expand Down
3 changes: 2 additions & 1 deletion lib/cupertino.rb
@@ -1,4 +1,5 @@
module Cupertino
VERSION = '0.5.1'
VERSION = '0.5.2'
HOSTNAME = "developer.apple.com"
ITC_HOSTNAME = "itunesconnect.apple.com"
end
23 changes: 23 additions & 0 deletions lib/cupertino/itunes_connect.rb
@@ -0,0 +1,23 @@
require 'mechanize'

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

require 'cupertino/itunes_connect/helpers'
require 'cupertino/itunes_connect/commands'
3 changes: 3 additions & 0 deletions lib/cupertino/itunes_connect/commands.rb
@@ -0,0 +1,3 @@
include Cupertino::ITunesConnect

require 'cupertino/itunes_connect/commands/report'
48 changes: 48 additions & 0 deletions lib/cupertino/itunes_connect/commands/report.rb
@@ -0,0 +1,48 @@
require 'itc_autoingest'
require 'security'

command :'itc:salessummaryreport' do |c|
c.syntax = 'ios itc:salessummaryreport <vendorid> <Daily|Weekly> <date_yyyymmdd>'
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

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 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
end

puts table
end
else
say_error report[:error]
end
end
end
8 changes: 8 additions & 0 deletions lib/cupertino/itunes_connect/helpers.rb
@@ -0,0 +1,8 @@
# Monkey Patch Commander::UI to alias password to avoid conflicts
module Commander::UI
alias :pw :password
end

class String
include Term::ANSIColor
end

0 comments on commit ca1db65

Please sign in to comment.