Class: TypePadTemplate::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/type_pad_template/request.rb

Constant Summary collapse

DEFAULT_HOST_NAME =
"www.typepad.com"
MAX_CONCURRENCY =
10

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Request.



14
15
16
17
# File 'lib/type_pad_template/request.rb', line 14

def initialize(url_or_path, options = {})
  @url_or_path = url_or_path
  @options = options
end

Class Method Details

.dispatchObject



6
7
8
# File 'lib/type_pad_template/request.rb', line 6

def self.dispatch
  hydra.run
end

.hydraObject



10
11
12
# File 'lib/type_pad_template/request.rb', line 10

def self.hydra
  @@hydra ||= Typhoeus::Hydra.new(:max_concurrency => MAX_CONCURRENCY)
end

Instance Method Details

#dispatchObject



27
28
29
30
31
32
# File 'lib/type_pad_template/request.rb', line 27

def dispatch
  hydra = Typhoeus::Hydra.new
  hydra.queue(request)
  hydra.run
  self
end

#enqueue(&block) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/type_pad_template/request.rb', line 19

def enqueue(&block)
  request.on_complete = lambda do |response|
    block.call(Response.new(response))
  end
  self.class.hydra.queue(request)
  self
end

#responseObject



34
35
36
# File 'lib/type_pad_template/request.rb', line 34

def response
  @response ||= Response.new(request.response) if request.response
end