Class: FoucaultHttp::HttpConnection

Inherits:
Object
  • Object
show all
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

Instance Method Details

#connection(address, encoding, cache_store = nil, instrumenter = nil) ⇒ Object



14
15
16
17
# File 'lib/foucault_http/http_connection.rb', line 14

def connection(address, encoding, cache_store = nil, instrumenter = nil)
  @http_connection = Try { http_connection(address, 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



19
20
21
22
23
24
25
26
27
# File 'lib/foucault_http/http_connection.rb', line 19

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



29
30
31
32
33
34
35
36
37
# File 'lib/foucault_http/http_connection.rb', line 29

def post(hdrs, body)
  return @http_connection.to_result if @http_connection.failure?
  Try {
    @http_connection.value_or.post do |r|
      r.body = body
      r.headers = hdrs
    end
  }.to_result
end