Class: FHTTPClient::Base Abstract
- Includes:
- HTTParty
- Defined in:
- lib/f_http_client/base.rb
Overview
This class is abstract.
Allows to have an http client to build a service
Constant Summary collapse
- DEFAULT_SKIP_CACHE_IF =
->(response) { FHTTPClient::Cache::HTTPResponseAnalyzer.not_cacheable?(response) }
Class Method Summary collapse
- .cache_expires_in(expires_in = nil) ⇒ Object
- .cache_strategy(strategy = nil) ⇒ Object
- .config ⇒ Object
Instance Method Summary collapse
Class Method Details
.cache_expires_in(expires_in = nil) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/f_http_client/base.rb', line 41 def self.cache_expires_in(expires_in = nil) [:cache_expires_in] = config.cache.expires_in if [:cache_expires_in].nil? return [:cache_expires_in] unless expires_in [:cache_expires_in] = expires_in end |
.cache_strategy(strategy = nil) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/f_http_client/base.rb', line 34 def self.cache_strategy(strategy = nil) [:cache_strategy] = config.cache.strategy if [:cache_strategy].nil? return [:cache_strategy] unless strategy [:cache_strategy] = strategy end |
.config ⇒ Object
30 31 32 |
# File 'lib/f_http_client/base.rb', line 30 def self.config raise NotImplementedError, 'Clients must implement .config' end |
Instance Method Details
#run ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/f_http_client/base.rb', line 19 def run configure_base_uri.and_then do response = make_cached_request.value! FHTTPClient::Processor::Response.(response: response, log_strategy: log_strategy) end rescue StandardError => e FHTTPClient::Processor::Exception.(error: e, log_strategy: log_strategy) .on_failure(:uncaught_error) { raise e } end |