Class: CandidApiClient::RequestClient
- Inherits:
-
Object
- Object
- CandidApiClient::RequestClient
- Defined in:
- lib/requests.rb
Instance Attribute Summary collapse
- #base_url ⇒ String readonly
- #conn ⇒ Faraday readonly
- #default_environment ⇒ String readonly
- #token ⇒ String, Method readonly
Instance Method Summary collapse
- #get_headers ⇒ Hash{String => String}
- #get_url(environment:, request_options: nil) ⇒ String
- #initialize(base_url: nil, environment: CandidApiClient::Environment::PRODUCTION, max_retries: nil, timeout_in_seconds: nil, token: nil) ⇒ CandidApiClient::RequestClient constructor
Constructor Details
#initialize(base_url: nil, environment: CandidApiClient::Environment::PRODUCTION, max_retries: nil, timeout_in_seconds: nil, token: nil) ⇒ CandidApiClient::RequestClient
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/requests.rb', line 25 def initialize(base_url: nil, environment: CandidApiClient::Environment::PRODUCTION, max_retries: nil, timeout_in_seconds: nil, token: nil) @default_environment = environment @token = token @conn = Faraday.new do |faraday| faraday.request :json faraday.response :raise_error, include_request: true faraday.request :retry, { max: max_retries } unless max_retries.nil? faraday..timeout = timeout_in_seconds unless timeout_in_seconds.nil? end end |
Instance Attribute Details
#base_url ⇒ String (readonly)
13 14 15 |
# File 'lib/requests.rb', line 13 def base_url @base_url end |
#conn ⇒ Faraday (readonly)
11 12 13 |
# File 'lib/requests.rb', line 11 def conn @conn end |
#default_environment ⇒ String (readonly)
17 18 19 |
# File 'lib/requests.rb', line 17 def default_environment @default_environment end |
#token ⇒ String, Method (readonly)
15 16 17 |
# File 'lib/requests.rb', line 15 def token @token end |
Instance Method Details
#get_headers ⇒ Hash{String => String}
45 46 47 48 49 |
# File 'lib/requests.rb', line 45 def get_headers headers = { "X-Fern-Language": "Ruby", "X-Fern-SDK-Name": "candidhealth", "X-Fern-SDK-Version": "0.35.1" } headers["Authorization"] = ((@token.is_a? Method) ? @token.call : @token) unless token.nil? headers end |
#get_url(environment:, request_options: nil) ⇒ String
40 41 42 |
# File 'lib/requests.rb', line 40 def get_url(environment:, request_options: nil) &.base_url || @default_environment[environment] || @base_url end |