Class: Campfire::Bot

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

Instance Method Summary collapse

Constructor Details

#initializeBot

Returns a new instance of Bot.



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/pagerduty_tools/campfire.rb', line 41

def initialize
  # TODO: make sure that the file is there and that all the keys are, too.
  config = YAML.load_file(File.expand_path(CONFIG_FILE))
  @uri   = URI.parse config["site"]
  @room  = config["room"]
  @token = config["token"]
  @pass  = 'x'

  @http             = Net::HTTP.new(@uri.host, @uri.port)
  @http.use_ssl     = true
  @http.ca_file     = File.expand_path(CA_FILE)
  @http.verify_mode = OpenSSL::SSL::VERIFY_PEER
end

Instance Method Details

#paste(body) ⇒ Object



65
66
67
68
69
70
71
72
73
74
# File 'lib/pagerduty_tools/campfire.rb', line 65

def paste(body)
  request = Net::HTTP::Post.new("/room/#{@room}/speak.xml")
  message = Nokogiri::XML::Builder.new do |xml|
    xml.message {
      xml.type_ "PasteMessage"
      xml.body body
    }
  end
  return do_request(request, message.to_xml)
end

#topic(topic) ⇒ Object



55
56
57
58
59
60
61
62
63
# File 'lib/pagerduty_tools/campfire.rb', line 55

def topic(topic)
  request = Net::HTTP::Put.new "/room/#{@room}.xml"
  message = Nokogiri::XML::Builder.new do |xml|
    xml.room {
      xml.topic topic
    }
  end
  return do_request(request, message.to_xml)
end