class ActiveHook::Server::Send
Attributes
hook[RW]
response[R]
response_time[R]
status[R]
Public Class Methods
new(options = {})
click to toggle source
# File lib/activehook/server/send.rb, line 13 def initialize(options = {}) options.each { |key, value| send("#{key}=", value) } end
Public Instance Methods
start()
click to toggle source
# File lib/activehook/server/send.rb, line 17 def start @status = post_hook log_status end
success?()
click to toggle source
# File lib/activehook/server/send.rb, line 26 def success? @status == :success end
uri()
click to toggle source
# File lib/activehook/server/send.rb, line 22 def uri @uri ||= URI.parse(@hook.uri) end
Private Instance Methods
final_headers()
click to toggle source
# File lib/activehook/server/send.rb, line 69 def final_headers { "X-Hook-Signature" => @hook.signature }.merge(REQUEST_HEADERS) end
log_status()
click to toggle source
# File lib/activehook/server/send.rb, line 60 def log_status msg = "POST | #{uri} | #{status.upcase} #{response_time}" if status == :success ActiveHook.log.info(msg) else ActiveHook.log.err(msg) end end
measure_response_time() { || ... }
click to toggle source
# File lib/activehook/server/send.rb, line 42 def measure_response_time start = Time.now yield finish = Time.now @response_time = "| #{((finish - start) * 1000.0).round(3)} ms" end
post_hook()
click to toggle source
# File lib/activehook/server/send.rb, line 32 def post_hook http = Net::HTTP.new(uri.host, uri.port) measure_response_time do @response = http.post(uri.path, @hook.final_payload, final_headers) end response_status(@response) rescue :error end
response_status(response)
click to toggle source
# File lib/activehook/server/send.rb, line 49 def response_status(response) case response.code.to_i when (200..204) :success when (400..499) :bad_request when (500..599) :server_problems end end