ireporter 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 79a4b2c1fc05047fe2a31330f8fe4b5db5d2fa76
4
+ data.tar.gz: 5238c49819dfdf0145fa817f45c6655efbf5fdd1
5
+ SHA512:
6
+ metadata.gz: 1774389467a26b99f4944c363a7fc9ec5cdf7b445cdfbf187673d0ce3d7e6a0d62683530dad5d1dc3b4c55a2bd2f4ae94a67ac0e87c829ba14e1910adb7ffc91
7
+ data.tar.gz: a3c5462dcb6b2f754d7a48ad197bd2801c4a549d3a5bff92a2aa0437315f9a873d25fe103831a63ef7a751b70eb0ea7b08532261dbd54dac6313d2dd6d3596ff
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1 @@
1
+ CODE_OF_CONDUCT.md
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ireporter.gemspec
4
+
5
+ gem "rest-client"
6
+
7
+
8
+
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Akshay Naik
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,41 @@
1
+ # Ireporter
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/ireporter`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'ireporter'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install ireporter
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/ireporter. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ireporter"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ireporter/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ireporter"
8
+ spec.version = Ireporter::VERSION
9
+ spec.authors = ["Akshay Naik","Rushikesh Kawadkar"]
10
+ spec.email = ["akshaynaik93@gmail.com"]
11
+
12
+ spec.summary = "ITC Reporter for apple reporting service"
13
+ spec.homepage = "https://github.com/nakshay/iReporter"
14
+ spec.license = "MIT"
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ if spec.respond_to?(:metadata)
19
+
20
+ else
21
+ raise "RubyGems 2.0 or newer is required to protect against " \
22
+ "public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
26
+ f.match(%r{^(test|spec|features)/})
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.add_development_dependency "bundler", "~> 1.13"
33
+ spec.add_development_dependency "rake", "~> 10.0"
34
+ end
@@ -0,0 +1,5 @@
1
+ require "ireporter/version"
2
+
3
+ module Ireporter
4
+ autoload :Reporter, 'ireporter/reporter'
5
+ end
@@ -0,0 +1,132 @@
1
+ require 'rest-client'
2
+ require 'zlib'
3
+ require 'json'
4
+
5
+
6
+ module Ireporter
7
+
8
+ class Reporter
9
+
10
+
11
+ # Constants initialization
12
+ VERSION = '1.0'
13
+ URL_SALES = 'https://reportingitc-reporter.apple.com/reportservice/sales/v1'
14
+ URL_FINANCE = 'https://reportingitc-reporter.apple.com/reportservice/finance/v1'
15
+
16
+ DATE_TYPE_DAILY = "Daily"
17
+ DATE_TYPE_WEEKLY = "Weekly"
18
+
19
+
20
+ #constructor
21
+
22
+ def initialize(username,password)
23
+ @username = username
24
+ @password = password
25
+ end
26
+
27
+ def get_status (service)
28
+
29
+ command = "[p=Reporter.properties, "+service+".getStatus]"
30
+ url = service == 'Sales' ? URL_SALES : URL_FINANCE
31
+
32
+ parameters = build_json_request(command)
33
+
34
+ response = post_request(parameters,url)
35
+
36
+ if response.headers[:"errormsg"]
37
+ raise "error fetching status"
38
+ else response.headers[:"filename"]
39
+ return response.body
40
+ end
41
+ end
42
+
43
+
44
+ def get_vendor()
45
+
46
+ command = '[p=Reporter.properties, Sales.getVendors]'
47
+
48
+ parameters = build_json_request(command)
49
+ response = post_request(parameters,URL_SALES)
50
+
51
+ if response.headers[:"errormsg"]
52
+ raise "vendor number not found"
53
+ else response.headers[:"filename"]
54
+ return response.body
55
+ end
56
+ end
57
+
58
+ def get_sales_report(datetype,reportdate)
59
+
60
+
61
+ datetype ||= DATE_TYPE_DAILY
62
+ reportdate ||= (Time.now-60*60*24).strftime("%Y%m%d")
63
+
64
+ vendorNumber=get_vendor().chomp
65
+
66
+ command = '[p=Reporter.properties, Sales.getReport, '+vendorNumber+',Sales,Summary,'+datetype+','+reportdate+']'
67
+ parameters = build_json_request(command)
68
+
69
+ response = post_request(parameters,URL_SALES)
70
+
71
+
72
+ if response.headers[:"errormsg"]
73
+ raise ITunesConnectError.new response.headers[:"errormsg"]
74
+ elsif response.headers[:"filename"]
75
+ Zlib::GzipReader.new(StringIO.new(response.body)).read
76
+ else
77
+ raise "no data returned from itunes: #{response.body}"
78
+ end
79
+ end
80
+
81
+
82
+ def build_json_request(command)
83
+
84
+ request_data = { :userid => @username ,:queryInput => command, :version => VERSION,:password => @password}
85
+ #Convert request paramters in JSON format
86
+ request_data=request_data.to_json
87
+
88
+ return 'jsonRequest='+ request_data
89
+ end
90
+
91
+
92
+ def post_request(parameters,url)
93
+
94
+ RestClient.post( url, parameters, headers = {:Accept => 'text/html,image/gif,image/jpeg; q=.2, */*; q=.2'} )
95
+ end
96
+
97
+ # Wrap data into Array
98
+ def wrap(report)
99
+ lines = report.split("\n")
100
+ header = lines.shift
101
+ lines.collect do |line|
102
+ provider, country, sku, developer, title, version, product_type_id, units, developer_proceeds, begin_date, end_date, currency, country_code, currency_of_proceeds, apple_id, customer_price, promo_code, parent_id, subscription, period = line.split("\t")
103
+ {
104
+ :provider => provider.strip,
105
+ :country => country.strip,
106
+ :sku => sku.strip,
107
+ :developer => developer.strip,
108
+ :title => title.strip,
109
+ :version => version.strip,
110
+ :product_type_id => product_type_id.strip,
111
+ :units => units.to_i,
112
+ :developer_proceeds => developer_proceeds.to_f,
113
+ :begin_date => Date.strptime(begin_date.strip, '%m/%d/%Y'),
114
+ :end_date => Date.strptime(end_date.strip, '%m/%d/%Y'),
115
+ :currency => currency.strip,
116
+ :country_code => country_code.strip,
117
+ :currency_of_proceeds => currency_of_proceeds.strip,
118
+ :apple_id => apple_id.to_i,
119
+ :customer_price => customer_price.to_f,
120
+ :promo_code => promo_code.strip,
121
+ :parent_id => parent_id.strip,
122
+ :subscription => subscription.strip,
123
+ :period => period
124
+ }
125
+ end
126
+ end
127
+
128
+
129
+ private :build_json_request,:post_request
130
+ end # class end
131
+
132
+ end #module end
@@ -0,0 +1,3 @@
1
+ module Ireporter
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ireporter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Akshay Naik
8
+ - Rushikesh Kawadkar
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2017-01-15 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.13'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1.13'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '10.0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '10.0'
42
+ description:
43
+ email:
44
+ - akshaynaik93@gmail.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - CODE_OF_CONDUCT.md
51
+ - Gemfile
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - bin/console
56
+ - bin/setup
57
+ - ireporter.gemspec
58
+ - lib/ireporter.rb
59
+ - lib/ireporter/reporter.rb
60
+ - lib/ireporter/version.rb
61
+ homepage: https://github.com/nakshay/iReporter
62
+ licenses:
63
+ - MIT
64
+ metadata: {}
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ requirements: []
80
+ rubyforge_project:
81
+ rubygems_version: 2.5.2
82
+ signing_key:
83
+ specification_version: 4
84
+ summary: ITC Reporter for apple reporting service
85
+ test_files: []