Class: TrophyApiClient::AsyncRequestClient
- Inherits:
-
Object
- Object
- TrophyApiClient::AsyncRequestClient
- Defined in:
- lib/requests.rb
Instance Attribute Summary collapse
- #api_key ⇒ String readonly
- #base_url ⇒ String readonly
- #conn ⇒ Faraday readonly
- #default_environment ⇒ String readonly
Instance Method Summary collapse
- #get_headers ⇒ Hash{String => String}
- #get_url(environment:, request_options: nil) ⇒ String
- #initialize(api_key:, base_url: nil, environment: TrophyApiClient::Environment::PRODUCTION, max_retries: nil, timeout_in_seconds: nil, tenant_id: nil) ⇒ TrophyApiClient::AsyncRequestClient constructor
Constructor Details
#initialize(api_key:, base_url: nil, environment: TrophyApiClient::Environment::PRODUCTION, max_retries: nil, timeout_in_seconds: nil, tenant_id: nil) ⇒ TrophyApiClient::AsyncRequestClient
76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/requests.rb', line 76 def initialize(api_key:, base_url: nil, environment: TrophyApiClient::Environment::PRODUCTION, max_retries: nil, timeout_in_seconds: nil, tenant_id: nil) @default_environment = environment @api_key = api_key @headers = {} @headers["Tenant-ID"] = tenant_id unless tenant_id.nil? @conn = Faraday.new(headers: @headers) do |faraday| faraday.request :json faraday.response :raise_error, include_request: true faraday.adapter :async_http 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
#api_key ⇒ String (readonly)
63 64 65 |
# File 'lib/requests.rb', line 63 def api_key @api_key end |
#base_url ⇒ String (readonly)
61 62 63 |
# File 'lib/requests.rb', line 61 def base_url @base_url end |
#conn ⇒ Faraday (readonly)
59 60 61 |
# File 'lib/requests.rb', line 59 def conn @conn end |
#default_environment ⇒ String (readonly)
65 66 67 |
# File 'lib/requests.rb', line 65 def default_environment @default_environment end |
Instance Method Details
#get_headers ⇒ Hash{String => String}
99 100 101 102 103 |
# File 'lib/requests.rb', line 99 def get_headers headers = { "X-Fern-Language": "Ruby", "X-Fern-SDK-Name": "trophy_api_client" } headers["X-API-KEY"] = ((@api_key.is_a? Method) ? @api_key.call : @api_key) unless @api_key.nil? headers end |
#get_url(environment:, request_options: nil) ⇒ String
94 95 96 |
# File 'lib/requests.rb', line 94 def get_url(environment:, request_options: nil) &.base_url || @default_environment[environment] || @base_url end |