Sha256: df2dc27d52ebb23441b041ca9fdbb17f5b2fdf47c5e655027a8098548daf15aa

Contents?: true

Size: 1.08 KB

Versions: 3

Compression:

Stored size: 1.08 KB

Contents

module CandyCheck
  module AppStore
    # Store multiple {Receipt}s in order to perform collective operation on them
    class ReceiptCollection
      # Multiple receipts as in verfication response
      # @return [Array<Receipt>]
      attr_reader :receipts

      # Initializes a new instance which bases on a JSON result
      # from Apple's verification server
      # @param attributes [Array<Hash>]
      def initialize(attributes)
        @receipts = attributes.map { |r| Receipt.new(r) }
      end

      # Check if the latest expiration date is passed
      # @return [bool]
      def expired?
        expires_at.to_time <= Time.now.utc
      end

      # Check if in trial
      # @return [bool]
      def trial?
        @receipts.last.is_trial_period
      end

      # Get latest expiration date
      # @return [DateTime]
      def expires_at
        @receipts.last.expires_date
      end

      # Get number of overdue days. If this is negative, it is not overdue.
      # @return [Integer]
      def overdue_days
        (Date.today - expires_at.to_date).to_i
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
candy_check-0.2.0 lib/candy_check/app_store/receipt_collection.rb
candy_check-0.1.2 lib/candy_check/app_store/receipt_collection.rb
candy_check-0.1.1 lib/candy_check/app_store/receipt_collection.rb