Class: EzClient::Request
- Inherits:
-
Object
- Object
- EzClient::Request
- Defined in:
- lib/ezclient/request.rb
Constant Summary collapse
- OPTION_KEYS =
%i[ body form json metadata params query ].freeze
Instance Attribute Summary collapse
-
#elapsed_seconds ⇒ Object
Returns the value of attribute elapsed_seconds.
-
#options ⇒ Object
Returns the value of attribute options.
-
#url ⇒ Object
Returns the value of attribute url.
-
#verb ⇒ Object
Returns the value of attribute verb.
Instance Method Summary collapse
- #add_headers!(new_headers) ⇒ Object
- #api_auth!(*args) ⇒ Object
- #body ⇒ Object
- #headers ⇒ Object
- #http_options ⇒ Object
-
#initialize(verb, url, options) ⇒ Request
constructor
A new instance of Request.
- #perform ⇒ Object
- #perform! ⇒ Object
- #uri ⇒ Object
Constructor Details
#initialize(verb, url, options) ⇒ Request
Returns a new instance of Request.
15 16 17 18 19 20 21 |
# File 'lib/ezclient/request.rb', line 15 def initialize(verb, url, ) self.verb = verb.to_s.upcase self.url = url self.client = .delete(:client) self. = EzClient::CheckOptions.call(, OPTION_KEYS + EzClient::Client::REQUEST_OPTION_KEYS) end |
Instance Attribute Details
#elapsed_seconds ⇒ Object
Returns the value of attribute elapsed_seconds.
13 14 15 |
# File 'lib/ezclient/request.rb', line 13 def elapsed_seconds @elapsed_seconds end |
#options ⇒ Object
Returns the value of attribute options.
13 14 15 |
# File 'lib/ezclient/request.rb', line 13 def @options end |
#url ⇒ Object
Returns the value of attribute url.
13 14 15 |
# File 'lib/ezclient/request.rb', line 13 def url @url end |
#verb ⇒ Object
Returns the value of attribute verb.
13 14 15 |
# File 'lib/ezclient/request.rb', line 13 def verb @verb end |
Instance Method Details
#add_headers!(new_headers) ⇒ Object
64 65 66 |
# File 'lib/ezclient/request.rb', line 64 def add_headers!(new_headers) http_request.headers.merge!(new_headers) end |
#api_auth!(*args) ⇒ Object
44 45 46 47 48 |
# File 'lib/ezclient/request.rb', line 44 def api_auth!(*args) raise "ApiAuth gem is not loaded" unless defined?(ApiAuth) ApiAuth.sign!(http_request, *args) self end |
#body ⇒ Object
54 55 56 57 58 |
# File 'lib/ezclient/request.rb', line 54 def body body = +"" http_request.body.each { |chunk| body << chunk } body end |
#headers ⇒ Object
60 61 62 |
# File 'lib/ezclient/request.rb', line 60 def headers http_request.headers.to_h end |
#http_options ⇒ Object
68 69 70 |
# File 'lib/ezclient/request.rb', line 68 def @http_options ||= http_client..merge(ssl_context: [:ssl_context]) end |
#perform ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/ezclient/request.rb', line 23 def perform http_response = perform_request EzClient::Response.new(http_response, http_request).tap do |response| on_complete.call(self, response, [:metadata]) end rescue => error on_error.call(self, error, [:metadata]) error_wrapper.call(self, error, [:metadata]) end |
#perform! ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/ezclient/request.rb', line 34 def perform! response = perform if response.error? raise EzClient::ResponseStatusError, response else response end end |
#uri ⇒ Object
50 51 52 |
# File 'lib/ezclient/request.rb', line 50 def uri http_request.uri end |