Class: ItunesConnect::Commands::Download
- Inherits:
-
Object
- Object
- ItunesConnect::Commands::Download
- Defined in:
- lib/itunes_connect/commands/download.rb
Overview
:nodoc:
Instance Method Summary collapse
- #description ⇒ Object
- #execute!(opts, args = []) ⇒ Object
-
#initialize(c, rcfile = ItunesConnect::RcFile.default) ⇒ Download
constructor
A new instance of Download.
Constructor Details
#initialize(c, rcfile = ItunesConnect::RcFile.default) ⇒ Download
Returns a new instance of Download.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/itunes_connect/commands/download.rb', line 6 def initialize(c, rcfile=ItunesConnect::RcFile.default) c.opt('u', 'username', :desc => 'iTunes Connect username') c.opt('p', 'password', :desc => 'iTunes Connect password') c.opt('d', 'date', :desc => 'Daily report date (MM/DD/YYYY format)', :default => (Date.today - 1).strftime('%m/%d/%Y')) c.opt('o', 'out', :desc => 'Dump report to file, - is stdout') c.opt('b', 'db', :desc => 'Dump report to sqlite DB at the given path') c.opt('r', 'report', :desc => 'Report type. One of "Daily", "Weekly", "Monthly"', :default => 'Daily') do |r| r.capitalize end @rcfile = rcfile end |
Instance Method Details
#description ⇒ Object
72 73 74 |
# File 'lib/itunes_connect/commands/download.rb', line 72 def description "Retrieves reports from the iTunes Connect site" end |
#execute!(opts, args = []) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/itunes_connect/commands/download.rb', line 21 def execute!(opts, args=[]) username, password = if opts.username and opts.password [opts.username, opts.password] else [@rcfile.username, @rcfile.password] end raise ArgumentError.new("Please provide a username") unless username raise ArgumentError.new("Please provide a password") unless password if opts.db and opts.out raise ArgumentError.new("You can only specify :out or :db, not both") end if opts.report =~ /^Monthly/ and opts.db raise ArgumentError.new("You cannot persist monthly reports to a " + "database because these reports have no dates " + "associated with them") end connection = ItunesConnect::Connection.new(username, password, opts.verbose?, opts.debug?) db = opts.db || @rcfile.database out = if opts.out.nil? db ? StringIO.new : $stdout else opts.out == "-" ? $stdout : File.open(opts.out, "w") end connection.get_report(opts.date || Date.today - 1, out, opts.report) if db and StringIO === out $stdout.puts "Importing into database file: #{db}" if opts.verbose? store = ItunesConnect::Store.new(db, opts.verbose?) out.rewind report = ItunesConnect::Report.new(out) count = 0 report.each do |entry| count += 1 if store.add(entry.date, entry.country, entry.install_count, entry.upgrade_count) end $stdout.puts "Inserted #{count} rows into #{opts.db}" if opts.verbose? end out.flush out.close unless out == $stdout end |