itunes-receipt 0.1.5 → 1.0.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 +4 -4
- data/Rakefile +5 -5
- data/VERSION +1 -1
- data/itunes-receipt.gemspec +1 -1
- data/lib/itunes/receipt.rb +95 -35
- data/spec/spec_helper.rb +6 -2
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3af833612e81aae09bc91540df286864a5e0d7d3
|
4
|
+
data.tar.gz: 9a07a02fbb0e1101b3c453b71f4018c0b806267a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 567db980094f5d71a613c56762fca1a4fe4a4c2c830bb807679f083db3d37f9d1d1e387ce78ce6891359908fd5ec8acd2bf3900b97998ea4f5c15feffdc08c98
|
7
|
+
data.tar.gz: 5f72d4ff38935184560f9fb079acfe6a5639c09471bf5a09a15f26f81291a65292e36e4a556d334c5f3115de79c1068cf22ff8dff22c3a82b4017efae7dae3f5
|
data/Rakefile
CHANGED
@@ -4,16 +4,16 @@ Bundler::GemHelper.install_tasks
|
|
4
4
|
require 'rspec/core/rake_task'
|
5
5
|
RSpec::Core::RakeTask.new(:spec)
|
6
6
|
|
7
|
-
namespace :
|
8
|
-
desc "
|
7
|
+
namespace :coverage do
|
8
|
+
desc "Open coverage report"
|
9
9
|
task :report do
|
10
|
-
require '
|
11
|
-
|
10
|
+
require 'simplecov'
|
11
|
+
`open "#{File.join SimpleCov.coverage_path, 'index.html' }"`
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
15
|
task :spec do
|
16
|
-
Rake::Task['
|
16
|
+
Rake::Task[:'coverage:report'].invoke unless ENV['TRAVIS_RUBY_VERSION']
|
17
17
|
end
|
18
18
|
|
19
19
|
task :default => :spec
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
1.0.0
|
data/itunes-receipt.gemspec
CHANGED
@@ -20,5 +20,5 @@ Gem::Specification.new do |s|
|
|
20
20
|
s.add_development_dependency 'rake', '>= 0.8'
|
21
21
|
s.add_development_dependency 'rspec', '>= 2'
|
22
22
|
s.add_development_dependency 'fakeweb', '>= 1.3.0'
|
23
|
-
s.add_development_dependency
|
23
|
+
s.add_development_dependency 'simplecov'
|
24
24
|
end
|
data/lib/itunes/receipt.rb
CHANGED
@@ -11,7 +11,7 @@ module Itunes
|
|
11
11
|
end
|
12
12
|
|
13
13
|
class SandboxReceiptReceived < VerificationFailed; end;
|
14
|
-
|
14
|
+
|
15
15
|
class ReceiptServerOffline < VerificationFailed; end;
|
16
16
|
|
17
17
|
class ExpiredReceiptReceived < VerificationFailed
|
@@ -22,52 +22,112 @@ module Itunes
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
25
|
+
attr_reader(
|
26
|
+
:adam_id,
|
27
|
+
:app_item_id,
|
28
|
+
:application_version,
|
29
|
+
:bid,
|
30
|
+
:bundle_id,
|
31
|
+
:bvrs,
|
32
|
+
:download_id,
|
33
|
+
:expires_date,
|
34
|
+
:in_app,
|
35
|
+
:is_trial_period,
|
36
|
+
:itunes_env,
|
37
|
+
:latest,
|
38
|
+
:original,
|
39
|
+
:product_id,
|
40
|
+
:purchase_date,
|
41
|
+
:purchase_date_ms,
|
42
|
+
:purchase_date_pst,
|
43
|
+
:quantity,
|
44
|
+
:receipt_data,
|
45
|
+
:request_date,
|
46
|
+
:request_date_ms,
|
47
|
+
:request_date_pst,
|
48
|
+
:transaction_id,
|
49
|
+
:version_external_identifier,
|
50
|
+
)
|
29
51
|
|
30
52
|
def initialize(attributes = {})
|
31
53
|
receipt_attributes = attributes.with_indifferent_access[:receipt]
|
32
|
-
|
33
|
-
@quantity = receipt_attributes[:quantity].to_i
|
34
|
-
end
|
35
|
-
@product_id = receipt_attributes[:product_id]
|
36
|
-
@transaction_id = receipt_attributes[:transaction_id]
|
37
|
-
@purchase_date = if receipt_attributes[:purchase_date]
|
38
|
-
Time.parse receipt_attributes[:purchase_date].sub('Etc/', '')
|
39
|
-
end
|
54
|
+
@adam_id = receipt_attributes[:adam_id]
|
40
55
|
@app_item_id = receipt_attributes[:app_item_id]
|
41
|
-
@
|
56
|
+
@application_version = receipt_attributes[:application_version]
|
42
57
|
@bid = receipt_attributes[:bid]
|
58
|
+
@bundle_id = receipt_attributes[:bundle_id]
|
43
59
|
@bvrs = receipt_attributes[:bvrs]
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
60
|
+
@download_id = receipt_attributes[:download_id]
|
61
|
+
@expires_date = if receipt_attributes[:expires_date]
|
62
|
+
Time.at(receipt_attributes[:expires_date].to_i / 1000)
|
63
|
+
end
|
64
|
+
@in_app = if receipt_attributes[:in_app]
|
65
|
+
receipt_attributes[:in_app].map { |ia| self.class.new(:receipt => ia) }
|
66
|
+
end
|
67
|
+
@is_trial_period = if receipt_attributes[:is_trial_period]
|
68
|
+
receipt_attributes[:is_trial_period]
|
69
|
+
end
|
70
|
+
@itunes_env = attributes[:itunes_env] || Itunes.itunes_env
|
71
|
+
@latest = if attributes[:latest_receipt_info]
|
72
|
+
full_receipt_data = attributes[:latest_receipt]
|
73
|
+
self.class.new(
|
74
|
+
:receipt => attributes[:latest_receipt_info],
|
75
|
+
:latest_receipt => full_receipt_data,
|
76
|
+
:receipt_type => :latest
|
77
|
+
)
|
78
|
+
end
|
79
|
+
@original = if receipt_attributes[:original_transaction_id] || receipt_attributes[:original_purchase_date]
|
80
|
+
self.class.new(:receipt => {
|
81
|
+
:transaction_id => receipt_attributes[:original_transaction_id],
|
82
|
+
:purchase_date => receipt_attributes[:original_purchase_date],
|
83
|
+
:purchase_date_ms => receipt_attributes[:original_purchase_date_ms],
|
84
|
+
:purchase_date_pst => receipt_attributes[:original_purchase_date_pst],
|
48
85
|
:application_version => receipt_attributes[:original_application_version]
|
49
86
|
})
|
50
87
|
end
|
51
|
-
|
52
|
-
@
|
53
|
-
|
54
|
-
|
55
|
-
if receipt_attributes[:in_app]
|
56
|
-
@in_app = receipt_attributes[:in_app].map { |ia| self.class.new(:receipt => ia) }
|
88
|
+
@product_id = receipt_attributes[:product_id]
|
89
|
+
@purchase_date = if receipt_attributes[:purchase_date]
|
90
|
+
Time.parse receipt_attributes[:purchase_date].sub('Etc/GMT', 'GMT')
|
57
91
|
end
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
if
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
92
|
+
@purchase_date_ms = if receipt_attributes[:purchase_date_ms]
|
93
|
+
receipt_attributes[:purchase_date_ms].to_i
|
94
|
+
end
|
95
|
+
@purchase_date_pst = if receipt_attributes[:purchase_date_pst]
|
96
|
+
Time.parse receipt_attributes[:purchase_date_pst].sub('America/Los_Angeles', 'PST')
|
97
|
+
end
|
98
|
+
@quantity = if receipt_attributes[:quantity]
|
99
|
+
receipt_attributes[:quantity].to_i
|
100
|
+
end
|
101
|
+
@receipt_data = if attributes[:receipt_type] == :latest
|
102
|
+
attributes[:latest_receipt]
|
103
|
+
end
|
104
|
+
@request_date = if receipt_attributes[:request_date]
|
105
|
+
Time.parse receipt_attributes[:request_date].sub('Etc/', '')
|
106
|
+
end
|
107
|
+
@request_date_ms = if receipt_attributes[:request_date_ms]
|
108
|
+
receipt_attributes[:request_date_ms].to_i
|
109
|
+
end
|
110
|
+
@request_date_pst = if receipt_attributes[:request_date_pst]
|
111
|
+
Time.parse receipt_attributes[:request_date_pst].sub('America/Los_Angeles', 'PST')
|
112
|
+
end
|
113
|
+
@transaction_id = receipt_attributes[:transaction_id]
|
114
|
+
@version_external_identifier = receipt_attributes[:version_external_identifier]
|
69
115
|
end
|
70
116
|
|
117
|
+
def as_json
|
118
|
+
{
|
119
|
+
:quantity => @quantity,
|
120
|
+
:product_id => @product_id,
|
121
|
+
:transaction_id => @transaction_id,
|
122
|
+
:purchase_date => @purchase_date,
|
123
|
+
:original_transaction_id => @original.try(:transaction_id),
|
124
|
+
:original_purchase_date => @original.try(:purchase_date),
|
125
|
+
:is_trial_period => @is_trial_period
|
126
|
+
}.tap do |hash|
|
127
|
+
hash[:application_version] = @application_version if @application_version.present?
|
128
|
+
hash[:bundle_id] = @bundle_id if @bundle_id.present?
|
129
|
+
end
|
130
|
+
end
|
71
131
|
|
72
132
|
def application_receipt?
|
73
133
|
!@bundle_id.nil?
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: itunes-receipt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- nov matake
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-02-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -109,19 +109,19 @@ dependencies:
|
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: 1.3.0
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
112
|
+
name: simplecov
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
115
|
- - '>='
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version:
|
117
|
+
version: '0'
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
122
|
- - '>='
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version:
|
124
|
+
version: '0'
|
125
125
|
description: Handle iTunes In App Purchase Receipt Verification
|
126
126
|
email: nov@matake.jp
|
127
127
|
executables: []
|