Class: Zenrows::InstrumentedClient Private
- Inherits:
-
Object
- Object
- Zenrows::InstrumentedClient
- Defined in:
- lib/zenrows/instrumented_client.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Wrapper around HTTP clients that executes hooks on requests
Decorates an HTTP client (from http.rb or Net::HTTP) to add hook execution before, during, and after requests.
Constant Summary collapse
- HTTP_METHODS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
HTTP methods to instrument
i[get post put patch delete head ].freeze
Instance Attribute Summary collapse
-
#context_base ⇒ Hash
readonly
private
Base context for all requests.
-
#hooks ⇒ Hooks
readonly
private
Hook registry.
-
#http ⇒ Object
readonly
private
Underlying HTTP client.
Instance Method Summary collapse
-
#delete(url, **options) ⇒ Object
private
Instrumented DELETE request.
-
#get(url, **options) ⇒ Object
private
Instrumented GET request.
-
#head(url, **options) ⇒ Object
private
Instrumented HEAD request.
-
#initialize(http, hooks:, context_base:) ⇒ InstrumentedClient
constructor
private
Create a new instrumented client.
-
#method_missing(method, *args, **kwargs, &block) ⇒ Object
private
Delegate unknown methods to underlying client.
-
#options(url, **options) ⇒ Object
private
Instrumented OPTIONS request.
-
#patch(url, **options) ⇒ Object
private
Instrumented PATCH request.
-
#post(url, **options) ⇒ Object
private
Instrumented POST request.
-
#put(url, **options) ⇒ Object
private
Instrumented PUT request.
-
#respond_to_missing?(method, include_private = false) ⇒ Boolean
private
Check if method is supported.
Constructor Details
#initialize(http, hooks:, context_base:) ⇒ InstrumentedClient
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Create a new instrumented client
37 38 39 40 41 |
# File 'lib/zenrows/instrumented_client.rb', line 37 def initialize(http, hooks:, context_base:) @http = http @hooks = hooks @context_base = context_base end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, **kwargs, &block) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Delegate unknown methods to underlying client
113 114 115 116 117 118 119 |
# File 'lib/zenrows/instrumented_client.rb', line 113 def method_missing(method, *args, **kwargs, &block) if @http.respond_to?(method) @http.public_send(method, *args, **kwargs, &block) else super end end |
Instance Attribute Details
#context_base ⇒ Hash (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns Base context for all requests.
30 31 32 |
# File 'lib/zenrows/instrumented_client.rb', line 30 def context_base @context_base end |
#hooks ⇒ Hooks (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns Hook registry.
27 28 29 |
# File 'lib/zenrows/instrumented_client.rb', line 27 def hooks @hooks end |
#http ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns Underlying HTTP client.
24 25 26 |
# File 'lib/zenrows/instrumented_client.rb', line 24 def http @http end |
Instance Method Details
#delete(url, **options) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Instrumented DELETE request
84 85 86 |
# File 'lib/zenrows/instrumented_client.rb', line 84 def delete(url, **) instrument(:delete, url, ) { @http.delete(url, **) } end |
#get(url, **options) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Instrumented GET request
48 49 50 |
# File 'lib/zenrows/instrumented_client.rb', line 48 def get(url, **) instrument(:get, url, ) { @http.get(url, **) } end |
#head(url, **options) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Instrumented HEAD request
93 94 95 |
# File 'lib/zenrows/instrumented_client.rb', line 93 def head(url, **) instrument(:head, url, ) { @http.head(url, **) } end |
#options(url, **options) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Instrumented OPTIONS request
102 103 104 |
# File 'lib/zenrows/instrumented_client.rb', line 102 def (url, **) instrument(:options, url, ) { @http.(url, **) } end |
#patch(url, **options) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Instrumented PATCH request
75 76 77 |
# File 'lib/zenrows/instrumented_client.rb', line 75 def patch(url, **) instrument(:patch, url, ) { @http.patch(url, **) } end |
#post(url, **options) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Instrumented POST request
57 58 59 |
# File 'lib/zenrows/instrumented_client.rb', line 57 def post(url, **) instrument(:post, url, ) { @http.post(url, **) } end |
#put(url, **options) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Instrumented PUT request
66 67 68 |
# File 'lib/zenrows/instrumented_client.rb', line 66 def put(url, **) instrument(:put, url, ) { @http.put(url, **) } end |
#respond_to_missing?(method, include_private = false) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Check if method is supported
126 127 128 |
# File 'lib/zenrows/instrumented_client.rb', line 126 def respond_to_missing?(method, include_private = false) @http.respond_to?(method, include_private) || super end |