Class: Itunes::Receipt::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/itunes/receipt/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



4
5
6
# File 'lib/itunes/receipt/response.rb', line 4

def data
  @data
end

#requestObject (readonly)

Returns the value of attribute request.



4
5
6
# File 'lib/itunes/receipt/response.rb', line 4

def request
  @request
end

#responseObject (readonly)

Returns the value of attribute response.



4
5
6
# File 'lib/itunes/receipt/response.rb', line 4

def response
  @response
end

Instance Method Details

#latest_receiptObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/itunes/receipt/response.rb', line 6

def latest_receipt
   info = data['latest_receipt_info'] || data['latest_expired_receipt_info']

   @latest_receipt ||=
   case info
   when Array
      base_receipt = data['receipt'].dup
      base_receipt.delete('in_app')
      receipt = info.sort_by { |x| x['expires_date'] }.last
      Itunes::Receipt::V2.new(data: base_receipt.merge(receipt))
   when Hash
      Itunes::Receipt::V1.new(data: info)
   end
end

#receiptObject



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/itunes/receipt/response.rb', line 21

def receipt
   if receipt = data['receipt']
      @receipt ||=
      if data['receipt']['in_app']
         base_receipt = data['receipt'].dup
         base_receipt.delete('in_app')
         Itunes::Receipt::V2.new(data: base_receipt)
      else
         Itunes::Receipt::V1.new(data: receipt)
      end
   end
end

#receiptsObject



34
35
36
37
38
39
40
41
42
43
# File 'lib/itunes/receipt/response.rb', line 34

def receipts
   @receipts ||=
   if receipts = data['receipt']['in_app']
      base_receipt = data['receipt'].dup
      base_receipt.delete('in_app')
      receipts.sort_by { |x| x['expires_date'] }.map { |r| Itunes::Receipt::V2.new(data: base_receipt.merge(r)) }
   else
      [ receipt, latest_receipt ]
   end
end

#statusObject



45
46
47
# File 'lib/itunes/receipt/response.rb', line 45

def status
   @status ||= data['status']
end

#valid?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/itunes/receipt/response.rb', line 49

def valid?
   status == 0
end

#validate!Object



53
54
55
56
57
58
59
# File 'lib/itunes/receipt/response.rb', line 53

def validate!
   if not valid?
      raise(Itunes::Receipt::Error.new(status))
   end

   true
end