Skip to content

Instantly share code, notes, and snippets.

@mperham
Created September 7, 2012 16:20
Show Gist options
  • Select an option

  • Save mperham/3667520 to your computer and use it in GitHub Desktop.

Select an option

Save mperham/3667520 to your computer and use it in GitHub Desktop.
Campfire in 10 lines
##
# Broadcast a message to Campfire
#
# campfire = Campfire.new(options)
# campfire.say("#{self.class.name} finished successfully!")
# campfire.say("trombone", :Sound)
#
def say(msg, type=:Text)
http = Net::HTTP.new("#{options[:subdomain]}.campfirenow.com", 443)
http.use_ssl = true
request = Net::HTTP::Post.new("/room/#{options[:roomid]}/speak.json")
request['Content-Type'] = 'application/json'
request.basic_auth options[:token], 'X'
request.body = Sidekiq.dump_json({:message => {:body => msg, :type => "#{type}Message"}})
response = http.request(request)
raise response.inspect if response.code != "201"
msg
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment