Class: Payabli::Internal::JSON::Request Private

Inherits:
Http::BaseRequest show all
Defined in:
lib/payabli/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, omit_content_type_without_body: false, 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)

  • omit_content_type_without_body (Boolean) (defaults to: false)

    When true and no body is present, the Content-Type header is omitted (used for endpoints whose request body is optional)

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


19
20
21
22
23
24
# File 'lib/payabli/internal/json/request.rb', line 19

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

  @body = body
  @omit_content_type_without_body = omit_content_type_without_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/payabli/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.



37
38
39
# File 'lib/payabli/internal/json/request.rb', line 37

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.



29
30
31
32
33
34
# File 'lib/payabli/internal/json/request.rb', line 29

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