Class: CloudApp::Account

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

Overview

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

Examples:

Create a CloudApp account

CloudApp::Account.create :email => "arthur@dent.com", :password => "towel"

Most other account actions require authentication first

CloudApp.authenticate "username", "password"

Usage via the Account class

# View account details
@account = CloudApp::Account.find

# Change default security
CloudApp::Account.update :private_items => false

# Change email
CloudApp::Account.update :email => "ford@prefect.com", :current_password => "towel"

# Change password
CloudApp::Account.update :password => "happy frood", :current_password => "towel"

# Set custom domain
CloudApp::Account.update :domain => "dent.com", :domain_home_page => "http://hhgproject.org"

# Forgot password
CloudApp::Account.reset :email => "arthur@dent.com"

# View account stats
CloudApp::Account.stats

Usage via the class instance

# Change default security
@account.update :private_items => false

# Change email
@account.update :email => "ford@prefect.com", :current_password => "towel"

# Change password
@account.update :password => "happy frood", :current_password => "towel"

# Set custom domain
@account.update :domain => "dent.com", :domain_home_page => "http://hhgproject.org"

# Forgot password
@account.reset

# View account stats
@account.stats

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from Base

authenticate

Constructor Details

- (Account) initialize(attributes = {})

Create a new CloudApp::Account object.

Only used internally

Parameters:



126
127
128
# File 'lib/cloudapp/account.rb', line 126

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

Instance Attribute Details

- (Object) activated_at (readonly)

Returns the value of attribute activated_at



117
118
119
# File 'lib/cloudapp/account.rb', line 117

def activated_at
  @activated_at
end

- (Object) alpha (readonly)

Returns the value of attribute alpha



117
118
119
# File 'lib/cloudapp/account.rb', line 117

def alpha
  @alpha
end

- (Object) created_at (readonly)

Returns the value of attribute created_at



117
118
119
# File 'lib/cloudapp/account.rb', line 117

def created_at
  @created_at
end

- (Object) domain (readonly)

Returns the value of attribute domain



117
118
119
# File 'lib/cloudapp/account.rb', line 117

def domain
  @domain
end

- (Object) domain_home_page (readonly)

Returns the value of attribute domain_home_page



117
118
119
# File 'lib/cloudapp/account.rb', line 117

def domain_home_page
  @domain_home_page
end

- (Object) email (readonly)

Returns the value of attribute email



117
118
119
# File 'lib/cloudapp/account.rb', line 117

def email
  @email
end

- (Object) id (readonly)

Returns the value of attribute id



117
118
119
# File 'lib/cloudapp/account.rb', line 117

def id
  @id
end

- (Object) private_items (readonly)

Returns the value of attribute private_items



117
118
119
# File 'lib/cloudapp/account.rb', line 117

def private_items
  @private_items
end

- (Object) subscribed (readonly)

Returns the value of attribute subscribed



117
118
119
# File 'lib/cloudapp/account.rb', line 117

def subscribed
  @subscribed
end

- (Object) updated_at (readonly)

Returns the value of attribute updated_at



117
118
119
# File 'lib/cloudapp/account.rb', line 117

def updated_at
  @updated_at
end

Class Method Details

+ (CloudApp::Account) create(opts = {})

Create a CloudApp account.

Parameters:

  • opts (Hash) (defaults to: {})

    options parameters

Options Hash (opts):

  • :email (String)

    Account email address

  • :password (String)

    Account password

  • :accept_tos (Boolean)

    Accept CloudApp terms of service

Returns:



71
72
73
74
# File 'lib/cloudapp/account.rb', line 71

def self.create(opts = {})
  res = post "/register", :body => {:user => opts}
  res.ok? ? Account.new(res) : res
end

+ (CloudApp::Account) find

Get the basic details of the authenticated account.

Requires authentication.

Returns:



59
60
61
62
# File 'lib/cloudapp/account.rb', line 59

def self.find
  res = get "/account", :digest_auth => @@auth
  res.ok? ? Account.new(res) : res
end

+ (Boolean) reset(opts = {})

Dispatch an email containing a link to reset the account's password.

Parameters:

  • opts (Hash) (defaults to: {})

    options parameters

Options Hash (opts):

  • :email (String)

    Account email address

Returns:

  • (Boolean)


102
103
104
105
# File 'lib/cloudapp/account.rb', line 102

def self.reset(opts = {})
  res = post "/reset", :body => {:user => opts}
  res.ok? ? true : res
end

+ (Hash) stats

Get the total number of drops created and total views for all drops.

Requires authentication.

Returns:



112
113
114
115
# File 'lib/cloudapp/account.rb', line 112

def self.stats
  res = get "/account/stats", :digest_auth => @@auth
  res.ok? ? res.symbolize_keys! : res
end

+ (CloudApp::Account) update(opts = {})

Modify the authenticated accounts details. Can change the default security of newly created drops, the accounts email address, password, and custom domain details.

Note that when changing email address or password, the current password is required. Also note that to change custom domains requires an account with a Pro subscription.

Requires authentication

Parameters:

  • opts (Hash) (defaults to: {})

    options parameters

Options Hash (opts):

  • :private_items (Boolean)

    Change default security of new drops

  • :email (String)

    Change email address

  • :password (String)

    Change password

  • :current_password (String)

    Current account password

  • :domain (String)

    Set custom domain

  • :domain_home_page (String)

    URL to redirect visitors to custom domain's root

Returns:



92
93
94
95
# File 'lib/cloudapp/account.rb', line 92

def self.update(opts = {})
  res = put "/account", {:body => {:user => opts}, :digest_auth => @@auth}
  res.ok? ? Account.new(res) : res
end

Instance Method Details

- (Boolean) reset

Dispatch an email containing a link to reset the account's password.

Parameters:

  • opts (Hash)

    options parameters

Returns:

  • (Boolean)


153
154
155
# File 'lib/cloudapp/account.rb', line 153

def reset
  self.class.reset :email => self.email
end

- (Hash) stats

Get the total number of drops created and total views for all drops.

Returns:



160
161
162
# File 'lib/cloudapp/account.rb', line 160

def stats
  self.class.stats
end

- (CloudApp::Account) update(opts = {})

Modify the authenticated accounts details. Can change the default security of newly created drops, the accounts email address, password, and custom domain details.

Note that when changing email address or password, the current password is required. Also note that to change custom domains requires an account with a Pro subscription.

Parameters:

  • opts (Hash) (defaults to: {})

    options parameters

Options Hash (opts):

  • :private_items (Boolean)

    Change default security of new drops

  • :email (String)

    Change email address

  • :password (String)

    Change password

  • :current_password (String)

    Current account password

  • :domain (String)

    Set custom domain

  • :domain_home_page (String)

    URL to redirect visitors to custom domain's root

Returns:



144
145
146
# File 'lib/cloudapp/account.rb', line 144

def update(opts = {})
  self.class.update opts
end