itunes_receipt_validator 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/itunes_receipt_validator/transaction.rb +48 -16
- data/lib/itunes_receipt_validator/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 59447ec52b6230c6b2615a9a915acddf433bdb5b
|
4
|
+
data.tar.gz: 1dcf1d374181b0f55ac86080eea1d351061800d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1b3109ff7b381d1e711f32245281273a6158a1604ef1161b7ea389fdd979cca183ebd302f05933a6473a2cd67aa2cb82c838ca70362e012a4a230fca0a89f500
|
7
|
+
data.tar.gz: 0ac47696ebda71a9a291429a0117f2a8c930e475c30f29c3cf1c46e8ce283ea81c7c196e447a8b5d6f374eddc9d76b94fa4a70ae9bbc531f418142bab9c258b6
|
@@ -6,6 +6,35 @@ module ItunesReceiptValidator
|
|
6
6
|
##
|
7
7
|
# ItunesReceiptValidator::Transaction
|
8
8
|
class Transaction
|
9
|
+
ATTR_MAP = {
|
10
|
+
id: :transaction_id,
|
11
|
+
original_id: :original_transaction_id,
|
12
|
+
product_id: :product_id,
|
13
|
+
quantity: :quantity,
|
14
|
+
web_order_line_item_id: proc do |hash|
|
15
|
+
hash[:web_order_line_item_id].to_s if
|
16
|
+
hash.fetch(:web_order_line_item_id, 0).to_i > 0
|
17
|
+
end,
|
18
|
+
trial_period: ->(hash) { hash[:is_trial_period] == 'true' },
|
19
|
+
purchased_at: proc do |hash|
|
20
|
+
parse_date(hash[:purchase_date_ms] || hash[:purchase_date])
|
21
|
+
end,
|
22
|
+
first_purchased_at: proc do |hash|
|
23
|
+
parse_date hash[:original_purchase_date_ms] ||
|
24
|
+
hash[:original_purchase_date]
|
25
|
+
end,
|
26
|
+
cancelled_at: proc do |hash|
|
27
|
+
parse_date(hash[:cancelled_date_ms] || hash[:cancelled_date])
|
28
|
+
end,
|
29
|
+
expires_at: proc do |hash|
|
30
|
+
if hash[:bid]
|
31
|
+
parse_date(hash[:expires_date] || hash[:expires_date_formatted])
|
32
|
+
else
|
33
|
+
parse_date(hash[:expires_date_ms] || hash[:expires_date])
|
34
|
+
end
|
35
|
+
end
|
36
|
+
}
|
37
|
+
|
9
38
|
attr_reader :id, :original_id, :product_id, :quantity, :first_purchased_at,
|
10
39
|
:purchased_at, :expires_at, :cancelled_at,
|
11
40
|
:web_order_line_item_id, :trial_period, :receipt
|
@@ -39,26 +68,29 @@ module ItunesReceiptValidator
|
|
39
68
|
|
40
69
|
private
|
41
70
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
end
|
71
|
+
attr_writer :id, :original_id, :product_id, :quantity,
|
72
|
+
:web_order_line_item_id, :trial_period, :purchased_at,
|
73
|
+
:first_purchased_at, :cancelled_at, :expires_at
|
46
74
|
|
47
75
|
def normalize(hash)
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
76
|
+
ATTR_MAP.each do |key, val|
|
77
|
+
if val.is_a?(Proc)
|
78
|
+
send("#{key}=".to_s, instance_exec(hash, &val))
|
79
|
+
else
|
80
|
+
send("#{key}=".to_s, hash[val])
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def parse_date(date)
|
86
|
+
return nil if date.nil?
|
87
|
+
if date.is_a?(Integer) || (date =~ /^\d+$/) == 0
|
88
|
+
Time.at(date.to_f / 1000).utc
|
59
89
|
else
|
60
|
-
|
90
|
+
Time.strptime(date, '%F %T Etc/%Z').utc
|
61
91
|
end
|
92
|
+
rescue StandardError => _e
|
93
|
+
nil
|
62
94
|
end
|
63
95
|
end
|
64
96
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: itunes_receipt_validator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mbaasy.com
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-12-
|
11
|
+
date: 2015-12-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: itunes_receipt_decoder
|