Class: Docs::Request

Inherits:
Typhoeus::Request
  • Object
show all
Includes:
Instrumentable
Defined in:
lib/docs/core/request.rb

Constant Summary collapse

DEFAULT_OPTIONS =
{
  followlocation: true,
  headers: { 'User-Agent' => 'devdocs.io' }
}

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Instrumentable

extended, included

Constructor Details

#initialize(url, options = {}) ⇒ Request


16
17
18
# File 'lib/docs/core/request.rb', line 16

def initialize(url, options = {})
  super url.to_s, DEFAULT_OPTIONS.merge(options)
end

Class Method Details

.run(*args, &block) ⇒ Object


10
11
12
13
14
# File 'lib/docs/core/request.rb', line 10

def self.run(*args, &block)
  request = new(*args)
  request.on_complete(&block) if block
  request.run
end

Instance Method Details

#response=(value) ⇒ Object


20
21
22
23
# File 'lib/docs/core/request.rb', line 20

def response=(value)
  value.extend Response if value
  super
end

#runObject


25
26
27
28
29
30
31
# File 'lib/docs/core/request.rb', line 25

def run
  instrument 'response.request', url: base_url do |payload|
    response = super
    payload[:response] = response
    response
  end
end