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 => "[email protected]", :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 => "[email protected]", :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 => "[email protected]"

# View account stats
CloudApp::Account.stats

Usage via the class instance

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

# Change email
@account.update :email => "[email protected]", :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

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

#activated_atObject (readonly)

Returns the value of attribute activated_at.



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

def activated_at
  @activated_at
end

#alphaObject (readonly)

Returns the value of attribute alpha.



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

def alpha
  @alpha
end

#created_atObject (readonly)

Returns the value of attribute created_at.



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

def created_at
  @created_at
end

#domainObject (readonly)

Returns the value of attribute domain.



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

def domain
  @domain
end

#domain_home_pageObject (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

#emailObject (readonly)

Returns the value of attribute email.



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

def email
  @email
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#private_itemsObject (readonly)

Returns the value of attribute private_items.



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

def private_items
  @private_items
end

#subscribedObject (readonly)

Returns the value of attribute subscribed.



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

def subscribed
  @subscribed
end

#subscription_expires_atObject (readonly)

Returns the value of attribute subscription_expires_at.



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

def subscription_expires_at
  @subscription_expires_at
end

#updated_atObject (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

.create(opts = {}) ⇒ CloudApp::Account

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

.findCloudApp::Account

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

.reset(opts = {}) ⇒ Boolean

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

.statsHash

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

.update(opts = {}) ⇒ CloudApp::Account

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

Instance Method Details

#resetBoolean

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

Parameters:

  • opts (Hash)

    options parameters

Returns:

  • (Boolean)


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

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

#statsHash

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

Returns:



151
152
153
# File 'lib/cloudapp/account.rb', line 151

def stats
  self.class.stats
end

#update(opts = {}) ⇒ CloudApp::Account

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:



135
136
137
# File 'lib/cloudapp/account.rb', line 135

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