Class: Lavin::Client
- Inherits:
-
Object
- Object
- Lavin::Client
- Defined in:
- lib/lavin/client.rb
Defined Under Namespace
Classes: Error, NoCurrentAsyncTaskError, ServerError
Constant Summary collapse
- DEFAULT_HEADERS =
{ 'User-Agent'=> 'LavinLoadTest', 'Accept' => '*/*', }.freeze
Instance Attribute Summary collapse
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
-
#cookie ⇒ Object
Returns the value of attribute cookie.
-
#internet ⇒ Object
readonly
Returns the value of attribute internet.
-
#report_statistics ⇒ Object
Returns the value of attribute report_statistics.
-
#request_count ⇒ Object
Returns the value of attribute request_count.
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(base_url = nil) ⇒ Client
constructor
A new instance of Client.
- #request(method, url:, headers:, body: nil) ⇒ Object
Constructor Details
#initialize(base_url = nil) ⇒ Client
Returns a new instance of Client.
29 30 31 32 33 34 35 36 37 |
# File 'lib/lavin/client.rb', line 29 def initialize(base_url = nil) raise NoCurrentAsyncTaskError unless Async::Task.current? @internet = Async::HTTP::Internet.new @base_url = base_url @request_count = 0 @cookie = nil @report_statistics = true end |
Instance Attribute Details
#base_url ⇒ Object (readonly)
Returns the value of attribute base_url.
26 27 28 |
# File 'lib/lavin/client.rb', line 26 def base_url @base_url end |
#cookie ⇒ Object
Returns the value of attribute cookie.
27 28 29 |
# File 'lib/lavin/client.rb', line 27 def @cookie end |
#internet ⇒ Object (readonly)
Returns the value of attribute internet.
26 27 28 |
# File 'lib/lavin/client.rb', line 26 def internet @internet end |
#report_statistics ⇒ Object
Returns the value of attribute report_statistics.
27 28 29 |
# File 'lib/lavin/client.rb', line 27 def report_statistics @report_statistics end |
#request_count ⇒ Object
Returns the value of attribute request_count.
27 28 29 |
# File 'lib/lavin/client.rb', line 27 def request_count @request_count end |
Instance Method Details
#close ⇒ Object
39 40 41 |
# File 'lib/lavin/client.rb', line 39 def close internet.close end |
#request(method, url:, headers:, body: nil) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/lavin/client.rb', line 43 def request(method, url:, headers:, body: nil) url, headers, body = rewrite_request(url:, headers:, body:) start_time = Time.now response = internet.send(method, url, headers, body) duration = Time.now - start_time status, headers, body = process(response) Statistics.register_request(method:, url:, status:, duration:) if report_statistics {status:, headers:, body: body} end |