class XRBP::WebClient::Connection
HTTP interface, use Connection
to perform web requests.
@example retrieve data from the web
connection = WebClient::Connection.new connection.url = "https://devnull.network" connection.perform
Constants
- DELEGATED_METHODS
Public Class Methods
new(url=nil) { |self| ... }
click to toggle source
# File lib/xrbp/webclient/connection.rb, line 45 def initialize(url=nil) self.url = url @force_quit = false yield self if block_given? end
Public Instance Methods
force_quit!()
click to toggle source
Immediate terminate outstanding requests
# File lib/xrbp/webclient/connection.rb, line 57 def force_quit! @force_quit = true wake_all # TODO immediate terminate outstanding requests end
force_quit?()
click to toggle source
# File lib/xrbp/webclient/connection.rb, line 52 def force_quit? @force_quit end
parsing_plugins()
click to toggle source
@private
# File lib/xrbp/webclient/connection.rb, line 29 def parsing_plugins plugins end
perform()
click to toggle source
Execute web request, retrieving results and returning
# 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
plugin_namespace()
click to toggle source
@private
# File lib/xrbp/webclient/connection.rb, line 24 def plugin_namespace WebClient end
url()
click to toggle source
Return current url
# File lib/xrbp/webclient/connection.rb, line 34 def url c.url end
Private Instance Methods
c()
click to toggle source
# File lib/xrbp/webclient/connection.rb, line 65 def c @curl ||= Curl::Easy.new end
handle_error()
click to toggle source
# File lib/xrbp/webclient/connection.rb, line 69 def handle_error plugins.select { |plg| plg.respond_to?(:handle_error) }.last&.handle_error end