In Files

Parent

Included Modules

HipChat::Room

Public Class Methods

new(token, params) click to toggle source
# File lib/hipchat.rb, line 51
def initialize(token, params)
  @token = token

  super(params)
end

Public Instance Methods

history(options = {}) click to toggle source

Pull this room's history

Usage

# Default

Options

date

Whether to return a specific day (YYYY-MM-DD format) or recent

(default "recent")

timezone

Your timezone. Supported timezones are at: www.hipchat.com/docs/api/timezones

(default "UTC")

format

Format to retrieve the history in. Valid options are JSON and XML

(default "JSON")
# File lib/hipchat.rb, line 162
def history(options = {})

  options = { :date => 'recent', :timezone => 'UTC', :format => 'JSON' }.merge options

  response = self.class.get('/history',
    :query => {
      :room_id    => room_id,
      :date       => options[:date],
      :timezone   => options[:timezone],
      :format     => options[:format],
      :auth_token => @token,
    }
  )

  case response.code
  when 200
    response.body
  when 404
    raise UnknownRoom,  "Unknown room: `#{room_id}'"
  when 401
    raise Unauthorized, "Access denied to room `#{room_id}'"
  else
    raise UnknownResponseCode, "Unexpected #{response.code} for room `#{room_id}'"
  end
end
send(from, message, options_or_notify = {}) click to toggle source

Send a message to this room.

Usage:

# Default
send 'nickname', 'some message'

# Notify users and color the message red
send 'nickname', 'some message', :notify => true, :color => 'red'

# Notify users (deprecated)
send 'nickname', 'some message', true

Options:

color

"yellow", "red", "green", "purple", or "random" (default "yellow")

notify

true or false (default false)

# File lib/hipchat.rb, line 76
def send(from, message, options_or_notify = {})
  if from.length > 15
    raise UsernameTooLong, "Username #{from} is `#{from.length} characters long. Limit is 15'"
  end
  options = if options_or_notify == true or options_or_notify == false
    warn "DEPRECATED: Specify notify flag as an option (e.g., :notify => true)"
    { :notify => options_or_notify }
  else
    options_or_notify || {}
  end

  options = { :color => 'yellow', :notify => false }.merge options

  response = self.class.post('/message',
    :query => { :auth_token => @token },
    :body  => {
      :room_id        => room_id,
      :from           => from,
      :message        => message,
      :message_format => options[:message_format] || 'html',
      :color          => options[:color],
      :notify         => options[:notify] ? 1 : 0
    }
  )

  case response.code
  when 200; true
  when 404
    raise UnknownRoom,  "Unknown room: `#{room_id}'"
  when 401
    raise Unauthorized, "Access denied to room `#{room_id}'"
  else
    raise UnknownResponseCode, "Unexpected #{response.code} for room `#{room_id}'"
  end
end
topic(new_topic, options = {}) click to toggle source

Change this room's topic

Usage:

# Default
topic 'my awesome topic'

Options:

from

the name of the person changing the topic

(default "API")
# File lib/hipchat.rb, line 123
def topic(new_topic, options = {})

  options = { :from => 'API' }.merge options

  response = self.class.post('/topic',
    :query => { :auth_token => @token },
    :body  => {
      :room_id        => room_id,
      :from           => options[:from],
      :topic          => new_topic
    }
  )

  case response.code
  when 200; true
  when 404
    raise UnknownRoom,  "Unknown room: `#{room_id}'"
  when 401
    raise Unauthorized, "Access denied to room `#{room_id}'"
  else
    raise UnknownResponseCode, "Unexpected #{response.code} for room `#{room_id}'"
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.