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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a56aa2df0293a47cd466a461d92e0549fe556dac
4
- data.tar.gz: 2e17d9e6fc166fbbc768eabdf6ae54fedf3d4cb3
3
+ metadata.gz: 3af833612e81aae09bc91540df286864a5e0d7d3
4
+ data.tar.gz: 9a07a02fbb0e1101b3c453b71f4018c0b806267a
5
5
  SHA512:
6
- metadata.gz: 505a4bab9cdf6a84e7e47ff2fc2181078cdec24f38ca17adb87d91a7b34aa41e8c90a67e4ce8c68bfe801bb371c3887523c3db273764e4fa56c342a3f0f2b94b
7
- data.tar.gz: f213f409d049054afec8f03696614fc9e08d18926a5607561a2ea29b7e83e03bec68c81cdfca9611765ec1be694dff2df66dc447b9974e5f85805522f091a44a
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 :cover_me do
8
- desc "Generates and opens code coverage report."
7
+ namespace :coverage do
8
+ desc "Open coverage report"
9
9
  task :report do
10
- require 'cover_me'
11
- CoverMe.complete!
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['cover_me:report'].invoke unless ENV['TRAVIS_RUBY_VERSION']
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.5
1
+ 1.0.0
@@ -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 "cover_me", ">= 1.2.0"
23
+ s.add_development_dependency 'simplecov'
24
24
  end
@@ -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
- # expires_date, receipt_data, and latest (receipt) will only appear for autorenew subscription products
26
- attr_reader :quantity, :product_id, :transaction_id, :purchase_date, :app_item_id, :version_external_identifier, :bid, :bvrs, :original, :expires_date, :receipt_data, :latest, :itunes_env
27
-
28
- attr_reader :bundle_id, :application_version, :in_app
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
- if receipt_attributes[:quantity]
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
- @version_external_identifier = receipt_attributes[:version_external_identifier]
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
- if receipt_attributes[:original_transaction_id] || receipt_attributes[:original_purchase_date]
45
- @original = self.class.new(:receipt => {
46
- :transaction_id => receipt_attributes[:original_transaction_id],
47
- :purchase_date => receipt_attributes[:original_purchase_date],
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
- @bundle_id = receipt_attributes[:bundle_id]
53
- @application_version = receipt_attributes[:application_version]
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
- # autorenew subscription handling
60
- # attributes[:latest_receipt_info] and attributes[:latest_receipt] will be nil if you already have the receipt for the most recent renewal.
61
- if attributes[:latest_receipt_info]
62
- full_receipt_data = attributes[:latest_receipt] # should also be in the top-level hash if attributes[:latest_receipt_info] is there, but this won't break if it isn't
63
- @latest = self.class.new(:receipt => attributes[:latest_receipt_info], :latest_receipt => full_receipt_data, :receipt_type => :latest)
64
- end
65
- @expires_date = Time.at(receipt_attributes[:expires_date].to_i / 1000) if receipt_attributes[:expires_date]
66
- @receipt_data = attributes[:latest_receipt] if attributes[:receipt_type] == :latest # it feels wrong to include the receipt_data for the latest receipt on anything other than the latest receipt
67
-
68
- @itunes_env = attributes[:itunes_env] || Itunes.itunes_env
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?
@@ -1,6 +1,10 @@
1
- require 'cover_me'
2
- require 'rspec'
1
+ require 'simplecov'
2
+
3
+ SimpleCov.start do
4
+ add_filter 'spec'
5
+ end
3
6
 
7
+ require 'rspec'
4
8
  require 'itunes/receipt'
5
9
  require 'helpers/fake_json_helper'
6
10
 
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.1.5
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: 2013-11-30 00:00:00.000000000 Z
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: cover_me
112
+ name: simplecov
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - '>='
116
116
  - !ruby/object:Gem::Version
117
- version: 1.2.0
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: 1.2.0
124
+ version: '0'
125
125
  description: Handle iTunes In App Purchase Receipt Verification
126
126
  email: nov@matake.jp
127
127
  executables: []