Class: XRBP::WebClient::Connection
- Inherits:
-
Object
- Object
- XRBP::WebClient::Connection
- Includes:
- EventEmitter, HasPlugin, HasResultParsers, ThreadRegistry
- 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.
- #parsing_plugins ⇒ Object
-
#perform ⇒ Object
Execute web request, retrieving results and returning.
- #plugin_namespace ⇒ Object
-
#url ⇒ Object
Return current url.
Methods included from ThreadRegistry
#rsleep, #thread_registry, #wake_all
Methods included from HasResultParsers
Methods included from HasPlugin
#add_plugin, #define_instance_method, #plugin, #plugin?, #plugins
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 |
#parsing_plugins ⇒ Object
29 30 31 |
# File 'lib/xrbp/webclient/connection.rb', line 29 def parsing_plugins plugins 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 |
# 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 parse_result(c.body_str, c) end |
#plugin_namespace ⇒ Object
24 25 26 |
# File 'lib/xrbp/webclient/connection.rb', line 24 def plugin_namespace WebClient end |
#url ⇒ Object
Return current url
34 35 36 |
# File 'lib/xrbp/webclient/connection.rb', line 34 def url c.url end |