class Capistrano::Hook::Web

Attributes

headers[R]
http[R]
request[R]
uri[R]

Public Class Methods

client(url, headers = {}) click to toggle source
# File lib/capistrano/hook/web.rb, line 25
def self.client(url, headers = {})
  new(url, headers.is_a?(Hash) ? headers : {})
end
new(url, headers) click to toggle source
# File lib/capistrano/hook/web.rb, line 11
def initialize(url, headers)
  @uri     = URI.parse(url).freeze
  @headers = headers
  initialize_http
  initialize_request
end

Public Instance Methods

post(params) click to toggle source
# File lib/capistrano/hook/web.rb, line 18
def post(params)
  http.start do
    request.body = params.to_json
    http.request(request)
  end
end

Private Instance Methods

default_headers() click to toggle source
# File lib/capistrano/hook/web.rb, line 38
def default_headers
  { 'Content-Type' => 'application/json' }
end
initialize_http() click to toggle source
# File lib/capistrano/hook/web.rb, line 42
def initialize_http
  @http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = uri.is_a?(URI::HTTPS)
end
initialize_request() click to toggle source
# File lib/capistrano/hook/web.rb, line 47
def initialize_request
  @request = Net::HTTP::Post.new(path)
  request.initialize_http_header(default_headers.merge(headers))
end
path() click to toggle source
# File lib/capistrano/hook/web.rb, line 31
def path
  return '/' if uri.path.nil?
  return '/' if uri.path.empty?

  uri.path
end