Class: Vellum::RequestClient
- Inherits:
-
Object
- Object
- Vellum::RequestClient
- 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::RequestClient constructor
Constructor Details
#initialize(base_url: nil, environment: Vellum::Environment::PRODUCTION, max_retries: nil, timeout_in_seconds: nil, api_key:, api_version: nil) ⇒ Vellum::RequestClient
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/requests.rb', line 32 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 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)
20 21 22 |
# File 'lib/requests.rb', line 20 def api_key @api_key end |
#base_url ⇒ String (readonly)
18 19 20 |
# File 'lib/requests.rb', line 18 def base_url @base_url end |
#conn ⇒ Faraday (readonly)
16 17 18 |
# File 'lib/requests.rb', line 16 def conn @conn end |
#default_environment ⇒ String (readonly)
22 23 24 |
# File 'lib/requests.rb', line 22 def default_environment @default_environment end |
Instance Method Details
#get_headers ⇒ Hash{String => String}
58 59 60 61 62 |
# File 'lib/requests.rb', line 58 def get_headers headers = { "X-Fern-Language": 'Ruby', "X-Fern-SDK-Name": 'vellum_ai', "X-Fern-SDK-Version": '1.2.3' } 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
54 55 56 |
# File 'lib/requests.rb', line 54 def get_url(request_options: nil, environment:) &.base_url || @default_environment[environment] || @base_url end |