class FoucaultHttp::HttpConnection
Constants
- HTTP_CONNECTION_FAILURE
Public Instance Methods
connection(address, opts, encoding, cache_store = nil, instrumenter = nil)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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
Private Instance Methods
http_connection(address, opts={}, encoding, cache_store, instrumenter)
click to toggle source
# File lib/foucault_http/http_connection.rb, line 50 def http_connection(address, opts={}, encoding, cache_store, instrumenter) faraday_connection = Faraday.new(opts.merge(url: address)) do |faraday| # faraday.use :http_cache, caching if caching faraday.request encoding if encoding if Configuration.config.logger && Configuration.config.log_formatter faraday.response :logger, Configuration.config.logger, formatter: Configuration.config.log_formatter elsif Configuration.config.logger faraday.response :logger, Configuration.config.logger else faraday.response :logger do |log| log.filter(/(Bearer.)(.+)/, '\1[REMOVED]') log.filter(/(Basic.)(.+)/, '\1[REMOVED]') end end faraday.adapter :net_http end faraday_connection end