Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add support for itunes connect reports #19

Closed
wants to merge 2 commits into from

2 participants

@carsonmcdonald

Support added for sales and opt-in reports to display in a table or download in their raw tab form.

@mattt
Owner

Sorry for not giving this the attention this deserves, @carsonmcdonald. This is an awesome contribution—thanks so much for submitting it.

I'm suffering from a bit of NIH syndrome, and am struggling to reconcile the utility of this with a combination of founded and unfounded objections to a large external dependency. So for that, I apologize. I'll give you a decision soon.

@carsonmcdonald

No problem. This was something I had fiddled with before so it was easy to add. I was actually warming up to see about adding support for managing IAP items via connect (something I have automated before). Doing that is probably another level of NIH because it is somewhat complex and I'm pretty sure it can't be done with mechanize.

@mattt mattt closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
1  bin/ios
@@ -19,3 +19,4 @@ program :help_formatter, :compact
default_command :help
require 'cupertino/provisioning_portal'
+require 'cupertino/itunes_connect'
View
1  cupertino.gemspec
@@ -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")
View
3  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
View
10 lib/cupertino/itunes_connect.rb
@@ -0,0 +1,10 @@
+require 'mechanize'
+
+module Cupertino
+ module ITunesConnect
+ class UnsuccessfulAuthenticationError < RuntimeError; end
+ end
+end
+
+require 'cupertino/itunes_connect/helpers'
+require 'cupertino/itunes_connect/commands'
View
3  lib/cupertino/itunes_connect/commands.rb
@@ -0,0 +1,3 @@
+include Cupertino::ITunesConnect
+
+require 'cupertino/itunes_connect/commands/report'
View
72 lib/cupertino/itunes_connect/commands/report.rb
@@ -0,0 +1,72 @@
+require 'itc_autoingest'
+require 'security'
+
+command :'itc:salessummaryreport' do |c|
+ 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> [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_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
+ 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 = ''
+
+ 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
+ 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
34 lib/cupertino/itunes_connect/helpers.rb
@@ -0,0 +1,34 @@
+# Monkey Patch Commander::UI to alias password to avoid conflicts
+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
Something went wrong with that request. Please try again.