mirror of
https://github.com/freeCodeCamp/devdocs
synced 2024-11-16 19:48:10 +01:00
33 lines
676 B
Ruby
33 lines
676 B
Ruby
module Docs
|
|
class Request < Typhoeus::Request
|
|
include Instrumentable
|
|
|
|
DEFAULT_OPTIONS = {
|
|
followlocation: true,
|
|
headers: { 'User-Agent' => 'DevDocs' }
|
|
}
|
|
|
|
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
|