Class: ITunesIngestion::Fetcher
- Inherits:
-
Object
- Object
- ITunesIngestion::Fetcher
- Defined in:
- lib/itunes_ingestion/fetcher.rb
Constant Summary collapse
- BASE_URL =
"https://reportingitc.apple.com/autoingestion.tft?"
- REPORT_TYPE_SALES =
"Sales"
- DATE_TYPE_DAILY =
"Daily"
- DATE_TYPE_WEEKLY =
"Weekly"
- REPORT_SUMMARY =
"Summary"
- REPORT_OPT_IN =
"Opt-In"
Instance Method Summary collapse
-
#fetch(options = {}) ⇒ Object
Fetch and unzip report from itunes connect.
-
#initialize(username, password, vadnumber) ⇒ Fetcher
constructor
Create new instance of Fetcher.
Constructor Details
#initialize(username, password, vadnumber) ⇒ Fetcher
Create new instance of Fetcher
username - username password - password vadnumber - vadnumber
20 21 22 23 24 |
# File 'lib/itunes_ingestion/fetcher.rb', line 20 def initialize(username, password, vadnumber) @username = username @password = password @vadnumber = vadnumber end |
Instance Method Details
#fetch(options = {}) ⇒ Object
Fetch and unzip report from itunes connect
options - Hash of options:
- :type_of_report can only be REPORT_TYPE_SALES at the moment
- :date_type either DATE_TYPE_DAILY or DATE_TYPE_WEEKLY, default DATE_TYPE_DAILY
- :report_type either REPORT_OPT_IN or REPORT_SUMMARY, default REPORT_SUMMARY
- :report_date date in YYYYMMDD
Returns text file downloaded and unzipped from iTunes
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/itunes_ingestion/fetcher.rb', line 35 def fetch(={}) params = { :USERNAME => @username, :PASSWORD => @password, :VNDNUMBER => @vadnumber } params[:TYPEOFREPORT] = [:type_of_report] || REPORT_TYPE_SALES params[:DATETYPE] = [:date_type] || DATE_TYPE_DAILY params[:REPORTTYPE] = [:report_type] || REPORT_SUMMARY params[:REPORTDATE] = [:report_date] || (Time.now-60*60*24).strftime("%Y%m%d") response = RestClient.post BASE_URL, params if response.headers[:"errormsg"] raise ITunesConnectError.new response.headers[:"errormsg"] elsif response.headers[:"filename"] Zlib::GzipReader.new(StringIO.new(response.body)).read else raise "no data returned from itunes: #{response.body}" end end |