Method: Marshmallow::Connection#find_room_id_by_name

Defined in:
lib/god/contacts/hipchat.rb,
lib/god/contacts/campfire.rb

#find_room_id_by_name(room) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/god/contacts/hipchat.rb', line 29

def find_room_id_by_name(room_name)
  url = URI.parse("#{base_url}/list?format=json&auth_token=#{@options[:token]}")
  http = Net::HTTP.new(url.host, url.port)
  http.use_ssl = true if @options[:ssl]

  req = Net::HTTP::Get.new(url.request_uri)
  req.set_content_type('application/json')

  res = http.request(req)
  case res
    when Net::HTTPSuccess
      rooms = JSON.parse(res.body)
      room = rooms['rooms'].select { |x| x['name'] == room_name }
      rooms.empty? ? nil : room.first['room_id'].to_i
    else
      raise res.error!
  end
end