Class: Twitter::Session

Inherits:
Object
  • Object
show all
Defined in:
lib/twitter/session.rb

Overview

Most of the logic in twitter-client lives in here. Responsible for maintaining/persisting credentials.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(username, password, opts = {}) ⇒ Session

Returns a new instance of Session.



8
9
10
11
# File 'lib/twitter/session.rb', line 8

def initialize(username, password, opts={})
  @username, @password = username, password
  @connection = opts[:connected] ? Connection.new(self) : nil
end

Instance Attribute Details

#filename=(value) ⇒ Object (writeonly)

Sets the attribute filename

Parameters:

  • value

    the value to set the attribute filename to.



6
7
8
# File 'lib/twitter/session.rb', line 6

def filename=(value)
  @filename = value
end

#passwordObject (readonly)

Returns the value of attribute password.



5
6
7
# File 'lib/twitter/session.rb', line 5

def password
  @password
end

#usernameObject (readonly)

Returns the value of attribute username.



5
6
7
# File 'lib/twitter/session.rb', line 5

def username
  @username
end

Instance Method Details

#==(other) ⇒ Object



32
33
34
# File 'lib/twitter/session.rb', line 32

def ==(other)
  [username, password] == [other.username, other.password]
end

#connect!Object

Ensure validity of credentials



21
22
23
# File 'lib/twitter/session.rb', line 21

def connect!
  connection(true)
end

#connected?Boolean

Provide verification that session is able to be used

Returns:

  • (Boolean)


26
27
28
29
30
# File 'lib/twitter/session.rb', line 26

def connected?
  if @connection
    true
  end
end

#tweet!(msg) ⇒ Object

Post a via the current session. TODO The Session class should be infrastructural. Domain logic like

this should go elsewhere.


16
17
18
# File 'lib/twitter/session.rb', line 16

def tweet!(msg)
  connection.post('/statuses/update', :status => msg) ; msg
end