Class: ItunesConnect::Commands::Report

Inherits:
Object
  • Object
show all
Defined in:
lib/itunes_connect/commands/report.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(c, rcfile = ItunesConnect::RcFile.default) ⇒ Report

Returns a new instance of Report.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/itunes_connect/commands/report.rb', line 6

def initialize(c, rcfile=ItunesConnect::RcFile.default)
  c.opt('b', 'db', :desc => 'Dump report to sqlite DB at the given path')
  c.opt('c', 'country',
        :desc => 'A two-letter country code to filter results with')
  c.opt('f', 'from', :desc => 'The starting date, inclusive') do |f|
    Date.parse(f)
  end
  c.opt('t', 'to', :desc => 'The ending date, inclusive') do |t|
    Date.parse(t)
  end
  c.flag('s', 'summarize', :desc => 'Summarize results by country code')
  c.flag('n', 'no-header', :desc => 'Suppress the column headers on output')
  c.opt('d', 'delimiter',
         :desc => 'The delimiter to use for output (normally TAB)',
        :default => "\t")
  c.flag('o', 'total', :desc => 'Add totals at the end of the report')
  @rcfile = rcfile
end

Instance Method Details

#descriptionObject



74
75
76
# File 'lib/itunes_connect/commands/report.rb', line 74

def description
  "Generates reports from a local database"
end

#execute!(opts, args = [], out = $stdout) ⇒ Object

Raises:

  • (ArgumentError)


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
71
72
# File 'lib/itunes_connect/commands/report.rb', line 25

def execute!(opts, args=[], out=$stdout)
  db = opts.db || @rcfile.database || nil
  raise ArgumentError.new("Missing :db option") if db.nil?
  store = ItunesConnect::Store.new(db)
  params = {
    :to => opts.to,
    :from => opts.from,
    :country => opts.country
  }

  total_installs, total_upgrades = 0, 0

  unless opts.no_header?
    out.puts([opts.summarize? ? nil : "Date",
              "Country",
              "Installs",
              "Upgrades"
             ].compact.join(opts.delimiter))
  end

  if opts.summarize?
    store.country_counts(params).each do |x|
      out.puts [x.country,
                x.install_count,
                x.update_count].join(opts.delimiter)
      total_installs += x.install_count
      total_upgrades += x.update_count
    end
  else
    store.counts(params).each do |x|
      out.puts [x.report_date,
                x.country,
                x.install_count,
                x.update_count].join(opts.delimiter)
      total_installs += x.install_count
      total_upgrades += x.update_count
    end
  end

  if opts.total?
    out.puts ["Total",
              opts.summarize? ? nil : "-",
              total_installs,
              total_upgrades
             ].compact.join(opts.delimiter)
  end
  out.flush
end