Class: PostCommit::Hooks::Campfire
- Defined in:
- lib/post_commit/hooks/campfire.rb
Overview
To send a Campifire post commit, you have to setup your subdomain, API token and room.
post_commit :campfire do
:subdomain => "mycompany", :token => "TVfD8rB0x1sze8nZ4P1vaO5wOWM", :room => 666, :ssl => true
post "Some message"
end
You can specify the message type. See PostCommit::Hooks::Campfire#post for usage.
Constant Summary collapse
- MESSAGE_TYPE =
{ :text => "TextMessage", :paste => "PasteMessage", :twitter => "TwitterMessage" }
Instance Attribute Summary
Attributes inherited from Base
#credentials, #options, #request, #response, #uri
Instance Method Summary collapse
-
#post(message, options = {}) ⇒ Object
Post message to Campfire.
Methods inherited from Base
#authorize, #convert_to_params, #convert_to_xml, inherited, #initialize, #set
Constructor Details
This class inherits a constructor from PostCommit::Hooks::Base
Instance Method Details
#post(message, options = {}) ⇒ Object
Post message to Campfire.
post "Hi Campfire!"
#=> send text message
post "Pasted code", :type => :paste
#=> formatted paste message with more link and scroll bar
post "http://twitter.com/dhh/status/9688523285", :type => :twitter
#=> display the specified Twitter status
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/post_commit/hooks/campfire.rb', line 28 def post(, = {}) = {:type => :text}.merge() protocol = credentials[:ssl] ? "https" : "http" @uri = URI.parse("#{protocol}://#{credentials[:subdomain]}.campfirenow.com/room/#{credentials[:room]}/speak.json") http = Net::HTTP.new(uri.host, uri.port) @request = Net::HTTP::Post.new(uri.path) @request.basic_auth credentials[:token], "x" @request.content_type = "application/json" @request.body = {:message => { :type => MESSAGE_TYPE[[:type].to_sym], :body => .to_s }}.to_json @response = http.request(@request) if @response.code == "201" JSON.parse response.body else false end rescue Exception false end |