Class: Ubiquitously::Service::Account

Inherits:
Base show all
Includes:
Account::Authorizable, Account::Loggable, Account::Restful
Defined in:
lib/ubiquitously/models/service/account.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Account::Authorizable

included

Methods included from Account::Loggable

included

Methods included from Account::Restful

included

Methods inherited from Base

#apply, #debug?

Methods included from SubclassableCallbacks

included, override

Constructor Details

#initialize(attributes = {}) ⇒ Account

Returns a new instance of Account.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/ubiquitously/models/service/account.rb', line 13

def initialize(attributes = {})
  attributes = attributes.symbolize_keys
  
  attributes[:username] = Ubiquitously.key("#{service}.key") if attributes[:username].blank?
  attributes[:password] = Ubiquitously.key("#{service}.secret") if attributes[:password].blank?
  
  if attributes[:username].blank? || attributes[:password].blank?
    raise "Where is the username and password for #{service}?"
  end
  
  @logged_in = false
  
  apply attributes
end

Instance Attribute Details

#credentialsObject

Returns the value of attribute credentials.



10
11
12
# File 'lib/ubiquitously/models/service/account.rb', line 10

def credentials
  @credentials
end

#ipObject

Returns the value of attribute ip.



11
12
13
# File 'lib/ubiquitously/models/service/account.rb', line 11

def ip
  @ip
end

#logged_inObject

Returns the value of attribute logged_in.



11
12
13
# File 'lib/ubiquitously/models/service/account.rb', line 11

def logged_in
  @logged_in
end

#passwordObject

Returns the value of attribute password.



10
11
12
# File 'lib/ubiquitously/models/service/account.rb', line 10

def password
  @password
end

#userObject

Returns the value of attribute user.



11
12
13
# File 'lib/ubiquitously/models/service/account.rb', line 11

def user
  @user
end

#usernameObject

Returns the value of attribute username.



10
11
12
# File 'lib/ubiquitously/models/service/account.rb', line 10

def username
  @username
end

Instance Method Details

#access_tokenObject



44
45
46
47
48
49
50
51
52
53
# File 'lib/ubiquitously/models/service/account.rb', line 44

def access_token
  if uses?(:oauth) && @access_token.blank?
    @access_token = "#{service.camelize}Token".constantize.new
    @access_token.token = credentials["token"]
    @access_token.secret = credentials["secret"]
    @access_token.key = credentials["key"]
  end
  
  @access_token
end

#agentObject



32
33
34
# File 'lib/ubiquitously/models/service/account.rb', line 32

def agent
  user.agent
end

#cookies?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/ubiquitously/models/service/account.rb', line 36

def cookies?
  user.cookies_for?(service)
end

#credentials?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/ubiquitously/models/service/account.rb', line 40

def credentials?
  !self.credentials.blank?
end