Duffel.Cars.SearchParams (Duffel v0.1.0)

Copy Markdown View Source

Build the request body for Duffel.Cars.Search.create/3.

new/1 assembles the params map and checks the required fields are present. driver/1, at_airport/1 and at_coordinates/2 build the nested driver and location values.

params =
  Duffel.Cars.SearchParams.new(
    driver: Duffel.Cars.SearchParams.driver(age: 30),
    pickup_date: "2026-07-01",
    pickup_time: "10:00",
    pickup_location: Duffel.Cars.SearchParams.at_airport("LHR"),
    dropoff_date: "2026-07-03",
    dropoff_time: "10:00",
    dropoff_location: Duffel.Cars.SearchParams.at_airport("LHR")
  )

Duffel.Cars.Search.create(client, params)

Using the builder is optional — create/3 still accepts a plain map.

Summary

Functions

Builds a pickup or dropoff location at an airport by IATA code.

Builds a pickup or dropoff location at geographic coordinates.

Builds a driver value for a search. Accepts :age and :residence_country_code; absent fields are omitted.

Builds a cars search params map.

Functions

at_airport(iata_code)

@spec at_airport(String.t()) :: map()

Builds a pickup or dropoff location at an airport by IATA code.

at_coordinates(latitude, longitude)

@spec at_coordinates(number(), number()) :: map()

Builds a pickup or dropoff location at geographic coordinates.

driver(opts \\ [])

@spec driver(keyword()) :: map()

Builds a driver value for a search. Accepts :age and :residence_country_code; absent fields are omitted.

A search driver only describes who is renting, because age and country of residence change which rates a supplier offers. The driver on a booking is a different shape (name, email, phone number, date of birth) and is passed straight to Duffel.Cars.Bookings.create/3.

Examples

Duffel.Cars.SearchParams.driver(age: 30, residence_country_code: "GB")

new(opts)

@spec new(keyword()) :: map()

Builds a cars search params map.

All of :driver, :pickup_date, :pickup_time, :pickup_location, :dropoff_date, :dropoff_time and :dropoff_location are required. Dates are YYYY-MM-DD and times are HH:MM. Raises ArgumentError if a required option is missing.