Class: AIM::User

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

Overview

represents an AIM User, initialized with a username and password

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#passwordObject

Returns the value of attribute password.



60
61
62
# File 'lib/aim.rb', line 60

def password
  @password
end

#usernameObject

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, message
  connection.buddy_list.buddy_named(screenname).send_im(message)
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, options = { }
  options[:output] ||= "#{ room_name }.log"
  self.when :chat do |message, buddy, room|
    File.open(options[: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