Class: XRBP::WebClient::Connection
- Inherits:
-
Object
- Object
- XRBP::WebClient::Connection
- Includes:
- EventEmitter
- Defined in:
- lib/xrbp/webclient/connection.rb
Overview
HTTP interface, use Connection to perform web requests.
Constant Summary collapse
- DELEGATED_METHODS =
[:url=, :timeout=, :ssl_verify_peer=, :ssl_verify_host=]
Instance Method Summary collapse
-
#force_quit! ⇒ Object
Immediate terminate outstanding requests.
- #force_quit? ⇒ Boolean
-
#initialize(url = nil) {|_self| ... } ⇒ Connection
constructor
A new instance of Connection.
-
#perform ⇒ Object
Execute web request, retrieving results and returning.
-
#url ⇒ Object
Return current url.
Constructor Details
#initialize(url = nil) {|_self| ... } ⇒ Connection
Returns a new instance of Connection.
45 46 47 48 49 50 |
# File 'lib/xrbp/webclient/connection.rb', line 45 def initialize(url=nil) self.url = url @force_quit = false yield self if block_given? end |
Instance Method Details
#force_quit! ⇒ Object
Immediate terminate outstanding requests
57 58 59 60 61 |
# File 'lib/xrbp/webclient/connection.rb', line 57 def force_quit! @force_quit = true wake_all # TODO immediate terminate outstanding requests end |
#force_quit? ⇒ Boolean
52 53 54 |
# File 'lib/xrbp/webclient/connection.rb', line 52 def force_quit? @force_quit end |
#perform ⇒ Object
Execute web request, retrieving results and returning
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/xrbp/webclient/connection.rb', line 78 def perform # TODO fault tolerance plugins: # configurable timeout, # round-robin urls, # redirect handling, etc begin c.perform rescue => e emit :error, e return handle_error end if c.response_code != 200 emit :http_error, c.response_code return handle_error end emit :success, c.body_str begin parse_result(c.body_str, c) rescue Exception => e emit :error, e return nil end end |
#url ⇒ Object
Return current url
34 35 36 |
# File 'lib/xrbp/webclient/connection.rb', line 34 def url c.url end |