Sha256: 7c260029352d27ee51b72fdc8828f67b47025e0bc3dde769f50dfd35b735f23f
Contents?: true
Size: 1.96 KB
Versions: 4
Compression:
Stored size: 1.96 KB
Contents
require 'net/http' require 'outpost/expectations' module Outpost module Scouts # Uses ruby's own Net:HTTP to send HTTP requests and evaluate response # body, response time and response code. # # * Responds to response_time expectation # ({Outpost::Expectations::ResponseTime}) # * Responds to response_code expectation # ({Outpost::Expectations::ResponseCode}) # * Responds to response_body expectation # ({Outpost::Expectations::ResponseBody}) # class Http < Outpost::Scout extend Outpost::Expectations::ResponseCode extend Outpost::Expectations::ResponseBody extend Outpost::Expectations::ResponseTime attr_reader :response_code, :response_body, :response_time report_data :response_code, :response_body, :response_time # Configure the scout with given options. # @param [Hash] Options to setup the scout # @option options [String] :host The host that will be connected to. # @option options [Number] :port The port that will be used to. # @option options [String] :path The path that will be fetched from the # host. # @option options [String] :http_class The class that will be used to # fetch the page, defaults to Net::HTTP def setup(options) @host = options[:host] @port = options[:port] || 80 @path = options[:path] || '/' @http_class = options[:http_class] || Net::HTTP end # Runs the scout, connecting to the host and getting the response code, # body and time. def execute previous_time = Time.now response = @http_class.get_response(@host, @path, @port) @response_time = (Time.now - previous_time) * 1000 # Miliseconds @response_code = response.code.to_i @response_body = response.body rescue SocketError, Errno::ECONNREFUSED @response_code = @response_body = @response_time = nil end end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
outpost-0.2.4 | lib/outpost/scouts/http.rb |
outpost-0.2.3 | lib/outpost/scouts/http.rb |
outpost-0.2.2 | lib/outpost/scouts/http.rb |
outpost-0.2.1 | lib/outpost/scouts/http.rb |