itc-autoingest 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in itc_autoingest.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,2 @@
1
+
2
+ http://www.apple.com/itunesnews/docs/AppStoreReportingInstructions.pdf
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "itc_autoingest"
4
+
5
+ abort "USAGE #{$0} <username> <password> <vendorid> <report_type> <date_type> <report_subtype> <date_yyyymmdd>" if ARGV.length != 7
6
+
7
+ username = ARGV[0]
8
+ password = ARGV[1]
9
+ vendorid = ARGV[2]
10
+ reporttype = ARGV[3]
11
+ datetype = ARGV[4]
12
+ reportsubtype = ARGV[5]
13
+ reportdate = ARGV[6]
14
+
15
+ itca = ITCAutoingest::ITCAutoingest.new(username, password, vendorid)
16
+ report = itca.send("#{datetype.downcase}_#{reporttype.downcase}_#{reportsubtype.sub('-', '').downcase}_report", reportdate)
17
+
18
+ if report[:error].nil?
19
+ if report[:report].size == 0
20
+ puts "Nothing to report."
21
+ else
22
+ os = ''
23
+ report[:report][0].keys.each { |header|
24
+ os = os + "#{header}\t"
25
+ }
26
+ os = os + "\n"
27
+ report[:report].each { |item|
28
+ item.values.each { |value|
29
+ os = os + "#{value}\t"
30
+ }
31
+ os = os + "\n"
32
+ }
33
+ puts os
34
+ end
35
+ else
36
+ puts report[:error]
37
+ end
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "itc_autoingest/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "itc-autoingest"
7
+ s.version = ITCAutoingest::VERSION
8
+ s.authors = ["Carson McDonald"]
9
+ s.email = ["carson@ioncannon.net"]
10
+ s.homepage = "http://github.com/carsonmcdonald/itc-autoingest"
11
+ s.summary = %q{ITC Autoingest is a gem for fetching iTunes connect reports.}
12
+ s.description = %q{This library makes it easy to fetch iTunes connect reports using the official autoingest system.}
13
+
14
+ s.rubyforge_project = "itc-autoingest"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_dependency "httparty"
22
+ end
@@ -0,0 +1,3 @@
1
+ module ITCAutoingest
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,61 @@
1
+ require "itc_autoingest/version"
2
+
3
+ require 'httparty'
4
+ require 'csv'
5
+
6
+ module ITCAutoingest
7
+
8
+ class ITCAutoingest
9
+ include HTTParty
10
+
11
+ base_uri 'https://reportingitc.apple.com'
12
+
13
+ REPORT_TYPES = ['Sales']
14
+ REPORT_SUB_TYPES = ['Summary', 'Opt-In']
15
+ REPORT_TIMEFRAME = ['Daily', 'Weekly']
16
+
17
+ def initialize(username, password, vndnumber)
18
+ @auth = {:USERNAME => username, :PASSWORD => password, :VNDNUMBER => vndnumber }
19
+
20
+ REPORT_TIMEFRAME.each { |timeframe|
21
+ REPORT_TYPES.each { |report_type|
22
+ REPORT_SUB_TYPES.each { |report_sub_type|
23
+ (class << self; self; end).class_eval {
24
+ define_method("#{timeframe.downcase}_#{report_type.downcase}_#{report_sub_type.sub('-', '').downcase}_report") { |*args|
25
+ reportdate = (args.length == 0 ? (Time.now - 86400).strftime('%Y%m%d') : args[0])
26
+ self.send('ingest', report_type, timeframe, report_sub_type, reportdate)
27
+ }
28
+ }
29
+ }
30
+ }
31
+ }
32
+ end
33
+
34
+ private
35
+
36
+ def ingest(typeofreport, datetype, reporttype, reportdate)
37
+ query = { :TYPEOFREPORT => typeofreport, :DATETYPE => datetype, :REPORTTYPE => reporttype, :REPORTDATE => reportdate }
38
+ query.merge!(@auth)
39
+
40
+ response = self.class.post( '/autoingestion.tft', :query => query )
41
+
42
+ if response.code != 200
43
+ {:error => response.message}
44
+ elsif !response.headers['ERRORMSG'].nil?
45
+ {:error => response.headers['ERRORMSG']}
46
+ else
47
+ hash_response(response.body)
48
+ end
49
+ end
50
+
51
+ def hash_response(body)
52
+ raw_data = Zlib::GzipReader.new(StringIO.new(body)).read
53
+
54
+ csv_data = CSV.parse(raw_data, {:col_sep => "\t"})
55
+
56
+ headers = csv_data.shift.map {|i| i.to_s }
57
+ string_data = csv_data.map {|row| row.map {|cell| cell.to_s } }
58
+ { :report => string_data.map {|row| Hash[*headers.zip(row).flatten] } }
59
+ end
60
+ end
61
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: itc-autoingest
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 1.0.0
6
+ platform: ruby
7
+ authors:
8
+ - Carson McDonald
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-09-19 00:00:00 -04:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: httparty
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: "0"
25
+ type: :runtime
26
+ version_requirements: *id001
27
+ description: This library makes it easy to fetch iTunes connect reports using the official autoingest system.
28
+ email:
29
+ - carson@ioncannon.net
30
+ executables:
31
+ - itc_autoingest
32
+ extensions: []
33
+
34
+ extra_rdoc_files: []
35
+
36
+ files:
37
+ - .gitignore
38
+ - Gemfile
39
+ - README.md
40
+ - Rakefile
41
+ - bin/itc_autoingest
42
+ - itc_autoingest.gemspec
43
+ - lib/itc_autoingest.rb
44
+ - lib/itc_autoingest/version.rb
45
+ has_rdoc: true
46
+ homepage: http://github.com/carsonmcdonald/itc-autoingest
47
+ licenses: []
48
+
49
+ post_install_message:
50
+ rdoc_options: []
51
+
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: "0"
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: "0"
66
+ requirements: []
67
+
68
+ rubyforge_project: itc-autoingest
69
+ rubygems_version: 1.6.2
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: ITC Autoingest is a gem for fetching iTunes connect reports.
73
+ test_files: []
74
+