You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
devdocs/lib/docs/core/request.rb

36 lines
699 B

11 years ago
require 'typhoeus'
module Docs
class Request < Typhoeus::Request
include Instrumentable
DEFAULT_OPTIONS = {
followlocation: true,
headers: { 'User-Agent' => 'devdocs.io' }
}
def self.run(*args, &block)
request = new(*args)
request.on_complete(&block) if block
request.run
end
def initialize(url, options = {})
super url.to_s, DEFAULT_OPTIONS.merge(options)
end
def response=(value)
value.extend Response if value
super
end
def run
instrument 'response.request', url: base_url do |payload|
response = super
payload[:response] = response
response
end
end
end
end