itunes_validator 0.2.1 → 0.3.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 906f270f46d2dcc5eb43dd20a91516c99351f618
4
- data.tar.gz: eac2d4410b1dd86e14d6e785e4d78cbd4c8c1ce6
3
+ metadata.gz: 1383cfb2c9e8a04f1ea0ea8af36e6ecbd0c5b865
4
+ data.tar.gz: 421dce6d0ad73e6eea100b3d046ad0457d59547c
5
5
  SHA512:
6
- metadata.gz: c97643fe127a11568a5cb05cf90cd85068c0d993ec78b14a557624bf39b52435a8a891f3b3e93dc9be03430d48fdd561f3f09a4982417d2e9d467a958dde6b4e
7
- data.tar.gz: e3661fa30e469ee41cbb25bfb84c5c09ed0754c559997bb39c9ac40ff667ccc6b898aaa2b968d2e4c7937c2cb30658b2625f9535fd883e50417a21fe189c2e98
6
+ metadata.gz: 8bbd3b01c5cf941b22f88eb75e5ea1f29e69c569e7050deb08812e0208f84000f5226c214def75ac6ae299a9db7d2b9e736a1b12e9c39e8b78bf994011f2d813
7
+ data.tar.gz: 80e92c453c1476f15c4be05935d3f2131d8d986de38e250886cc4c417a1165b6816b0d5fc754d26263cfadcfc813d441fe1db75cc65a9d2a8f8e76c2c9c6aac3
@@ -14,6 +14,7 @@ module ItunesValidator
14
14
  class Client
15
15
  def initialize(options=nil)
16
16
  @shared_secret = options[:shared_secret] if options
17
+ @use_latest = (options[:use_latest] if options) || true
17
18
  end
18
19
 
19
20
  def validate(receipt_data)
@@ -34,15 +35,20 @@ module ItunesValidator
34
35
  req.body = post_body.to_json
35
36
 
36
37
  response = http.request(req)
38
+ raise ItunesCommunicationError.new(response.code) unless response.code == '200'
37
39
  response_body = JSON.parse(response.body)
38
40
 
39
41
  case itunes_status = response_body['status'].to_i
40
42
  when 0
41
43
  receipt_info = response_body['receipt']
44
+ if @use_latest && response_body['latest_receipt_info']
45
+ receipt_info = response_body['latest_receipt_info']
46
+ end
42
47
  else
43
48
  raise ItunesValidationError.new(itunes_status)
44
49
  end
45
50
  end
51
+ rescue ItunesCommunicationError
46
52
  rescue ItunesValidationError => e
47
53
  case e.code
48
54
  when 21007
@@ -61,6 +67,14 @@ module ItunesValidator
61
67
  class ParameterError < Error
62
68
  end
63
69
 
70
+ class ItunesCommunicationError < Error
71
+ def initialize(code)
72
+ @code = code
73
+ end
74
+
75
+ attr_reader :code
76
+ end
77
+
64
78
  class ItunesValidationError < Error
65
79
  def initialize(code)
66
80
  @code = code
@@ -1,3 +1,3 @@
1
1
  module ItunesValidator
2
- VERSION = '0.2.1'
2
+ VERSION = '0.3.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: itunes_validator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Talbot