ireporter 0.1.0 → 0.1.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 79a4b2c1fc05047fe2a31330f8fe4b5db5d2fa76
4
- data.tar.gz: 5238c49819dfdf0145fa817f45c6655efbf5fdd1
3
+ metadata.gz: 997fee57d686d48ad5e8a7042f24c9872f13cf22
4
+ data.tar.gz: f6f6c484623f3f596bbed8c1a29af8e3f6bd9b85
5
5
  SHA512:
6
- metadata.gz: 1774389467a26b99f4944c363a7fc9ec5cdf7b445cdfbf187673d0ce3d7e6a0d62683530dad5d1dc3b4c55a2bd2f4ae94a67ac0e87c829ba14e1910adb7ffc91
7
- data.tar.gz: a3c5462dcb6b2f754d7a48ad197bd2801c4a549d3a5bff92a2aa0437315f9a873d25fe103831a63ef7a751b70eb0ea7b08532261dbd54dac6313d2dd6d3596ff
6
+ metadata.gz: bece219ed2412aab7e7ad6ae3ad8d697e37d7af624a1a8990217aeb091d97e008446f4885020ffefb09f2496c138bed930dd5f0b132b90a0f53d30a63fe90bb7
7
+ data.tar.gz: a2763a73efcfef4fb8cc14a7097e5fec5aff67bf7972f3e2bb3ba8cb900bc8a1f0b74a12578466ea17e1a4a726115f12142bb99d5d17bf6565ad1b3cb70fbf4e
data/Gemfile CHANGED
@@ -1,6 +1,5 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in ireporter.gemspec
4
3
 
5
4
  gem "rest-client"
6
5
 
data/README.md CHANGED
@@ -1,8 +1,10 @@
1
1
  # Ireporter
2
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.
3
+ This gem is the Ruby alternative to **iTunes Connect Reporter** written in java library used to fetch sales and finance reports.
4
+
5
+ This gem is written considering requirement of Rails app, but can be used as a regular ruby gem.
6
+
4
7
 
5
- TODO: Delete this and the text above, and describe your gem
6
8
 
7
9
  ## Installation
8
10
 
@@ -22,20 +24,67 @@ Or install it yourself as:
22
24
 
23
25
  ## Usage
24
26
 
25
- TODO: Write usage instructions here
27
+ Create a reporter object
28
+
29
+ ```
30
+ reporterObj= Ireporter::Reporter.new('user id','password')
31
+ ```
32
+
33
+ And use below awesome methods, and see the Magic happen.
34
+
35
+ Get the status of services (Sales and Finance)
36
+
37
+ ```
38
+ reporterObj.get_status('Sales')
39
+ reporterObj.get_status('Finance')
40
+
41
+ ```
42
+
43
+ Fetch the sales report
26
44
 
27
- ## Development
45
+ ```
46
+ report_data=reporterObj.get_sales_report('daily','20160818')
47
+ ```
28
48
 
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.
49
+ And then wrap it in the Array
30
50
 
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).
51
+ ```
52
+ array = reporterObj.wrap(report_data)
53
+ ```
32
54
 
33
55
  ## Contributing
34
56
 
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.
57
+ Bug reports and pull requests are welcome on GitHub at https://github.com/nakshay/ireporter.
58
+
59
+
60
+ ## Contributors
61
+
62
+ Akshay Naik
63
+
64
+ Rushikesh Kawadkar
65
+
66
+
67
+ ## Contributors
68
+
69
+ The MIT License (MIT)
70
+
71
+ Copyright (c) 2017 Akshay Naik
36
72
 
73
+ Permission is hereby granted, free of charge, to any person obtaining a copy
74
+ of this software and associated documentation files (the "Software"), to deal
75
+ in the Software without restriction, including without limitation the rights
76
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
77
+ copies of the Software, and to permit persons to whom the Software is
78
+ furnished to do so, subject to the following conditions:
37
79
 
38
- ## License
80
+ The above copyright notice and this permission notice shall be included in
81
+ all copies or substantial portions of the Software.
39
82
 
40
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
83
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
84
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
85
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
86
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
87
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
88
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
89
+ THE SOFTWARE.
41
90
 
@@ -31,4 +31,6 @@ Gem::Specification.new do |spec|
31
31
 
32
32
  spec.add_development_dependency "bundler", "~> 1.13"
33
33
  spec.add_development_dependency "rake", "~> 10.0"
34
+ spec.add_runtime_dependency "rest-client"
35
+
34
36
  end
@@ -19,114 +19,114 @@ DATE_TYPE_WEEKLY = "Weekly"
19
19
 
20
20
  #constructor
21
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
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
130
  end # class end
131
131
 
132
132
  end #module end
@@ -1,3 +1,3 @@
1
1
  module Ireporter
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ireporter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Akshay Naik
@@ -39,6 +39,20 @@ dependencies:
39
39
  - - "~>"
40
40
  - !ruby/object:Gem::Version
41
41
  version: '10.0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rest-client
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
42
56
  description:
43
57
  email:
44
58
  - akshaynaik93@gmail.com