Module: HTTPartyCurl::Logger::ClassMethods

Defined in:
lib/httparty_curl/logger.rb

Overview

Class methods added to the including class.

Constant Summary collapse

HTTP_METHODS =

List of HTTP methods to override with logging functionality.

%i[get post put patch delete].freeze

Instance Method Summary collapse

Instance Method Details

#to_curl(method, uri, options = {}) ⇒ String

Converts an HTTParty request to a cURL command.

Parameters:

  • method (Symbol)

    the HTTP method (e.g., :get, :post).

  • uri (String)

    the request URI.

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

    the request options (headers, body, etc.).

Returns:

  • (String)

    the generated cURL command.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/httparty_curl/logger.rb', line 36

def to_curl(method, uri, options = {})
  options ||= {}

  # Prepare the URI and append query parameters if present
  uri = prepare_uri(uri, options[:query])

  curl_command = initialize_curl_command(method, uri)

  # Add proxy settings if available
  add_proxy_settings(curl_command)

  # Add headers to the cURL command
  add_headers(curl_command, options[:headers])

  # Add authentication to the cURL command
  add_authentication(curl_command, options[:basic_auth], options[:digest_auth])

  # Add body data to the cURL command
  add_body_data(curl_command, options[:body], options[:headers])

  curl_command.join(" \\\n")
end