Class: Vapi::Internal::JSON::Request Private

Inherits:
Http::BaseRequest show all
Defined in:
lib/vapi/internal/json/request.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Attribute Summary collapse

Attributes inherited from Http::BaseRequest

#base_url, #headers, #method, #path, #query, #request_options

Instance Method Summary collapse

Methods inherited from Http::BaseRequest

#encode_query

Constructor Details

#initialize(base_url:, path:, method:, headers: {}, query: {}, body: nil, request_options: {}) ⇒ Request

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Request.

Parameters:

  • base_url (String)

    The base URL for the request

  • path (String)

    The path for the request

  • method (Symbol)

    The HTTP method for the request (:get, :post, etc.)

  • headers (Hash) (defaults to: {})

    Additional headers for the request (optional)

  • query (Hash) (defaults to: {})

    Query parameters for the request (optional)

  • body (Object, nil) (defaults to: nil)

    The JSON request body (optional)

  • request_options (Vapi::RequestOptions, Hash{Symbol=>Object}, nil) (defaults to: {})


17
18
19
20
21
# File 'lib/vapi/internal/json/request.rb', line 17

def initialize(base_url:, path:, method:, headers: {}, query: {}, body: nil, request_options: {})
  super(base_url:, path:, method:, headers:, query:, request_options:)

  @body = body
end

Instance Attribute Details

#bodyObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



8
9
10
# File 'lib/vapi/internal/json/request.rb', line 8

def body
  @body
end

Instance Method Details

#encode_bodyString?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns The encoded HTTP request body.

Returns:

  • (String, nil)

    The encoded HTTP request body.



35
36
37
# File 'lib/vapi/internal/json/request.rb', line 35

def encode_body
  @body.nil? ? nil : ::JSON.generate(@body)
end

#encode_headers(protected_keys: []) ⇒ Hash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns The encoded HTTP request headers.

Parameters:

  • protected_keys (Array<String>) (defaults to: [])

    Header keys set by the SDK client (e.g. auth, metadata) that must not be overridden by additional_headers from request_options.

Returns:

  • (Hash)

    The encoded HTTP request headers.



26
27
28
29
30
31
32
# File 'lib/vapi/internal/json/request.rb', line 26

def encode_headers(protected_keys: [])
  sdk_headers = {
    "Content-Type" => "application/json",
    "Accept" => "application/json"
  }.merge(@headers)
  merge_additional_headers(sdk_headers, protected_keys:)
end