Class: FHTTPClient::Base Abstract

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

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)
  default_options[:cache_expires_in] = config.cache.expires_in if default_options[:cache_expires_in].nil?

  return default_options[:cache_expires_in] unless expires_in

  default_options[: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)
  default_options[:cache_strategy] = config.cache.strategy if default_options[:cache_strategy].nil?
  return default_options[:cache_strategy] unless strategy

  default_options[:cache_strategy] = strategy
end

.configObject

Raises:

  • (NotImplementedError)


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

#runObject



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