Class: XRBP::WebClient::Connection

Inherits:
Object
  • Object
show all
Includes:
EventEmitter, HasPlugin, HasResultParsers, ThreadRegistry
Defined in:
lib/xrbp/webclient/connection.rb

Overview

HTTP interface, use Connection to perform web requests.

Examples:

retrieve data from the web

connection = WebClient::Connection.new
connection.url = "https://devnull.network"
connection.perform

Constant Summary collapse

DELEGATED_METHODS =
[:url=,
:timeout=,
:ssl_verify_peer=,
:ssl_verify_host=]

Instance Method Summary collapse

Methods included from ThreadRegistry

#rsleep, #thread_registry, #wake_all

Methods included from HasResultParsers

#parse_result

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.

Yields:

  • (_self)

Yield Parameters:



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

Returns:

  • (Boolean)


52
53
54
# File 'lib/xrbp/webclient/connection.rb', line 52

def force_quit?
  @force_quit
end

#parsing_pluginsObject



29
30
31
# File 'lib/xrbp/webclient/connection.rb', line 29

def parsing_plugins
  plugins
end

#performObject

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_namespaceObject



24
25
26
# File 'lib/xrbp/webclient/connection.rb', line 24

def plugin_namespace
  WebClient
end

#urlObject

Return current url



34
35
36
# File 'lib/xrbp/webclient/connection.rb', line 34

def url
  c.url
end