itunes_validator 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/itunes_validator/client.rb +14 -0
- data/lib/itunes_validator/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1383cfb2c9e8a04f1ea0ea8af36e6ecbd0c5b865
|
4
|
+
data.tar.gz: 421dce6d0ad73e6eea100b3d046ad0457d59547c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|