Class: Vellum::AsyncRequestClient
- Inherits:
-
Object
- Object
- Vellum::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(request_options: nil, environment:) ⇒ String
- #initialize(base_url: nil, environment: Vellum::Environment::PRODUCTION, max_retries: nil, timeout_in_seconds: nil, api_key:, api_version: nil) ⇒ Vellum::AsyncRequestClient constructor
Constructor Details
#initialize(base_url: nil, environment: Vellum::Environment::PRODUCTION, max_retries: nil, timeout_in_seconds: nil, api_key:, api_version: nil) ⇒ Vellum::AsyncRequestClient
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/requests.rb', line 82 def initialize(base_url: nil, environment: Vellum::Environment::PRODUCTION, max_retries: nil, timeout_in_seconds: nil, api_key:, api_version: nil) @default_environment = environment @api_key = api_key @headers = { } unless api_version.nil? @headers["X-API-Version"] = api_version end @conn = Faraday.new(headers: @headers) do | faraday | faraday.request :multipart faraday.request :json faraday.response :raise_error, include_request: true faraday.adapter :async_http unless max_retries.nil? faraday.request :retry , { max: max_retries } end unless timeout_in_seconds.nil? faraday..timeout = timeout_in_seconds end end end |
Instance Attribute Details
#api_key ⇒ String (readonly)
70 71 72 |
# File 'lib/requests.rb', line 70 def api_key @api_key end |
#base_url ⇒ String (readonly)
68 69 70 |
# File 'lib/requests.rb', line 68 def base_url @base_url end |
#conn ⇒ Faraday (readonly)
66 67 68 |
# File 'lib/requests.rb', line 66 def conn @conn end |
#default_environment ⇒ String (readonly)
72 73 74 |
# File 'lib/requests.rb', line 72 def default_environment @default_environment end |
Instance Method Details
#get_headers ⇒ Hash{String => String}
109 110 111 112 113 |
# File 'lib/requests.rb', line 109 def get_headers headers = { "X-Fern-Language": 'Ruby', "X-Fern-SDK-Name": 'vellum_ai', "X-Fern-SDK-Version": '1.3.1' } headers["X-API-KEY"] = ((@api_key.is_a? Method) ? @api_key.call : @api_key) unless @api_key.nil? headers end |
#get_url(request_options: nil, environment:) ⇒ String
105 106 107 |
# File 'lib/requests.rb', line 105 def get_url(request_options: nil, environment:) &.base_url || @default_environment[environment] || @base_url end |