Class: CandyCheck::AppStore::ReceiptCollection

Inherits:
Object
  • Object
show all
Defined in:
lib/candy_check/app_store/receipt_collection.rb

Overview

Store multiple Receipts in order to perform collective operation on them

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ ReceiptCollection

Initializes a new instance which bases on a JSON result from Apple’s verification server

Parameters:

  • attributes (Array<Hash>)

    raw data from Apple’s server



12
13
14
15
16
# File 'lib/candy_check/app_store/receipt_collection.rb', line 12

def initialize(attributes)
  @receipts = attributes.map { |r| Receipt.new(r) }.sort do |a, b|
    a.purchase_date - b.purchase_date
  end
end

Instance Attribute Details

#receiptsArray<Receipt> (readonly)

Multiple receipts as in verfication response

Returns:



7
8
9
# File 'lib/candy_check/app_store/receipt_collection.rb', line 7

def receipts
  @receipts
end

Instance Method Details

#expired?bool

Check if the latest expiration date is passed

Returns:

  • (bool)


20
21
22
# File 'lib/candy_check/app_store/receipt_collection.rb', line 20

def expired?
  expires_at.to_time <= Time.now.utc
end

#expires_atDateTime

Get latest expiration date

Returns:

  • (DateTime)


32
33
34
# File 'lib/candy_check/app_store/receipt_collection.rb', line 32

def expires_at
  @receipts.last.expires_date
end

#overdue_daysInteger

Get number of overdue days. If this is negative, it is not overdue.

Returns:

  • (Integer)


38
39
40
# File 'lib/candy_check/app_store/receipt_collection.rb', line 38

def overdue_days
  (Date.today - expires_at.to_date).to_i
end

#trial?bool

Check if in trial

Returns:

  • (bool)


26
27
28
# File 'lib/candy_check/app_store/receipt_collection.rb', line 26

def trial?
  @receipts.last.is_trial_period
end