Class: Braintrust::RequestOptions

Inherits:
Object
  • Object
show all
Defined in:
lib/braintrust/request_options.rb

Overview

Specify HTTP behaviour to use for a specific request. These options supplement or override those provided at the client level.

When making a request, you can pass an actual RequestOptions instance, or simply pass a Hash with symbol keys matching the attributes on this class.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(values = {}) ⇒ RequestOptions

Returns a new instance of RequestOptions.

Parameters:

  • values (Hash{Symbol => Object}) (defaults to: {})

    initial option values to set on the instance.



25
26
27
# File 'lib/braintrust/request_options.rb', line 25

def initialize(values = {})
  @_values = values
end

Instance Attribute Details

#extra_bodyHash{Symbol => Object}

Extra data to send with the request. These are deep merged into any data generated as part of the normal request.

Returns:

  • (Hash{Symbol => Object})


51
# File 'lib/braintrust/request_options.rb', line 51

option :extra_body

#extra_headersHash{String => String}

Extra headers to send with the request. These are .merged’d into any extra_headers given at the client level.

Returns:

  • (Hash{String => String})


39
# File 'lib/braintrust/request_options.rb', line 39

option :extra_headers

#extra_queryHash{Symbol => Object}

Extra query params to send with the request. These are .merge’d into any query given at the client level.

Returns:

  • (Hash{Symbol => Object})


45
# File 'lib/braintrust/request_options.rb', line 45

option :extra_query

#idempotency_keyString

Idempotency key to send with request and all associated retries. Will only be sent for write requests.

Returns:

  • (String)


33
# File 'lib/braintrust/request_options.rb', line 33

option :idempotency_key

#max_retriesInteger

Maximum number of retries to attempt after a failed initial request.

Returns:

  • (Integer)


56
# File 'lib/braintrust/request_options.rb', line 56

option :max_retries

Instance Method Details

#[](key) ⇒ Object

Lookup an option previously set on this instance.

Returns:

  • (Object)


61
62
63
# File 'lib/braintrust/request_options.rb', line 61

def [](key)
  @_values[key]
end

#inspectString

Returns:

  • (String)


75
76
77
# File 'lib/braintrust/request_options.rb', line 75

def inspect
  "#<Braintrust::RequestOptions:0x#{object_id.to_s(16)} #{@_values.inspect}>"
end

#to_hHash{Symbol => Object} Also known as: to_hash

Return a Hash containing the options set on this instance.

Returns:

  • (Hash{Symbol => Object})


68
69
70
# File 'lib/braintrust/request_options.rb', line 68

def to_h
  @_values
end

#to_sString

Returns:

  • (String)


80
81
82
# File 'lib/braintrust/request_options.rb', line 80

def to_s
  @_values.to_s
end