Sha256: 2f9ef39635a2f2c40ea11b367dc35404fb08822988d2f8480d5d23b27ba70672

Contents?: true

Size: 1.65 KB

Versions: 2

Compression:

Stored size: 1.65 KB

Contents

module TwitterAuth
  class GenericUser < ActiveRecord::Base
    attr_protected :login

    TWITTER_ATTRIBUTES = [
      :name,
      :location,
      :description,
      :profile_image_url,
      :url,
      :protected,
      :profile_background_color,
      :profile_sidebar_fill_color,
      :profile_link_color,
      :profile_sidebar_border_color,
      :profile_text_color,
      :friends_count,
      :statuses_count,
      :followers_count,      
      :favourites_count,
      :time_zone,
      :utc_offset
    ]
    
    validates_presence_of :login
    validates_format_of :login, :with => /\A[a-z0-9_]+\z/i
    validates_length_of :login, :in => 1..15
    validates_uniqueness_of :login, :case_sensitive => false
    
    def self.table_name; 'users' end

    def self.new_from_twitter_hash(hash)
      raise ArgumentError, 'Invalid hash: must include screen_name.' unless hash.key?('screen_name')

      user = User.new
      user.login = hash['screen_name']

      TWITTER_ATTRIBUTES.each do |att|
        user.send("#{att}=", hash[att.to_s]) if user.respond_to?("#{att}=")
      end

      user
    end
      
    def assign_twitter_attributes(hash)
      TWITTER_ATTRIBUTES.each do |att|
        send("#{att}=", hash[att.to_s]) if respond_to?("#{att}=")
      end
    end

    def update_twitter_attributes(hash)
      assign_twitter_attributes(hash)
      save
    end

    if TwitterAuth.oauth?
      include TwitterAuth::OauthUser
    else
      include TwitterAuth::BasicUser
    end

    def twitter
      if TwitterAuth.oauth?
        TwitterAuth::Dispatcher::Oauth.new(self)
      else
        TwitterAuth::Dispatcher::Basic.new(self)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
mbleigh-twitter-auth-0.1.8 app/models/twitter_auth/generic_user.rb
twitter-auth-0.1.8 app/models/twitter_auth/generic_user.rb