itunes_receipt_decoder 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1f91cdd0877d05e706d5620f7bf29f871ab656f3
4
- data.tar.gz: ce718feed167486e498dcbc417a410058505c6c5
3
+ metadata.gz: 7249d3ca881c622ef2e0ccd6d94be8da200eece2
4
+ data.tar.gz: ccea5b7c522881e76705920a20a6ab49a396d7ea
5
5
  SHA512:
6
- metadata.gz: 269eb5b5315bf31c5318ab7f7236972e81d4dc76f826d1aebdad422355468a104ca1f2b72c5ea7c26688c90d0ed81619354fe30bd7ddd7e7399c585b5d6f3118
7
- data.tar.gz: b1cdc45f24929b77c82e75bbfaf068797df9ef46de591795a4f08e0b00f5c92486a29e6e4564a37aaeb312811da23f5b3784db71066657b98f4777f66a1a70e7
6
+ metadata.gz: 812a954786a1bb1dc53677e68a8fe8494b6f8f46765d5ce8404132354680bccffc774bd2fb909e1d76e06e643493da1b4b010eb701b3e680270c91093e86b562
7
+ data.tar.gz: 0887a6b967bdd98309bc052812bfee0500d3cdcec88725e8cf0f109f3e0e0ff2de186e5624bfc73ce46d68ccedf820d7cc41c4f2d9cc0f2adb767b036db21394
@@ -26,7 +26,7 @@ module ItunesReceiptDecoder
26
26
  ##
27
27
  # Returns true if the receipt is created in the Production environment
28
28
  def production?
29
- environment == 'Production'
29
+ environment == :production
30
30
  end
31
31
 
32
32
  ##
@@ -16,9 +16,11 @@ module ItunesReceiptDecoder
16
16
 
17
17
  def decode
18
18
  @receipt = parse_purchase_info
19
- @environment = payload.fetch('environment', nil)
20
- rescue KeyError => e
21
- raise DecodingError, e.message
19
+ if payload.fetch('environment', 'Production') == 'Production'
20
+ @environment = :production
21
+ else
22
+ @environment = :sandbox
23
+ end
22
24
  end
23
25
 
24
26
  def parse_purchase_info
@@ -30,14 +32,8 @@ module ItunesReceiptDecoder
30
32
  end
31
33
 
32
34
  def purchase_info
33
- return @purchase_info if @purchase_info
34
- contents = Base64.decode64 payload.fetch('purchase-info')
35
- rescue KeyError => e
36
- raise DecodingError, e.message
37
- rescue ArgumentError => e
38
- raise DecodingError, e.message
39
- else
40
- @purchase_info = parse_plist(contents)
35
+ @purchase_info ||=
36
+ parse_plist(payload.fetch('purchase-info').unpack('m').first)
41
37
  end
42
38
 
43
39
  def payload
@@ -49,6 +45,8 @@ module ItunesReceiptDecoder
49
45
  hash = CFPropertyList.native_types(plist.value)
50
46
  fail DecodingError, 'hash not found in plist' unless hash.is_a?(Hash)
51
47
  hash
48
+ rescue CFPlistError => e
49
+ raise DecodingError, e.message
52
50
  end
53
51
  end
54
52
  end
@@ -43,7 +43,11 @@ module ItunesReceiptDecoder
43
43
 
44
44
  def decode
45
45
  @receipt = parse_app_receipt_fields(payload.value)
46
- @environment = @receipt.fetch(:environment, nil)
46
+ if @receipt.fetch(:environment, 'Production') == 'Production'
47
+ @environment = :production
48
+ else
49
+ @environment = :sandbox
50
+ end
47
51
  end
48
52
 
49
53
  def parse_app_receipt_fields(fields)
@@ -3,5 +3,5 @@
3
3
  module ItunesReceiptDecoder
4
4
  ##
5
5
  # Gem version
6
- VERSION = '0.2.2'
6
+ VERSION = '0.2.3'
7
7
  end
@@ -1,5 +1,4 @@
1
1
  require 'time'
2
- require 'base64'
3
2
  require 'openssl'
4
3
  require 'cfpropertylist'
5
4
  require 'itunes_receipt_decoder/version'
@@ -22,12 +21,12 @@ module ItunesReceiptDecoder
22
21
  # * +receipt_data+ - the base64 encoded receipt
23
22
  # * +options+ - optional arguments
24
23
  def self.new(receipt_data, options = {})
25
- raw_receipt = Base64.decode64(receipt_data)
24
+ raw_receipt = receipt_data.unpack('m').first
26
25
  rescue ArgumentError => e
27
26
  raise DecodingError, e.message
28
27
  else
29
- if (match = raw_receipt.match(PLIST_REGEX))
30
- Decode::TransactionReceipt.new(match[0], options)
28
+ if (match = raw_receipt.match(PLIST_REGEX).to_a.first) && match.ascii_only?
29
+ Decode::TransactionReceipt.new(match, options)
31
30
  else
32
31
  Decode::UnifiedReceipt.new(raw_receipt, options)
33
32
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: itunes_receipt_decoder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
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-02 00:00:00.000000000 Z
11
+ date: 2015-12-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: CFPropertyList