Class: HipChatCli::Message

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

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Message

Returns a new instance of Message.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/hip_chat_cli/message.rb', line 5

def initialize(params)

  %w(token room).each do |key|
    raise OptionParser::MissingArgument, "#{key} is a required option" if params[key.to_sym].nil?
  end

  @room     = params[:room]
  @notify   = params[:notify]   || false
  @format   = params[:format]   || 'html'
  @color    = params[:color]    || 'yellow'
  @username = params[:username] || 'API'

  @client = HipChat::Client.new(params[:token])
end

Instance Method Details

#deliver(message) ⇒ Object

Raises:

  • (OptionParser::MissingArgument)


20
21
22
23
24
25
26
27
28
29
30
# File 'lib/hip_chat_cli/message.rb', line 20

def deliver(message)

  raise OptionParser::MissingArgument, "message is required" if message.nil? || message == ''

  @client[@room].send(@username, message, {
      :notify => @notify,
      :message_format => @format,
      :color => @color
    }
  )
end