Class: CloudApp::GiftCard

Inherits:
Base
  • Object
show all
Defined in:
lib/cloudapp/gift_card.rb

Overview

An ActiveResource-like interface through which to interract with CloudApp gift cards.

Examples:

Gets started by Authenticating

CloudApp.authenticate "username", "password"

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

Instance Attribute Summary collapse

Attributes inherited from Base

#data

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

authenticate, bad_response, #initialize

Constructor Details

This class inherits a constructor from CloudApp::Base

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



42
43
44
# File 'lib/cloudapp/gift_card.rb', line 42

def code
  @code
end

#created_atObject (readonly)

Returns the value of attribute created_at.



42
43
44
# File 'lib/cloudapp/gift_card.rb', line 42

def created_at
  @created_at
end

#effective_atObject (readonly)

Returns the value of attribute effective_at.



42
43
44
# File 'lib/cloudapp/gift_card.rb', line 42

def effective_at
  @effective_at
end

#expires_atObject (readonly)

Returns the value of attribute expires_at.



42
43
44
# File 'lib/cloudapp/gift_card.rb', line 42

def expires_at
  @expires_at
end

#hrefObject (readonly)

Returns the value of attribute href.



42
43
44
# File 'lib/cloudapp/gift_card.rb', line 42

def href
  @href
end

#idObject (readonly)

Returns the value of attribute id.



42
43
44
# File 'lib/cloudapp/gift_card.rb', line 42

def id
  @id
end

#monthsObject (readonly)

Returns the value of attribute months.



42
43
44
# File 'lib/cloudapp/gift_card.rb', line 42

def months
  @months
end

#planObject (readonly)

Returns the value of attribute plan.



42
43
44
# File 'lib/cloudapp/gift_card.rb', line 42

def plan
  @plan
end

#redeemed_atObject (readonly)

Returns the value of attribute redeemed_at.



42
43
44
# File 'lib/cloudapp/gift_card.rb', line 42

def redeemed_at
  @redeemed_at
end

#updated_atObject (readonly)

Returns the value of attribute updated_at.



42
43
44
# File 'lib/cloudapp/gift_card.rb', line 42

def updated_at
  @updated_at
end

Class Method Details

.find(code) ⇒ CloudApp::GiftCard

Get the details of an unredeemed gift card.

Requires authentication.

Parameters:

  • code (String)

    Gift card code

Returns:



26
27
28
29
# File 'lib/cloudapp/gift_card.rb', line 26

def self.find(code)
  res = get "/gift_cards/#{code}", :digest_auth => @@auth
  res.ok? ? GiftCard.new(res) : bad_response(res)
end

.redeem(code) ⇒ CloudApp::GiftCard

Apply a gift card to the authenticated account.

Requires authentication.

Parameters:

  • code (String)

    Gift card code

Returns:



37
38
39
40
# File 'lib/cloudapp/gift_card.rb', line 37

def self.redeem(code)
  res = put "/gift_cards/#{code}", {:body => {}, :digest_auth => @@auth}
  res.ok? ? GiftCard.new(res) : bad_response(res)
end

Instance Method Details

#redeemCloudApp::GiftCard

Apply the gift card to the authenticated account.

Returns:



48
49
50
# File 'lib/cloudapp/gift_card.rb', line 48

def redeem
  self.class.redeem code
end