Sha256: 464da2ffaaf3294acea05172430358d12b69ebdb5d61555867af3ed2934454f8

Contents?: true

Size: 1.42 KB

Versions: 6

Compression:

Stored size: 1.42 KB

Contents

module CloudApp
  
  # An ActiveResource-like interface through which to interract with CloudApp gift cards.
  #
  #
  # @example Gets started by Authenticating
  #   CloudApp.authenticate "username", "password"
  #
  # @example Usage via the GiftCard class
  #   # View gift card details
  #   @gift = CloudApp::GiftCard.find "ABC123"
  #   
  #   # Apply the gift card
  #   CloudApp::GiftCard.redeem "ABC123"
  #     # or
  #   @gift.redeem
  # 
  class GiftCard < Base
    
    # Get the details of an unredeemed gift card.
    #
    # Requires authentication.
    #
    # @param [String] code Gift card code
    # @return [CloudApp::GiftCard]
    def self.find(code)
      res = get "/gift_cards/#{code}", :digest_auth => @@auth
      res.ok? ? GiftCard.new(res) : bad_response(res)
    end
    
    # Apply a gift card to the authenticated account.
    #
    # Requires authentication.
    #
    # @param [String] code Gift card code
    # @return [CloudApp::GiftCard]
    def self.redeem(code)
      res = put "/gift_cards/#{code}", {:body => {}, :digest_auth => @@auth}
      res.ok? ? GiftCard.new(res) : bad_response(res)
    end
    
    attr_reader :id, :code, :plan, :months, :href,
                :created_at, :updated_at, :redeemed_at, :effective_at, :expires_at
        
    # Apply the gift card to the authenticated account.
    #
    # @return [CloudApp::GiftCard]
    def redeem
      self.class.redeem code
    end
    
  end
  
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
cloudapp_api-0.5.0 lib/cloudapp/gift_card.rb
cloudapp_api-0.4.0 lib/cloudapp/gift_card.rb
cloudapp_api-0.3.3 lib/cloudapp/gift_card.rb
cloudapp_api-0.3.2 lib/cloudapp/gift_card.rb
cloudapp_api-0.3.1 lib/cloudapp/gift_card.rb
cloudapp_api-0.3.0 lib/cloudapp/gift_card.rb