Module: Ubiquitously::Account::Authorizable::InstanceMethods

Defined in:
lib/ubiquitously/models/service/account/authorizable.rb

Instance Method Summary collapse

Instance Method Details

#authorize(condition) ⇒ Object



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

def authorize(condition)
  @logged_in = !!condition
end

#authorize!(condition) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/ubiquitously/models/service/account/authorizable.rb', line 23

def authorize!(condition)
  authorize(condition)
  
  unless logged_in?
    raise AuthenticationError.new("Invalid username or password for #{service.titleize}")
  end
  
  logged_in?
end

#authorized?Boolean

Returns:

  • (Boolean)


49
50
51
52
53
# File 'lib/ubiquitously/models/service/account/authorizable.rb', line 49

def authorized?
  return true if logged_in?
  return (credentials? && cookies?) if requires_credentials?
  return cookies?
end

#logged_in?Boolean

Returns:

  • (Boolean)


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

def logged_in?
  @logged_in == true
end

#requires_credentials?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/ubiquitously/models/service/account/authorizable.rb', line 45

def requires_credentials?
  uses?(:oauth)
end

#uses?(protocol) ⇒ Boolean

Returns:

  • (Boolean)


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

def uses?(protocol)
  self.class.uses?(protocol)
end