apple_reporter 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 68ad733ac1c03c1a768daa5a3df1b22943da3f1af59094118868283f99e49024
4
- data.tar.gz: ee402084f42e5c81993fdc07952482e3155d60707ed7a559a5a4c931c9899df5
3
+ metadata.gz: 1e96ff23e34a81a9f7ba0e6d93420cba262039578c4a3d0dbeff2d50b5427c81
4
+ data.tar.gz: d9321c247000ce4e397b13e210e3de4177016d27156cd1b0741fafa13f1f1755
5
5
  SHA512:
6
- metadata.gz: f80632c87c808fa928bbb2d12f8798ca2e1478503423f5a20964c8519ec07b609294cffdda86d4b5ff10b6eb3e36a4f4bf8fef8760c615d06d5a9ebf2b55764b
7
- data.tar.gz: 72cb636cb268b934844efbacebf3ed9b3a6e33cb2fb9297cd178277082382150d98e3d8ecba5f05a8bab0535a2ac72099c75cd978b435dc2ac29f5bdfc11d056
6
+ metadata.gz: fbaaea3513df08e0afb7519cdfff2513cb65f0dfeae375e01d56ea5b5c66de720ae1a9195b4f60dc77364db9c344b9148929504670dd07e673e9d43decbcc1bd
7
+ data.tar.gz: 58b9ebf2e728af1b1380ebed53914321efd372369e8bc33ee715d7397fedea6c3c455a30a7b225bbea09ab4446379cd4bd6abf7c9db8109ae116c3c2006a1f49
data/.gitignore CHANGED
@@ -7,3 +7,5 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ .byebug_history
11
+ .DS_Store
data/Gemfile CHANGED
@@ -2,3 +2,18 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in apple_reporter.gemspec
4
4
  gemspec
5
+
6
+ group :development do
7
+ gem 'rake'
8
+ gem 'webmock'
9
+
10
+ platforms :mri do
11
+ # to avoid problems, bring Byebug in on just versions of Ruby under which
12
+ # it's known to work well
13
+ if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.0.0')
14
+ gem 'byebug'
15
+ gem 'pry'
16
+ gem 'pry-byebug'
17
+ end
18
+ end
19
+ end
data/README.md CHANGED
@@ -59,8 +59,8 @@ report = reporter.get_report(
59
59
 
60
60
  ```ruby
61
61
  reporter = AppleReporter::Finance.new(
62
- user_id: 'your user id',
63
- access_token: 'your access token'
62
+ user_id: 'your user id',
63
+ access_token: 'your access token',
64
64
  version: '1_1'
65
65
  )
66
66
  report = reporter.get_report(
@@ -1,7 +1,7 @@
1
1
  module AppleReporter
2
2
  class Reporter
3
3
  ENDPOINT = 'https://reportingitc-reporter.apple.com/reportservice'
4
-
4
+ GZIP_MIMETYPE = '1f8b0800000000000000'.freeze
5
5
  #
6
6
  # Usage:
7
7
  # reporter = Apple::Reporter::Sale.new(user_id: 'iscreen', access_token: 'secret', account: 'myAccount')
@@ -30,20 +30,25 @@ module AppleReporter
30
30
  }
31
31
  payload[:account] = @config[:account] if @config[:account]
32
32
  payload[:password] = @config[:password] if @config[:password]
33
-
34
- response = RestClient.post("#{ENDPOINT}#{api_path}", "jsonRequest=#{payload.to_json}#{url_params}", headers)
33
+ response = RestClient.post(
34
+ "#{ENDPOINT}#{api_path}",
35
+ "jsonRequest=#{payload.to_json}#{url_params}",
36
+ headers
37
+ )
35
38
  handle_response(@config[:mode], response)
36
39
  rescue RestClient::ExceptionWithResponse => err
37
- handle_response(@config[:mode], err.response)
40
+ if err.response
41
+ handle_response(@config[:mode], err.response)
42
+ else
43
+ raise err
44
+ end
38
45
  end
39
46
 
40
47
  #
41
48
  def handle_response(mode, response)
42
49
  if response.code == 200
43
50
  if response.headers[:content_type] == 'application/a-gzip'
44
- io = StringIO.new(response.body)
45
- gz = Zlib::GzipReader.new(io)
46
- return gz.readlines.join
51
+ decompress_gzip(response.body)
47
52
  else
48
53
  handle_response_body_with_mode(response.body, mode)
49
54
  end
@@ -59,5 +64,18 @@ module AppleReporter
59
64
  body
60
65
  end
61
66
  end
67
+
68
+ def decompress_gzip(compress_string)
69
+ buffer = []
70
+ chunks = compress_string.unpack('H*').first.split(GZIP_MIMETYPE)
71
+ if chunks.length == 1
72
+ buffer << ActiveSupport::Gzip.decompress([chunks.first].pack('H*'))
73
+ else
74
+ chunks.reject(&:empty?).each do |chunk|
75
+ buffer << Zlib::GzipReader.new(StringIO.new([GZIP_MIMETYPE + chunk].pack('H*'))).read
76
+ end
77
+ end
78
+ buffer.join
79
+ end
62
80
  end
63
81
  end
@@ -1,3 +1,3 @@
1
1
  module AppleReporter
2
- VERSION = '0.1.6'.freeze
2
+ VERSION = '0.1.7'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apple_reporter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dean Lin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-11-20 00:00:00.000000000 Z
11
+ date: 2018-12-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client