Class: Itunes::Receipt::Response
- Inherits:
-
Object
- Object
- Itunes::Receipt::Response
- Defined in:
- lib/itunes/receipt/response.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
- #latest_receipt ⇒ Object
- #receipt ⇒ Object
- #receipts ⇒ Object
- #status ⇒ Object
- #valid? ⇒ Boolean
- #validate! ⇒ Object
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
4 5 6 |
# File 'lib/itunes/receipt/response.rb', line 4 def data @data end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
4 5 6 |
# File 'lib/itunes/receipt/response.rb', line 4 def request @request end |
#response ⇒ Object (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_receipt ⇒ Object
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 |
#receipt ⇒ Object
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 |
#receipts ⇒ Object
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 |
#status ⇒ Object
45 46 47 |
# File 'lib/itunes/receipt/response.rb', line 45 def status @status ||= data['status'] end |
#valid? ⇒ Boolean
49 50 51 |
# File 'lib/itunes/receipt/response.rb', line 49 def valid? status == 0 end |