Sha256: a8139c7efa5379bd0667b37669303d14cd78eff0dbd4ff049de68b6aecbb9572

Contents?: true

Size: 1.57 KB

Versions: 1

Compression:

Stored size: 1.57 KB

Contents

Dir["#{File.dirname(__FILE__)}/account/*"].each { |c| require c unless File.directory?(c) }

module Ubiquitously
  module Service
    class Account < Ubiquitously::Base
      include Ubiquitously::Account::Restful
      include Ubiquitously::Account::Loggable
      include Ubiquitously::Account::Authorizable
      
      attr_accessor :username, :password, :credentials
      attr_accessor :logged_in, :ip, :user
      
      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
      
      def credentials
        @credentials ||= {}
      end
      
      def agent
        user.agent
      end
      
      def cookies?
        user.cookies_for?(service)
      end
      
      def credentials?
        !self.credentials.blank?
      end
      
      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
      
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ubiquitously-0.1.0 lib/ubiquitously/models/service/account.rb