Sha256: bf49893a3452dffa650fafffc1cb9cf3fd91b15e8cdd9cff6b1c6b5c6925eb2f

Contents?: true

Size: 925 Bytes

Versions: 6

Compression:

Stored size: 925 Bytes

Contents

require 'net/http'
require 'openssl'
require 'benchmark'

module Chicanery
  class Site
    attr_reader :name, :uri, :options, :body, :code, :duration

    def initialize name, url, options={}
      @name, @uri, @options = name, URI(url), options
    end

    def path
      uri.query ? "#{uri.path}?#{uri.query}" : uri.path
    end

    def get
      req = Net::HTTP::Get.new path
      req.basic_auth options[:user], options[:password] if options[:user] and options[:password]
      http_opts = { use_ssl: uri.scheme == 'https' }
      http_opts[:verify_mode] = OpenSSL::SSL::VERIFY_NONE unless options[:verify_ssl]
      start = Time.now
      res = Net::HTTP.start uri.host, uri.port, http_opts do |https|
        https.request req
      end
      @duration, @code, @body = (Time.now - start), res.code, res.body
      res.value #check for success via a spectactularly poorly named method
      res.body
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
chicanery-0.2.0 lib/chicanery/site.rb
chicanery-0.1.9 lib/chicanery/site.rb
chicanery-0.1.8 lib/chicanery/site.rb
chicanery-0.1.7 lib/chicanery/site.rb
chicanery-0.1.6 lib/chicanery/site.rb
chicanery-0.1.5 lib/chicanery/site.rb