Class: PostCommit::Hooks::Basecamp
- Defined in:
- lib/post_commit/hooks/basecamp.rb
Overview
To send a Basecamp post commit, you have to setup your subdomain, API token and project.
post_commit :basecamp do
:subdomain => "mycompany", :token => "TVfD8rB0x1sze8nZ4P1vaO5wOWM", :project => 666, :ssl => true
post "Some title", "Some message"
end
Instance Attribute Summary
Attributes inherited from Base
#credentials, #options, #request, #response, #uri
Instance Method Summary collapse
-
#post(title, message) ⇒ Object
Post message to Basecamp.
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(title, message) ⇒ Object
Post message to Basecamp.
post "Some title", "Some message"
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/post_commit/hooks/basecamp.rb', line 14 def post(title, ) protocol = credentials[:ssl] ? "https" : "http" @uri = URI.parse("#{protocol}://#{credentials[:subdomain]}.basecamphq.com/projects/#{credentials[:project]}/posts.xml") 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/xml" @request.body = " <post>\n <title><![CDATA[\#{title}]]></title>\n <body><![CDATA[\#{message}]]></body>\n </post>\n TXT\n\n @response = http.request(@request)\n\n if @response.code == \"201\"\n true\n else\n false\n end\nrescue Exception\n false\nend\n" |