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)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from Base

authenticate

Constructor Details

- (GiftCard) initialize(attributes = {})

Create a new CloudApp::GiftCard object.

Only used internally

Parameters:



51
52
53
# File 'lib/cloudapp/gift_card.rb', line 51

def initialize(attributes = {})
  load(attributes)
end

Instance Attribute Details

- (Object) code (readonly)

Returns the value of attribute code



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

def code
  @code
end

- (Object) created_at (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

- (Object) effective_at (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

- (Object) expires_at (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

- (Object) href (readonly)

Returns the value of attribute href



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

def href
  @href
end

- (Object) id (readonly)

Returns the value of attribute id



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

def id
  @id
end

- (Object) months (readonly)

Returns the value of attribute months



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

def months
  @months
end

- (Object) plan (readonly)

Returns the value of attribute plan



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

def plan
  @plan
end

- (Object) redeemed_at (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

- (Object) updated_at (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

+ (CloudApp::GiftCard) find(code)

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) : res
end

+ (CloudApp::GiftCard) redeem(code)

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}", :digest_auth => @@auth
  res.ok? ? GiftCard.new(res) : res
end

Instance Method Details

- (CloudApp::GiftCard) redeem

Apply the gift card to the authenticated account.

Returns:



58
59
60
# File 'lib/cloudapp/gift_card.rb', line 58

def redeem
  self.class.redeem code
end