Class: EzClient::Request
- Inherits:
-
Object
- Object
- EzClient::Request
- Defined in:
- lib/ezclient/request.rb
Instance Attribute Summary collapse
-
#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
- #api_auth!(*args) ⇒ Object
- #body ⇒ Object
- #headers ⇒ Object
-
#initialize(verb, url, options) ⇒ Request
constructor
A new instance of Request.
- #perform ⇒ Object
- #perform! ⇒ Object
Constructor Details
#initialize(verb, url, options) ⇒ Request
Returns a new instance of Request.
6 7 8 9 10 |
# File 'lib/ezclient/request.rb', line 6 def initialize(verb, url, ) self.verb = verb.to_s.upcase self.url = url self. = end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
4 5 6 |
# File 'lib/ezclient/request.rb', line 4 def @options end |
#url ⇒ Object
Returns the value of attribute url.
4 5 6 |
# File 'lib/ezclient/request.rb', line 4 def url @url end |
#verb ⇒ Object
Returns the value of attribute verb.
4 5 6 |
# File 'lib/ezclient/request.rb', line 4 def verb @verb end |
Instance Method Details
#api_auth!(*args) ⇒ Object
33 34 35 36 37 |
# File 'lib/ezclient/request.rb', line 33 def api_auth!(*args) raise "ApiAuth gem is not loaded" unless defined?(ApiAuth) ApiAuth.sign!(http_request, *args) self end |
#body ⇒ Object
39 40 41 42 43 44 |
# File 'lib/ezclient/request.rb', line 39 def body http_request.body.source.rewind if http_request.body.source.respond_to?(:rewind) body = +"" http_request.body.each { |chunk| body << chunk } body end |
#headers ⇒ Object
46 47 48 |
# File 'lib/ezclient/request.rb', line 46 def headers http_request.headers.to_h end |
#perform ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/ezclient/request.rb', line 12 def perform http_response = perform_request EzClient::Response.new(http_response).tap do |response| on_complete.call(self, response, [:metadata]) end rescue => error on_error.call(self, error, [:metadata]) raise error end |
#perform! ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/ezclient/request.rb', line 23 def perform! response = perform if response.error? raise EzClient::ResponseStatusError, response else response end end |