Method: X::RequestBuilder#build

Defined in:
lib/x/request_builder.rb

#build(http_method:, uri:, body: nil, headers: {}, authenticator: Authenticator.new) ⇒ Net::HTTPRequest

Build an HTTP request

Examples:

Build a GET request

builder.build(http_method: :get, uri: URI("https://api.x.com/2/users/me"))

Parameters:

  • http_method (Symbol)

    the HTTP method (:get, :post, :put, :delete)

  • uri (URI)

    the request URI

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

    the request body

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

    additional headers for the request

  • authenticator (Authenticator) (defaults to: Authenticator.new)

    the authenticator for the request

Returns:

  • (Net::HTTPRequest)

    the built HTTP request

Raises:

  • (ArgumentError)

    if the HTTP method is not supported



35
36
37
38
39
40
# File 'lib/x/request_builder.rb', line 35

def build(http_method:, uri:, body: nil, headers: {}, authenticator: Authenticator.new)
  request = create_request(http_method:, uri:, body:)
  add_headers(request:, headers:)
  add_authentication(request:, authenticator:)
  request
end