Class: CandyCheck::AppStore::ReceiptCollection
- Inherits:
-
Object
- Object
- CandyCheck::AppStore::ReceiptCollection
- 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
-
#receipts ⇒ Array<Receipt>
readonly
Multiple receipts as in verfication response.
Instance Method Summary collapse
-
#expired? ⇒ bool
Check if the latest expiration date is passed.
-
#expires_at ⇒ DateTime
Get latest expiration date.
-
#initialize(attributes) ⇒ ReceiptCollection
constructor
Initializes a new instance which bases on a JSON result from Apple’s verification server.
-
#overdue_days ⇒ Integer
Get number of overdue days.
-
#trial? ⇒ bool
Check if in trial.
Constructor Details
#initialize(attributes) ⇒ ReceiptCollection
Initializes a new instance which bases on a JSON result from Apple’s verification 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
#receipts ⇒ Array<Receipt> (readonly)
Multiple receipts as in verfication response
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
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_at ⇒ DateTime
Get latest expiration date
32 33 34 |
# File 'lib/candy_check/app_store/receipt_collection.rb', line 32 def expires_at @receipts.last.expires_date end |
#overdue_days ⇒ Integer
Get number of overdue days. If this is negative, it is not overdue.
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
26 27 28 |
# File 'lib/candy_check/app_store/receipt_collection.rb', line 26 def trial? @receipts.last.is_trial_period end |