export type GetApiV1RideSegmentsArgs = {duration: number, isPersonalRecord?: boolean | undefined, fromDate?: string | undefined, toDate?: string | undefined, page: number, limit: number}; export type GetApiV1RideSegmentsOptions = {baseUrl: string, bearer?: string | undefined, fetch?: typeof fetch | undefined}; /** * GET /v1/ride-segments */ export const getApiV1RideSegments = async (args: GetApiV1RideSegmentsArgs, options: GetApiV1RideSegmentsOptions) => { const {baseUrl, fetch: fetchFn = fetch, bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.duration != null) query.append("duration", String(args.duration)) if (args.isPersonalRecord != null) query.append("isPersonalRecord", String(args.isPersonalRecord)) if (args.fromDate != null) query.append("fromDate", String(args.fromDate)) if (args.toDate != null) query.append("toDate", String(args.toDate)) if (args.page != null) query.append("page", String(args.page)) if (args.limit != null) query.append("limit", String(args.limit)) if (bearer !== undefined) headers.set('authorization', `Bearer ${bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/ride-segments${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };