Class: Mizuno::ClientExchange
- Inherits:
-
ContentExchange
- Object
- ContentExchange
- Mizuno::ClientExchange
- Defined in:
- lib/mizuno/client_exchange.rb
Overview
what do I want to happen on a timeout or error?
Instance Method Summary collapse
-
#initialize(client) ⇒ ClientExchange
constructor
A new instance of ClientExchange.
- #onConnectionFailed(error) ⇒ Object
- #onException(error) ⇒ Object
- #onExpire ⇒ Object
- #onResponseComplete ⇒ Object
- #onResponseHeader(name, value) ⇒ Object
- #run_callback ⇒ Object
- #setup(url, options = {}, &block) ⇒ Object
- #waitForDone ⇒ Object
Constructor Details
#initialize(client) ⇒ ClientExchange
Returns a new instance of ClientExchange.
10 11 12 13 |
# File 'lib/mizuno/client_exchange.rb', line 10 def initialize(client) super(false) @client = client end |
Instance Method Details
#onConnectionFailed(error) ⇒ Object
51 52 53 |
# File 'lib/mizuno/client_exchange.rb', line 51 def onConnectionFailed(error) @exception ||= error end |
#onException(error) ⇒ Object
47 48 49 |
# File 'lib/mizuno/client_exchange.rb', line 47 def onException(error) @exception ||= error end |
#onExpire ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/mizuno/client_exchange.rb', line 39 def onExpire @client.clear(self) @response.timeout = true @response.status = -1 @response.body = nil run_callback end |
#onResponseComplete ⇒ Object
32 33 34 35 36 37 |
# File 'lib/mizuno/client_exchange.rb', line 32 def onResponseComplete @client.clear(self) @response.status = getResponseStatus @response.body = getResponseContent run_callback end |
#onResponseHeader(name, value) ⇒ Object
28 29 30 |
# File 'lib/mizuno/client_exchange.rb', line 28 def onResponseHeader(name, value) @response[name.to_s] = value.to_s end |
#run_callback ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/mizuno/client_exchange.rb', line 55 def run_callback begin @callback.call(@response) rescue => error onException(error) end end |
#setup(url, options = {}, &block) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/mizuno/client_exchange.rb', line 15 def setup(url, = {}, &block) @callback = block @response = ClientResponse.new(url) setURL(url) @response.ssl = (getScheme == 'https') setMethod(([:method] or "GET").upcase) headers = [:headers] and headers.each_pair { |k, v| setRequestHeader(k, v) } return unless [:body] body = StringIO.new([:body].read) setRequestContentSource(body.to_inputstream) end |
#waitForDone ⇒ Object
63 64 65 66 |
# File 'lib/mizuno/client_exchange.rb', line 63 def waitForDone super throw(@exception) if @exception end |