Module: PatientHttp::RequestHelper::ClassMethods
- Includes:
- HttpMethodHelpers
- Defined in:
- lib/patient_http/request_helper.rb
Instance Method Summary collapse
-
#async_request(method, url, callback:, headers: nil, body: nil, json: nil, params: nil, timeout: nil, raise_error_responses: nil, callback_args: nil, preprocessors: nil, processor: nil) ⇒ Object
Builds and dispatches an asynchronous HTTP request.
-
#async_request_template ⇒ RequestTemplate?
private
Returns the RequestTemplate defined for this class or its ancestors, or nil if none is defined.
-
#request_template(base_url: nil, headers: {}, params: nil, timeout: 30, preprocessors: nil, processor: nil) ⇒ void
Defines a default request template for this class.
Methods included from HttpMethodHelpers
#async_delete, #async_get, #async_patch, #async_post, #async_put
Instance Method Details
#async_request(method, url, callback:, headers: nil, body: nil, json: nil, params: nil, timeout: nil, raise_error_responses: nil, callback_args: nil, preprocessors: nil, processor: nil) ⇒ Object
Builds and dispatches an asynchronous HTTP request.
When a request template is configured, the request is built from the template. Otherwise, it is built directly from the provided arguments.
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/patient_http/request_helper.rb', line 153 def async_request( method, url, callback:, headers: nil, body: nil, json: nil, params: nil, timeout: nil, raise_error_responses: nil, callback_args: nil, preprocessors: nil, processor: nil ) template = async_request_template kwargs = {body: body, json: json, headers: headers, params: params, timeout: timeout, preprocessors: preprocessors, processor: processor} request = if template template.request(method, url, **kwargs) else Request.new(method, url, **kwargs) end PatientHttp.execute( request: request, callback: callback, callback_args: callback_args, raise_error_responses: raise_error_responses ) end |
#async_request_template ⇒ RequestTemplate?
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 the RequestTemplate defined for this class or its ancestors, or nil if none is defined. This allows subclasses to inherit the request template from their parent class if they don't define their own.
189 190 191 192 193 194 |
# File 'lib/patient_http/request_helper.rb', line 189 def async_request_template return @patient_http_request_template if @patient_http_request_template return superclass.async_request_template if superclass.include?(PatientHttp::RequestHelper) nil end |
#request_template(base_url: nil, headers: {}, params: nil, timeout: 30, preprocessors: nil, processor: nil) ⇒ void
This method returns an undefined value.
Defines a default request template for this class.
Requests created with the helper methods merge these defaults unless explicitly overridden.
121 122 123 124 125 126 127 128 129 130 |
# File 'lib/patient_http/request_helper.rb', line 121 def request_template(base_url: nil, headers: {}, params: nil, timeout: 30, preprocessors: nil, processor: nil) @patient_http_request_template = RequestTemplate.new( base_url: base_url, headers: headers, params: params, timeout: timeout, preprocessors: preprocessors, processor: processor ) end |