Class: Twitter::Session
- Inherits:
-
Object
- Object
- Twitter::Session
- 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
-
#filename ⇒ Object
writeonly
Sets the attribute filename.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#connect! ⇒ Object
Ensure validity of credentials.
-
#connected? ⇒ Boolean
Provide verification that session is able to be used.
-
#initialize(username, password, opts = {}) ⇒ Session
constructor
A new instance of Session.
-
#tweet!(msg) ⇒ Object
Post a via the current session.
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
6 7 8 |
# File 'lib/twitter/session.rb', line 6 def filename=(value) @filename = value end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
5 6 7 |
# File 'lib/twitter/session.rb', line 5 def password @password end |
#username ⇒ Object (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
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 |