Class: Smackr::Chat

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

Defined Under Namespace

Classes: MessageReceiver

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Chat

Returns a new instance of Chat.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/smackr/chat.rb', line 7

def initialize(opts={})
  unless opts[:chat_manager]
    raise ArgumentError, ":chat_manager is required"
  end
  unless opts[:target]
    raise ArgumentError, ':target is required'
  end

  @chat_manager = opts[:chat_manager]
  @message_callback = opts[:message_callback]
  self.messages = []
  @chat = self.chat_manager.create_chat(opts[:target],
                                        MessageReceiver.new(:chat => self))
end

Instance Attribute Details

#chatObject (readonly)

Returns the value of attribute chat.



3
4
5
# File 'lib/smackr/chat.rb', line 3

def chat
  @chat
end

#chat_managerObject (readonly)

Returns the value of attribute chat_manager.



3
4
5
# File 'lib/smackr/chat.rb', line 3

def chat_manager
  @chat_manager
end

#message_callbackObject

Returns the value of attribute message_callback.



4
5
6
# File 'lib/smackr/chat.rb', line 4

def message_callback
  @message_callback
end

#messagesObject

Returns the value of attribute messages.



5
6
7
# File 'lib/smackr/chat.rb', line 5

def messages
  @messages
end

Instance Method Details

#send_message(msg) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/smackr/chat.rb', line 22

def send_message(msg)
  if msg.is_a?(String)
    self.chat.send_message(msg)
  else #TODO take a proper Message object instead of just the message body
    raise Exception, "NOT IMPLEMENTED, SUCKA"
  end
end