Class: AIM::User
- Inherits:
-
Object
- Object
- AIM::User
- Defined in:
- lib/aim.rb
Overview
represents an AIM User, initialized with a username and password
Instance Attribute Summary collapse
-
#password ⇒ Object
Returns the value of attribute password.
-
#username ⇒ Object
Returns the value of attribute username.
Instance Method Summary collapse
-
#clear_events! ⇒ Object
undoes all event subscriptions.
-
#im_user(screenname, message) ⇒ Object
user.im_user ‘bob’, “hi bob!”.
-
#initialize(username, password) ⇒ User
constructor
A new instance of User.
- #join_chatroom(room_name) ⇒ Object
-
#log_chatroom(room_name, options = { }) ⇒ Object
helper, will save all messages in a chatroom to a file, or in memory, or wherever.
- #login! ⇒ Object
-
#wait! ⇒ Object
tell the user to just chill! hang out and wait for events.
-
#when(event_name, &block) ⇒ Object
do something on an event.
Constructor Details
#initialize(username, password) ⇒ User
Returns a new instance of User.
62 63 64 |
# File 'lib/aim.rb', line 62 def initialize username, password @username, @password = username, password end |
Instance Attribute Details
#password ⇒ Object
Returns the value of attribute password.
60 61 62 |
# File 'lib/aim.rb', line 60 def password @password end |
#username ⇒ Object
Returns the value of attribute username.
60 61 62 |
# File 'lib/aim.rb', line 60 def username @username end |
Instance Method Details
#clear_events! ⇒ Object
undoes all event subscriptions
71 72 73 |
# File 'lib/aim.rb', line 71 def clear_events! connection.clear_callbacks! end |
#im_user(screenname, message) ⇒ Object
user.im_user ‘bob’, “hi bob!”
94 95 96 |
# File 'lib/aim.rb', line 94 def im_user screenname, connection.buddy_list.buddy_named(screenname).send_im() end |
#join_chatroom(room_name) ⇒ Object
118 119 120 |
# File 'lib/aim.rb', line 118 def join_chatroom room_name connection.join_chat room_name end |
#log_chatroom(room_name, options = { }) ⇒ Object
helper, will save all messages in a chatroom to a file, or in memory, or wherever
right now, usage is simply:
user.log_chatroom 'roomname', :output => 'filename.log'
104 105 106 107 108 109 110 111 |
# File 'lib/aim.rb', line 104 def log_chatroom room_name, = { } [:output] ||= "#{ room_name }.log" self.when :chat do |, buddy, room| File.open([:output], 'a'){|f| f << "#{ buddy.screen_name }: #{ message }\n" } end join_chatroom room_name end |
#login! ⇒ Object
66 67 68 |
# File 'lib/aim.rb', line 66 def login! connection.connect end |
#wait! ⇒ Object
tell the user to just chill! hang out and wait for events
114 115 116 |
# File 'lib/aim.rb', line 114 def wait! connection.wait end |
#when(event_name, &block) ⇒ Object
do something on an event
user.when :im do |message, buddy|
puts "message '#{message}' received from #{ buddy }"
end
user.when :error do |error|
...
end
user.when :chat do |message, buddy, room|
...
end
89 90 91 |
# File 'lib/aim.rb', line 89 def when event_name, &block connection.send "on_#{ event_name }", &block end |