Class: PostCommit::Hooks::URL
Overview
To send an URL post commit, you have to set up your URL and, optionally, username and password.
post_commit :url do
post "http://example.com", :message => "Post commit"
end
If you need to authorize your request with basic auth, you can set your username and password.
post_commit :url do
:username => "johndoe", :password => "mypass"
post "http://example.com", :message => "Post commit"
end
Instance Attribute Summary
Attributes inherited from Base
#credentials, #request, #response, #uri
Instance Method Summary collapse
-
#post(url, params = {}) ⇒ Object
Post data to an arbitrary URL.
Methods inherited from Base
#authorize, inherited, #initialize
Constructor Details
This class inherits a constructor from PostCommit::Hooks::Base
Instance Method Details
#post(url, params = {}) ⇒ Object
Post data to an arbitrary URL. The data should a one-depth hash.
post "http://example.com", :message => "Post commit", :service => "yourapp"
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/post_commit/hooks/url.rb', line 19 def post(url, params = {}) @uri = URI.parse(url) http = Net::HTTP.new(uri.host, uri.port) @request = Net::HTTP::Post.new(uri.path) @request.basic_auth credentials[:username], credentials[:password] if credentials[:username] @request.form_data = params @response = http.request(@request) if response.code =~ /^2\d+/ true else false end rescue Exception false end |