Class: SocialCount::TwitterUser

Inherits:
ApiBase
  • Object
show all
Defined in:
lib/social_count/twitter_user.rb

Constant Summary collapse

API_DOMAIN =
"https://api.twitter.com"
USER_DOMAIN =
"https://twitter.com"
CONSUMER_OPTIONS =
{ :site => API_DOMAIN, :scheme => :header }

Instance Attribute Summary

Attributes inherited from ApiBase

#name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApiBase

get_http_response, #initialize

Constructor Details

This class inherits a constructor from SocialCount::ApiBase

Class Method Details

.access_tokenObject



33
34
35
# File 'lib/social_count/twitter_user.rb', line 33

def access_token
  @access_token ||= OAuth::AccessToken.from_hash(consumer, token_hash)
end

Instance Method Details

#follower_countObject



16
17
18
19
20
21
22
# 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?Boolean

Returns:

  • (Boolean)


10
11
12
13
14
# 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