Class: Tuiter::Client

Inherits:
Object
  • Object
show all
Includes:
AccountMethods, DirectMessageMethods, FriendshipMethods, SocialGraphMethods, StatusMethods, UserMethods
Defined in:
lib/tuiter/client.rb

Instance Method Summary collapse

Methods included from AccountMethods

#account_rate_limit_status, #account_verify_credentials?

Methods included from SocialGraphMethods

#followers_ids, #friends_ids

Methods included from FriendshipMethods

#friendships_create, #friendships_destroy, #friendships_exists?

Methods included from DirectMessageMethods

#direct_messages, #direct_messages_new, #direct_messages_sent

Methods included from UserMethods

#statuses_followers, #statuses_friends, #users_show

Methods included from StatusMethods

#statuses_mentions, #statuses_show, #statuses_update

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/tuiter/client.rb', line 11

def initialize(options = {})
  @pid = Process.pid
  @logger = options[:logger] || Logger.new('tuiter.log')
  begin
    authentication_type = options.delete(:authentication)
    authentication_type = :basic if authentication_type.nil?
    @request_handler = Tuiter::Request.new(authentication_type, options)
  rescue
    return nil
  end
  log("initialize()")
end

Instance Method Details

#authorize(token, secret) ⇒ Object



28
29
30
# File 'lib/tuiter/client.rb', line 28

def authorize(token, secret)
  @request_handler.authorize(token, secret)
end

#authorized?Boolean

Returns:

  • (Boolean)


32
33
34
35
36
37
38
39
40
# File 'lib/tuiter/client.rb', line 32

def authorized?
  oauth_response = @request_handler.get('/account/verify_credentials.json')
  if oauth_response.class == Net::HTTPOK
    @username = JSON.parse(oauth_response.body)[:username]
    true
  else
    false
  end
end

#request_tokenObject



24
25
26
# File 'lib/tuiter/client.rb', line 24

def request_token
  @request_handler.request_token
end

#usernameObject



42
43
44
# File 'lib/tuiter/client.rb', line 42

def username
  @username ||= .screen_name
end