Class: NewDemoApiClient::RequestClient
- Inherits:
-
Object
- Object
- NewDemoApiClient::RequestClient
- Defined in:
- lib/requests.rb
Instance Attribute Summary collapse
- #base_url ⇒ String readonly
- #conn ⇒ Faraday readonly
- #default_environment ⇒ String readonly
- #token ⇒ String readonly
Instance Method Summary collapse
- #get_headers ⇒ Hash{String => String}
- #get_url(request_options: nil) ⇒ String
- #initialize(token:, base_url: nil, environment: NewDemoApiClient::Environment::DEFAULT, max_retries: nil, timeout_in_seconds: nil) ⇒ NewDemoApiClient::RequestClient constructor
Constructor Details
#initialize(token:, base_url: nil, environment: NewDemoApiClient::Environment::DEFAULT, max_retries: nil, timeout_in_seconds: nil) ⇒ NewDemoApiClient::RequestClient
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/requests.rb', line 26 def initialize(token:, base_url: nil, environment: NewDemoApiClient::Environment::DEFAULT, max_retries: nil, timeout_in_seconds: nil) @default_environment = environment @base_url = environment || base_url @token = "Bearer #{token}" @conn = Faraday.new do |faraday| faraday.request :multipart 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)
14 15 16 |
# File 'lib/requests.rb', line 14 def base_url @base_url end |
#conn ⇒ Faraday (readonly)
12 13 14 |
# File 'lib/requests.rb', line 12 def conn @conn end |
#default_environment ⇒ String (readonly)
18 19 20 |
# File 'lib/requests.rb', line 18 def default_environment @default_environment end |
#token ⇒ String (readonly)
16 17 18 |
# File 'lib/requests.rb', line 16 def token @token end |
Instance Method Details
#get_headers ⇒ Hash{String => String}
47 48 49 50 51 |
# File 'lib/requests.rb', line 47 def get_headers headers = { "X-Fern-Language": "Ruby", "X-Fern-SDK-Name": "test_sdk", "X-Fern-SDK-Version": "0.0.4" } headers["Authorization"] = ((@token.is_a? Method) ? @token.call : @token) unless @token.nil? headers end |
#get_url(request_options: nil) ⇒ String
42 43 44 |
# File 'lib/requests.rb', line 42 def get_url(request_options: nil) &.base_url || @default_environment || @base_url end |