Class: LunaPark::Http::Send
- Inherits:
-
Object
- Object
- LunaPark::Http::Send
- Extended by:
- Extensions::Callable
- Defined in:
- lib/luna_park/http/send.rb
Overview
Send Request and get Response.
This service, in fact, works as an adapter for the RestClient gem. If you want to remove dependence on RestClient, you should rewrite Send class.
Instead of using these service directly, better use the request method Request#call. Which freeze request and define Request#sent_at timestamp.
Instance Method Summary collapse
-
#call ⇒ LunaPark::Http::Response
Send defined request.
-
#call! ⇒ LunaPark::Http::Response
Send defined request.
-
#initialize(original_request) ⇒ Send
constructor
Define new Send service.
Constructor Details
#initialize(original_request) ⇒ Send
Define new Send service
26 27 28 |
# File 'lib/luna_park/http/send.rb', line 26 def initialize(original_request) @original_request = original_request end |
Instance Method Details
#call ⇒ LunaPark::Http::Response
Send defined request. Always return response even if the response is not successful.
42 43 44 45 46 47 48 49 |
# File 'lib/luna_park/http/send.rb', line 42 def call rest_request = build_rest_request(original_request) rest_response = rest_request.execute build_original_response(rest_response) rescue Errno::ECONNREFUSED then build_unavailable_response rescue ::RestClient::Exceptions::Timeout then build_timeout_response rescue ::RestClient::Exception => e then build_original_response(e.response) end |
#call! ⇒ LunaPark::Http::Response
Send defined request. If response is not successful the method raise Errors::Http
63 64 65 66 67 |
# File 'lib/luna_park/http/send.rb', line 63 def call! call.tap do |response| raise response.exception unless response.exception.nil? end end |