Created
July 9, 2021 01:38
-
-
Save reizist/5187e4df49a76877b49666cb8b2330b7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'pry-byebug' | |
require 'app_store_connect' | |
private_key_str = ENV['PRIVATE_KEY'] | |
private_key = private_key_str.gsub('\n', "\n") | |
AppStoreConnect.config = { | |
issuer_id: ENV['ISSUER_ID'], | |
key_id: ENV['KEY_ID'], | |
private_key: private_key | |
} | |
require 'csv' | |
client = AppStoreConnect::Client.new | |
IDENTIFIER = ENV["IDENTIFIER"] | |
EXEC_DATE = ENV["EXEC_DATE"] || "2021-03-21" | |
filter = { | |
report_type: 'SALES', | |
report_sub_type: 'SUMMARY', | |
frequency: 'DAILY', | |
vendor_number: ENV['VENDOR_NUMBER'], | |
report_date: EXEC_DATE | |
} | |
sales_reports = client.sales_reports(filter: filter) | |
rows = CSV.parse(sales_reports, col_sep: "\t", headers: true) | |
# Product Type Identifier: see https://developer.apple.com/forums/thread/24203 | |
data = rows.map{|r| JSON.parse(r.to_hash.to_json)}. | |
filter{|r| r['Apple Identifier'] == IDENTIFIER }. | |
filter{|d| d["Product Type Identifier"].include?("1") || d["Product Type Identifier"].include?("3")} | |
puts data |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment