Class: FoucaultHttp::HttpConnection
- Inherits:
-
Object
- Object
- FoucaultHttp::HttpConnection
- Includes:
- Dry::Monads::Result::Mixin, Dry::Monads::Try::Mixin
- Defined in:
- lib/foucault_http/http_connection.rb
Constant Summary collapse
- HTTP_CONNECTION_FAILURE =
:http_connection_failure
Instance Method Summary collapse
- #connection(address, opts, encoding, cache_store = nil, instrumenter = nil) ⇒ Object
- #delete(hdrs) ⇒ Object
- #get(hdrs, params) ⇒ Object
- #post(hdrs, body) ⇒ Object
Instance Method Details
#connection(address, opts, encoding, cache_store = nil, instrumenter = nil) ⇒ Object
13 14 15 16 |
# File 'lib/foucault_http/http_connection.rb', line 13 def connection(address, opts, encoding, cache_store = nil, instrumenter = nil) @http_connection = Try { http_connection(address, opts, encoding, cache_store, instrumenter) } self end |
#delete(hdrs) ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/foucault_http/http_connection.rb', line 39 def delete(hdrs) return @http_connection.to_result if @http_connection.failure? Try { @http_connection.value_or.delete do |r| r.headers = hdrs end }.to_result end |
#get(hdrs, params) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/foucault_http/http_connection.rb', line 18 def get(hdrs, params) return @http_connection.to_result if @http_connection.failure? Try { @http_connection.value_or.get do |r| r.headers = hdrs if hdrs r.params = params if params end }.to_result end |
#post(hdrs, body) ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/foucault_http/http_connection.rb', line 28 def post(hdrs, body) return @http_connection.to_result if @http_connection.failure? return body.to_result if body.failure? Try { @http_connection.value_or.post do |r| r.body = body.value_or r.headers = hdrs end }.to_result end |