class SocialCount::TwitterUser
Constants
- API_DOMAIN
- CONSUMER_OPTIONS
- USER_DOMAIN
Private Class Methods
access_token()
click to toggle source
# File lib/social_count/twitter_user.rb, line 33 def access_token @access_token ||= OAuth::AccessToken.from_hash(consumer, token_hash) end
consumer()
click to toggle source
# File lib/social_count/twitter_user.rb, line 37 def consumer @consumer ||= OAuth::Consumer.new(credentials.twitter_consumer_key, credentials.twitter_consumer_secret, CONSUMER_OPTIONS) end
token_hash()
click to toggle source
# File lib/social_count/twitter_user.rb, line 40 def token_hash @token_hash ||= { :oauth_token => credentials.twitter_oauth_token, :oauth_token_secret => credentials.twitter_oauth_token_secret } end
Public Instance Methods
follower_count()
click to toggle source
# File lib/social_count/twitter_user.rb, line 16 def follower_count return unless valid? response = self.class.access_token.request(:get, follower_count_url) response = JSON.parse(response.body) raise SocialCount::TwitterApiError.new("Twitter API returned the following errors: #{response["errors"]}", response["errors"].collect{|e| e["code"]}) if response["errors"] response["followers_count"] end
valid?()
click to toggle source
# File lib/social_count/twitter_user.rb, line 10 def valid? return @valid unless @valid.nil? url ="#{USER_DOMAIN}/#{name}" @valid = self.class.get_http_response(url).is_a?(Net::HTTPOK) end
Private Instance Methods
follower_count_url()
click to toggle source
# File lib/social_count/twitter_user.rb, line 25 def follower_count_url @follower_count_url ||= "#{API_DOMAIN}/1.1/users/show.json?screen_name=#{URI.escape(name_without_at)}" end
name_without_at()
click to toggle source
# File lib/social_count/twitter_user.rb, line 28 def name_without_at @name_without_at ||= '@' == name[0] ? name[1..-1] : name end