Class: Slash::TyphoeusConnection
- Inherits:
-
Connection
- Object
- Connection
- Slash::TyphoeusConnection
- Defined in:
- lib/slash/typhoeus.rb
Instance Attribute Summary collapse
-
#queue ⇒ Object
Returns the value of attribute queue.
Attributes inherited from Connection
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ TyphoeusConnection
constructor
A new instance of TyphoeusConnection.
- #request(method, uri, options = {}) ⇒ Object
Methods inherited from Connection
create_default, #delete, #get, #head, #post, #put
Constructor Details
#initialize(options = {}) ⇒ TyphoeusConnection
Returns a new instance of TyphoeusConnection.
31 32 33 |
# File 'lib/slash/typhoeus.rb', line 31 def initialize( = {}) @queue = [:queue] || TyphoeusQueue.new end |
Instance Attribute Details
#queue ⇒ Object
Returns the value of attribute queue.
35 36 37 |
# File 'lib/slash/typhoeus.rb', line 35 def queue @queue end |
Instance Method Details
#request(method, uri, options = {}) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/slash/typhoeus.rb', line 37 def request(method, uri, = {}) = .dup prepare_request(uri, ) params, headers = [:params], [:headers] rq = Typhoeus::Request.new(uri.to_s, :method => method, :headers => headers, :params => !params.blank? ? params.inject({}) {|h, x| h[x[0].to_s] = x[1] || ''; h } : nil, :body => [:body], :timeout => [:timeout] || timeout, :user_agent => headers['User-Agent'] ) ret = nil rq.on_complete do |response| if logger logger.debug "%s %s --> %d (%d %.0fs)" % [rq.method.to_s.upcase, rq.url, response.code, response.body ? response.body.length : 0, response.time] end ret = response = augment_response(response) ret = yield response if block_given? response end async = [:async] queue = [true, false, nil].include?(async) ? self.queue : async queue.submit(rq) if async queue else queue.run block_given? ? ret : check_and_raise(rq.handled_response) end end |