Class: Tweetable::TwitterClient

Inherits:
Object
  • Object
show all
Defined in:
lib/tweetable/twitter_client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &block) ⇒ Object

Raises:



5
6
7
8
# File 'lib/tweetable/twitter_client.rb', line 5

def method_missing(sym, *args, &block)
  raise TweetableAuthError.new('Not authorized. You must login or authorize the client.') if @client.nil?
  @client.send sym, *args, &block
end

Instance Attribute Details

#authorizationObject

:oauth_access_token, :oauth_access_secret



3
4
5
# File 'lib/tweetable/twitter_client.rb', line 3

def authorization
  @authorization
end

#consumer_secretObject

:oauth_access_token, :oauth_access_secret



3
4
5
# File 'lib/tweetable/twitter_client.rb', line 3

def consumer_secret
  @consumer_secret
end

#consumer_tokenObject

:oauth_access_token, :oauth_access_secret



3
4
5
# File 'lib/tweetable/twitter_client.rb', line 3

def consumer_token
  @consumer_token
end

Instance Method Details

#authorize(token, secret, authorization) ⇒ Object

Raises:



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/tweetable/twitter_client.rb', line 10

def authorize(token, secret, authorization)
  raise TweetableAuthError if authorization.nil?
  
  self.authorization = authorization
  self.consumer_token = token
  self.consumer_secret = secret      
  self.oauth.authorize_from_access(self.authorization.oauth_access_token, self.authorization.oauth_access_secret)
        
  @client = Twitter::Base.new(self.oauth)
  self
end

#login(username, password) ⇒ Object



22
23
24
25
# File 'lib/tweetable/twitter_client.rb', line 22

def (username, password)
  @client = Twitter::Base.new(Twitter::HTTPAuth.new(username, password))
  self
end

#oauthObject



27
28
29
# File 'lib/tweetable/twitter_client.rb', line 27

def oauth      
  @oauth ||= Twitter::OAuth.new(self.consumer_token, self.consumer_secret)      
end

#statusObject



31
32
33
34
# File 'lib/tweetable/twitter_client.rb', line 31

def status
  status = self.rate_limit_status
  {:hourly_limit => status[:hourly_limit], :remaining_hits => status[:remaining_hits], :reset_time => status[:reset_time], :reset_time_in_seconds => status[:reset_time_in_seconds]}
end