The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

iTunesConnect - An iTunesConnect client interface

SYNOPSIS

 use WWW::iTunesConnect;

 my $itc = WWW::iTunesConnect->new(user=>$user, password=>$password);
 my %report = $itc->daily_sales_summary;

DESCRIPTION

iTunesConnect provides an interface to Apple's iTunes Connect website. Daily, Weekly and Monthly summaries, as well as Finanacial Reports, can be retrieved. Eventually this will become a complete interface.

A script suitable for use as a nightly cronjob can be found at http://github.com/bfoz/itunesconnect-tools

CONSTRUCTOR

$itc = WWW::iTunesConnect->new(user=>$user, password=>$password);

Constructs and returns a new iTunesConnect interface object. Accepts a hash containing the iTunes Connect username and password.

ATTRIBUTES

$itc->user

Get/Set the iTunes Connect username. NOTE: User and Password must be set before calling any other methods.

$itc->password

Get/Set the iTunes Connect password. NOTE: User and Password must be set before calling any other methods.

Class Methods

%report = WWW::iTunesConnect->parse_sales_summary($input, %options)

Parse a gzip'd summary file fetched from the Sales/Trend page. Arguments are the same as the IO::Uncompress::Gunzip constructor, less the output argument. To parse a file pass a scalar containing the file name as $input. To parse a string of content, pass a scalar reference as $input. The %options hash is passed directly to gunzip.

The returned hash has two elements: header and data. The header element is a reference to an array of the column headers in the fetched TSV file. The data element is a reference to an array of array references, one for each non-header line in the fetched TSV file.

METHODS

These methods fetch various bits of information from the iTunes Connect servers. Everything here uses LWP and is therefore essentially a screen scraper. So, be careful and try not to load up Apple's servers too much. We don't want them to make this any more difficult than it already is.

$itc->login()

Uses the username and password properties to authenticate to the iTunes Connect server. This is automatically called as needed by the other fetch methods if user and password have already been set.

$itc->daily_sales_summary_dates

Fetch the list of available dates for Sales/Trend Daily Summary Reports. This caches the returned results so it can be safely called multiple times. Note, however, that if the parent script runs for longer than 24 hours the cached results will be invalid.

Dates are sorted in descending order.

$itc->daily_sales_summary()

Fetch the most recent Sales/Trends Daily Summary report and return it as a hash of array references. The returned hash has two elements in addition to the elements returned by parse_sales_summary: file and filename. The file element is the raw content of the file retrieved from iTunes Connect and the filename element is the filename provided by the Content-Disposition header line.

If a single string argument is given in the form 'MM/DD/YYYY' that date will be fetched instead (if it's available).

$itc->fetch_financial_report($month, $region)

Fetch the raw report content for a given month and region. The month argument must be of the form 'YYYYMM' and the region argument is the name of a region as listed on the Financial Reports page of iTunes Connect.

Returns a hash with two keys:

    Key         Description
    -----------------------------------------------------------------------
    filename    The report filename as listed on the Financial Reports page
    content     Raw content of the report file
$itc->financial_report_list()

Fetch the list of available Financial Reports. This caches the returned results and can be safely called multiple times.

$itc->financial_report()

Fetch the most recent Financial Report and return it as a hash. The keys of the returned hash are of the form 'YYYYMM', each of which is a hash containing one entry for each region included in that month's report. Each of the region entries is a yet another hash with six elements:

    Key         Description
    ---------------------------------------------
    currency    Currency code
    data        Reference to array of report rows
    file        Raw content of the retrieved file
    filename    Retrieved file name
    header      Header row
    total       Sum of all rows in data

If a single string argument is given in the form 'YYYYMM', that month's report will be fetched instead (if it's available).

$itc->monthly_free_summary_dates

Fetch the list of available months for Sales/Trend Monthly Summary Reports. This caches the returned results so it can be safely called multiple times.

Months are returned as an array of hash references in descending order. Each hash contains the keys From and To, indicating the start and end dates of each report.

$itc->monthly_free_summary( %options )

Fetch the most recent Sales/Trends Monthly Summary report and return it as a hash of array references. The returned hash has two elements in addition to the elements returned by parse_sales_summary: file and filename. The file element is the raw content of the file retrieved from iTunes Connect and the filename element is the filename provided by the Content-Disposition header line.

If both From and To options are passed, and both are of the form 'MM/DD/YYYY', the monthly summary matching the two dates will be fetched instead (if it's available). The hashes returned by monthly_free_summary_dates() are suitable for passing to this method.

$itc->weekly_sales_summary_dates

Fetch the list of available dates for Sales/Trend Weekly Summary Reports. This caches the returned results so it can be safely called multiple times.

Dates are sorted in descending order.

$itc->weekly_sales_summary()

Fetch the most recent Sales/Trends Weekly Summary report and return it as a hash of array references. The returned hash has two elements in addition to the elements returned by parse_sales_summary: file and filename. The file element is the raw content of the file retrieved from iTunes Connect and the filename element is the filename provided by the Content-Disposition header line.

If a single string argument is given in the form 'MM/DD/YYYY' the week ending on the given date will be fetched instead (if it's available).

SEE ALSO

LWP HTML::Form HTML::Tree IO::Uncompress::Gunzip Net::SSLeay

AUTHOR

Brandon Fosdick, <bfoz@bfoz.net>

COPYRIGHT AND LICENSE

Copyright 2008-2009 Brandon Fosdick <bfoz@bfoz.net>

This software is provided under the terms of the BSD License.