train-travel 0.0.7__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. train_travel/__init__.py +17 -0
  2. train_travel/_hooks/__init__.py +6 -0
  3. train_travel/_hooks/oauth2scopes.py +16 -0
  4. train_travel/_hooks/registration.py +13 -0
  5. train_travel/_hooks/sdkhooks.py +76 -0
  6. train_travel/_hooks/types.py +112 -0
  7. train_travel/_version.py +15 -0
  8. train_travel/basesdk.py +388 -0
  9. train_travel/bookings.py +1190 -0
  10. train_travel/errors/__init__.py +63 -0
  11. train_travel/errors/no_response_error.py +17 -0
  12. train_travel/errors/responsevalidationerror.py +27 -0
  13. train_travel/errors/traintraveldefaulterror.py +40 -0
  14. train_travel/errors/traintravelerror.py +30 -0
  15. train_travel/httpclient.py +125 -0
  16. train_travel/models/__init__.py +416 -0
  17. train_travel/models/booking.py +59 -0
  18. train_travel/models/booking_input.py +52 -0
  19. train_travel/models/bookingpayment.py +221 -0
  20. train_travel/models/create_booking_paymentop.py +269 -0
  21. train_travel/models/create_booking_rawop.py +144 -0
  22. train_travel/models/create_bookingop.py +144 -0
  23. train_travel/models/delete_bookingop.py +30 -0
  24. train_travel/models/get_bookingop.py +159 -0
  25. train_travel/models/get_bookingsop.py +198 -0
  26. train_travel/models/get_stationsop.py +230 -0
  27. train_travel/models/get_tripsop.py +324 -0
  28. train_travel/models/links_booking.py +35 -0
  29. train_travel/models/links_self.py +36 -0
  30. train_travel/models/new_bookingop.py +92 -0
  31. train_travel/models/security.py +39 -0
  32. train_travel/models/station.py +57 -0
  33. train_travel/models/trip.py +90 -0
  34. train_travel/payments.py +262 -0
  35. train_travel/py.typed +1 -0
  36. train_travel/sdk.py +213 -0
  37. train_travel/sdkconfiguration.py +51 -0
  38. train_travel/stations.py +284 -0
  39. train_travel/trips.py +291 -0
  40. train_travel/types/__init__.py +21 -0
  41. train_travel/types/basemodel.py +77 -0
  42. train_travel/utils/__init__.py +206 -0
  43. train_travel/utils/annotations.py +79 -0
  44. train_travel/utils/datetimes.py +23 -0
  45. train_travel/utils/enums.py +134 -0
  46. train_travel/utils/eventstreaming.py +248 -0
  47. train_travel/utils/forms.py +234 -0
  48. train_travel/utils/headers.py +136 -0
  49. train_travel/utils/logger.py +27 -0
  50. train_travel/utils/metadata.py +118 -0
  51. train_travel/utils/queryparams.py +217 -0
  52. train_travel/utils/requestbodies.py +66 -0
  53. train_travel/utils/retries.py +281 -0
  54. train_travel/utils/security.py +192 -0
  55. train_travel/utils/serializers.py +229 -0
  56. train_travel/utils/unmarshal_json_response.py +38 -0
  57. train_travel/utils/url.py +155 -0
  58. train_travel/utils/values.py +137 -0
  59. train_travel-0.0.7.dist-info/METADATA +567 -0
  60. train_travel-0.0.7.dist-info/RECORD +62 -0
  61. train_travel-0.0.7.dist-info/WHEEL +5 -0
  62. train_travel-0.0.7.dist-info/top_level.txt +1 -0
@@ -0,0 +1,1190 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+
3
+ from .basesdk import BaseSDK
4
+ from enum import Enum
5
+ import io
6
+ from train_travel import errors, models, utils
7
+ from train_travel._hooks import HookContext
8
+ from train_travel.types import OptionalNullable, UNSET
9
+ from train_travel.utils import get_security_from_env
10
+ from train_travel.utils.unmarshal_json_response import unmarshal_json_response
11
+ from typing import IO, Mapping, Optional, Union
12
+
13
+
14
+ class GetBookingsAcceptEnum(str, Enum):
15
+ APPLICATION_JSON = "application/json"
16
+ APPLICATION_XML = "application/xml"
17
+
18
+
19
+ class CreateBookingAcceptEnum(str, Enum):
20
+ APPLICATION_JSON = "application/json"
21
+ APPLICATION_XML = "application/xml"
22
+
23
+
24
+ class CreateBookingRawAcceptEnum(str, Enum):
25
+ APPLICATION_JSON = "application/json"
26
+ APPLICATION_XML = "application/xml"
27
+
28
+
29
+ class GetBookingAcceptEnum(str, Enum):
30
+ APPLICATION_JSON = "application/json"
31
+ APPLICATION_XML = "application/xml"
32
+
33
+
34
+ class Bookings(BaseSDK):
35
+ r"""Create and manage bookings for train trips, including passenger details
36
+ and optional extras.
37
+
38
+ """
39
+
40
+ def get_bookings(
41
+ self,
42
+ *,
43
+ page: Optional[int] = 1,
44
+ limit: Optional[int] = 10,
45
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
46
+ server_url: Optional[str] = None,
47
+ timeout_ms: Optional[int] = None,
48
+ accept_header_override: Optional[GetBookingsAcceptEnum] = None,
49
+ http_headers: Optional[Mapping[str, str]] = None,
50
+ ) -> models.GetBookingsResponse:
51
+ r"""List existing bookings
52
+
53
+ Returns a list of all trip bookings by the authenticated user.
54
+
55
+ :param page: The page number to return
56
+ :param limit: The number of items to return per page
57
+ :param retries: Override the default retry configuration for this method
58
+ :param server_url: Override the default server URL for this method
59
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
60
+ :param accept_header_override: Override the default accept header for this method
61
+ :param http_headers: Additional headers to set or replace on requests.
62
+ """
63
+ base_url = None
64
+ url_variables = None
65
+ if timeout_ms is None:
66
+ timeout_ms = self.sdk_configuration.timeout_ms
67
+
68
+ if server_url is not None:
69
+ base_url = server_url
70
+ else:
71
+ base_url = self._get_url(base_url, url_variables)
72
+
73
+ request = models.GetBookingsRequest(
74
+ page=page,
75
+ limit=limit,
76
+ )
77
+
78
+ req = self._build_request(
79
+ method="GET",
80
+ path="/bookings",
81
+ base_url=base_url,
82
+ url_variables=url_variables,
83
+ request=request,
84
+ request_body_required=False,
85
+ request_has_path_params=False,
86
+ request_has_query_params=True,
87
+ user_agent_header="user-agent",
88
+ accept_header_value=accept_header_override.value
89
+ if accept_header_override is not None
90
+ else "application/json;q=1, application/xml;q=0",
91
+ http_headers=http_headers,
92
+ security=self.sdk_configuration.security,
93
+ allow_empty_value=None,
94
+ timeout_ms=timeout_ms,
95
+ )
96
+
97
+ if retries == UNSET:
98
+ if self.sdk_configuration.retry_config is not UNSET:
99
+ retries = self.sdk_configuration.retry_config
100
+ else:
101
+ retries = utils.RetryConfig(
102
+ "backoff", utils.BackoffStrategy(500, 60000, 1.5, 3600000), True
103
+ )
104
+
105
+ retry_config = None
106
+ if isinstance(retries, utils.RetryConfig):
107
+ retry_config = (retries, ["5XX"])
108
+
109
+ http_res = self.do_request(
110
+ hook_ctx=HookContext(
111
+ config=self.sdk_configuration,
112
+ base_url=base_url or "",
113
+ operation_id="get-bookings",
114
+ oauth2_scopes=None,
115
+ security_source=get_security_from_env(
116
+ self.sdk_configuration.security, models.Security
117
+ ),
118
+ ),
119
+ request=req,
120
+ error_status_codes=["400", "401", "403", "429", "4XX", "500", "5XX"],
121
+ retry_config=retry_config,
122
+ )
123
+
124
+ if utils.match_response(http_res, "200", "application/json"):
125
+ return models.GetBookingsResponse(
126
+ result=unmarshal_json_response(
127
+ models.GetBookingsResponseBody, http_res
128
+ ),
129
+ headers=utils.get_response_headers(http_res.headers),
130
+ )
131
+ if utils.match_response(http_res, "200", "application/xml"):
132
+ http_res_bytes = utils.stream_to_bytes(http_res)
133
+ return models.GetBookingsResponse(
134
+ result=http_res_bytes,
135
+ headers=utils.get_response_headers(http_res.headers),
136
+ )
137
+ if utils.match_response(http_res, ["400", "401", "403", "429"], "*"):
138
+ http_res_text = utils.stream_to_text(http_res)
139
+ raise errors.TrainTravelDefaultError(
140
+ "API error occurred", http_res, http_res_text
141
+ )
142
+ if utils.match_response(http_res, "500", "*"):
143
+ http_res_text = utils.stream_to_text(http_res)
144
+ raise errors.TrainTravelDefaultError(
145
+ "API error occurred", http_res, http_res_text
146
+ )
147
+ if utils.match_response(http_res, "4XX", "*"):
148
+ http_res_text = utils.stream_to_text(http_res)
149
+ raise errors.TrainTravelDefaultError(
150
+ "API error occurred", http_res, http_res_text
151
+ )
152
+ if utils.match_response(http_res, "5XX", "*"):
153
+ http_res_text = utils.stream_to_text(http_res)
154
+ raise errors.TrainTravelDefaultError(
155
+ "API error occurred", http_res, http_res_text
156
+ )
157
+
158
+ raise errors.TrainTravelDefaultError("Unexpected response received", http_res)
159
+
160
+ async def get_bookings_async(
161
+ self,
162
+ *,
163
+ page: Optional[int] = 1,
164
+ limit: Optional[int] = 10,
165
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
166
+ server_url: Optional[str] = None,
167
+ timeout_ms: Optional[int] = None,
168
+ accept_header_override: Optional[GetBookingsAcceptEnum] = None,
169
+ http_headers: Optional[Mapping[str, str]] = None,
170
+ ) -> models.GetBookingsResponse:
171
+ r"""List existing bookings
172
+
173
+ Returns a list of all trip bookings by the authenticated user.
174
+
175
+ :param page: The page number to return
176
+ :param limit: The number of items to return per page
177
+ :param retries: Override the default retry configuration for this method
178
+ :param server_url: Override the default server URL for this method
179
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
180
+ :param accept_header_override: Override the default accept header for this method
181
+ :param http_headers: Additional headers to set or replace on requests.
182
+ """
183
+ base_url = None
184
+ url_variables = None
185
+ if timeout_ms is None:
186
+ timeout_ms = self.sdk_configuration.timeout_ms
187
+
188
+ if server_url is not None:
189
+ base_url = server_url
190
+ else:
191
+ base_url = self._get_url(base_url, url_variables)
192
+
193
+ request = models.GetBookingsRequest(
194
+ page=page,
195
+ limit=limit,
196
+ )
197
+
198
+ req = self._build_request_async(
199
+ method="GET",
200
+ path="/bookings",
201
+ base_url=base_url,
202
+ url_variables=url_variables,
203
+ request=request,
204
+ request_body_required=False,
205
+ request_has_path_params=False,
206
+ request_has_query_params=True,
207
+ user_agent_header="user-agent",
208
+ accept_header_value=accept_header_override.value
209
+ if accept_header_override is not None
210
+ else "application/json;q=1, application/xml;q=0",
211
+ http_headers=http_headers,
212
+ security=self.sdk_configuration.security,
213
+ allow_empty_value=None,
214
+ timeout_ms=timeout_ms,
215
+ )
216
+
217
+ if retries == UNSET:
218
+ if self.sdk_configuration.retry_config is not UNSET:
219
+ retries = self.sdk_configuration.retry_config
220
+ else:
221
+ retries = utils.RetryConfig(
222
+ "backoff", utils.BackoffStrategy(500, 60000, 1.5, 3600000), True
223
+ )
224
+
225
+ retry_config = None
226
+ if isinstance(retries, utils.RetryConfig):
227
+ retry_config = (retries, ["5XX"])
228
+
229
+ http_res = await self.do_request_async(
230
+ hook_ctx=HookContext(
231
+ config=self.sdk_configuration,
232
+ base_url=base_url or "",
233
+ operation_id="get-bookings",
234
+ oauth2_scopes=None,
235
+ security_source=get_security_from_env(
236
+ self.sdk_configuration.security, models.Security
237
+ ),
238
+ ),
239
+ request=req,
240
+ error_status_codes=["400", "401", "403", "429", "4XX", "500", "5XX"],
241
+ retry_config=retry_config,
242
+ )
243
+
244
+ if utils.match_response(http_res, "200", "application/json"):
245
+ return models.GetBookingsResponse(
246
+ result=unmarshal_json_response(
247
+ models.GetBookingsResponseBody, http_res
248
+ ),
249
+ headers=utils.get_response_headers(http_res.headers),
250
+ )
251
+ if utils.match_response(http_res, "200", "application/xml"):
252
+ http_res_bytes = await utils.stream_to_bytes_async(http_res)
253
+ return models.GetBookingsResponse(
254
+ result=http_res_bytes,
255
+ headers=utils.get_response_headers(http_res.headers),
256
+ )
257
+ if utils.match_response(http_res, ["400", "401", "403", "429"], "*"):
258
+ http_res_text = await utils.stream_to_text_async(http_res)
259
+ raise errors.TrainTravelDefaultError(
260
+ "API error occurred", http_res, http_res_text
261
+ )
262
+ if utils.match_response(http_res, "500", "*"):
263
+ http_res_text = await utils.stream_to_text_async(http_res)
264
+ raise errors.TrainTravelDefaultError(
265
+ "API error occurred", http_res, http_res_text
266
+ )
267
+ if utils.match_response(http_res, "4XX", "*"):
268
+ http_res_text = await utils.stream_to_text_async(http_res)
269
+ raise errors.TrainTravelDefaultError(
270
+ "API error occurred", http_res, http_res_text
271
+ )
272
+ if utils.match_response(http_res, "5XX", "*"):
273
+ http_res_text = await utils.stream_to_text_async(http_res)
274
+ raise errors.TrainTravelDefaultError(
275
+ "API error occurred", http_res, http_res_text
276
+ )
277
+
278
+ raise errors.TrainTravelDefaultError("Unexpected response received", http_res)
279
+
280
+ def create_booking(
281
+ self,
282
+ *,
283
+ trip_id: Optional[str] = None,
284
+ passenger_name: Optional[str] = None,
285
+ has_bicycle: Optional[bool] = None,
286
+ has_dog: Optional[bool] = None,
287
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
288
+ server_url: Optional[str] = None,
289
+ timeout_ms: Optional[int] = None,
290
+ accept_header_override: Optional[CreateBookingAcceptEnum] = None,
291
+ http_headers: Optional[Mapping[str, str]] = None,
292
+ ) -> models.CreateBookingResponse:
293
+ r"""Create a booking
294
+
295
+ A booking is a temporary hold on a trip. It is not confirmed until the payment is processed.
296
+
297
+ :param trip_id: Identifier of the booked trip
298
+ :param passenger_name: Name of the passenger
299
+ :param has_bicycle: Indicates whether the passenger has a bicycle.
300
+ :param has_dog: Indicates whether the passenger has a dog.
301
+ :param retries: Override the default retry configuration for this method
302
+ :param server_url: Override the default server URL for this method
303
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
304
+ :param accept_header_override: Override the default accept header for this method
305
+ :param http_headers: Additional headers to set or replace on requests.
306
+ """
307
+ base_url = None
308
+ url_variables = None
309
+ if timeout_ms is None:
310
+ timeout_ms = self.sdk_configuration.timeout_ms
311
+
312
+ if server_url is not None:
313
+ base_url = server_url
314
+ else:
315
+ base_url = self._get_url(base_url, url_variables)
316
+
317
+ request = models.BookingInput(
318
+ trip_id=trip_id,
319
+ passenger_name=passenger_name,
320
+ has_bicycle=has_bicycle,
321
+ has_dog=has_dog,
322
+ )
323
+
324
+ req = self._build_request(
325
+ method="POST",
326
+ path="/bookings",
327
+ base_url=base_url,
328
+ url_variables=url_variables,
329
+ request=request,
330
+ request_body_required=True,
331
+ request_has_path_params=False,
332
+ request_has_query_params=True,
333
+ user_agent_header="user-agent",
334
+ accept_header_value=accept_header_override.value
335
+ if accept_header_override is not None
336
+ else "application/json;q=1, application/xml;q=0",
337
+ http_headers=http_headers,
338
+ security=self.sdk_configuration.security,
339
+ get_serialized_body=lambda: utils.serialize_request_body(
340
+ request, False, False, "json", models.BookingInput
341
+ ),
342
+ allow_empty_value=None,
343
+ timeout_ms=timeout_ms,
344
+ )
345
+
346
+ if retries == UNSET:
347
+ if self.sdk_configuration.retry_config is not UNSET:
348
+ retries = self.sdk_configuration.retry_config
349
+ else:
350
+ retries = utils.RetryConfig(
351
+ "backoff", utils.BackoffStrategy(500, 60000, 1.5, 3600000), True
352
+ )
353
+
354
+ retry_config = None
355
+ if isinstance(retries, utils.RetryConfig):
356
+ retry_config = (retries, ["5XX"])
357
+
358
+ http_res = self.do_request(
359
+ hook_ctx=HookContext(
360
+ config=self.sdk_configuration,
361
+ base_url=base_url or "",
362
+ operation_id="create-booking",
363
+ oauth2_scopes=None,
364
+ security_source=get_security_from_env(
365
+ self.sdk_configuration.security, models.Security
366
+ ),
367
+ ),
368
+ request=req,
369
+ error_status_codes=["400", "401", "404", "409", "429", "4XX", "500", "5XX"],
370
+ retry_config=retry_config,
371
+ )
372
+
373
+ if utils.match_response(http_res, "201", "application/json"):
374
+ return models.CreateBookingResponse(
375
+ result=unmarshal_json_response(
376
+ models.CreateBookingResponseBody, http_res
377
+ ),
378
+ headers={},
379
+ )
380
+ if utils.match_response(http_res, "201", "application/xml"):
381
+ http_res_bytes = utils.stream_to_bytes(http_res)
382
+ return models.CreateBookingResponse(result=http_res_bytes, headers={})
383
+ if utils.match_response(http_res, ["400", "401", "404", "409", "429"], "*"):
384
+ http_res_text = utils.stream_to_text(http_res)
385
+ raise errors.TrainTravelDefaultError(
386
+ "API error occurred", http_res, http_res_text
387
+ )
388
+ if utils.match_response(http_res, "500", "*"):
389
+ http_res_text = utils.stream_to_text(http_res)
390
+ raise errors.TrainTravelDefaultError(
391
+ "API error occurred", http_res, http_res_text
392
+ )
393
+ if utils.match_response(http_res, "4XX", "*"):
394
+ http_res_text = utils.stream_to_text(http_res)
395
+ raise errors.TrainTravelDefaultError(
396
+ "API error occurred", http_res, http_res_text
397
+ )
398
+ if utils.match_response(http_res, "5XX", "*"):
399
+ http_res_text = utils.stream_to_text(http_res)
400
+ raise errors.TrainTravelDefaultError(
401
+ "API error occurred", http_res, http_res_text
402
+ )
403
+
404
+ raise errors.TrainTravelDefaultError("Unexpected response received", http_res)
405
+
406
+ async def create_booking_async(
407
+ self,
408
+ *,
409
+ trip_id: Optional[str] = None,
410
+ passenger_name: Optional[str] = None,
411
+ has_bicycle: Optional[bool] = None,
412
+ has_dog: Optional[bool] = None,
413
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
414
+ server_url: Optional[str] = None,
415
+ timeout_ms: Optional[int] = None,
416
+ accept_header_override: Optional[CreateBookingAcceptEnum] = None,
417
+ http_headers: Optional[Mapping[str, str]] = None,
418
+ ) -> models.CreateBookingResponse:
419
+ r"""Create a booking
420
+
421
+ A booking is a temporary hold on a trip. It is not confirmed until the payment is processed.
422
+
423
+ :param trip_id: Identifier of the booked trip
424
+ :param passenger_name: Name of the passenger
425
+ :param has_bicycle: Indicates whether the passenger has a bicycle.
426
+ :param has_dog: Indicates whether the passenger has a dog.
427
+ :param retries: Override the default retry configuration for this method
428
+ :param server_url: Override the default server URL for this method
429
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
430
+ :param accept_header_override: Override the default accept header for this method
431
+ :param http_headers: Additional headers to set or replace on requests.
432
+ """
433
+ base_url = None
434
+ url_variables = None
435
+ if timeout_ms is None:
436
+ timeout_ms = self.sdk_configuration.timeout_ms
437
+
438
+ if server_url is not None:
439
+ base_url = server_url
440
+ else:
441
+ base_url = self._get_url(base_url, url_variables)
442
+
443
+ request = models.BookingInput(
444
+ trip_id=trip_id,
445
+ passenger_name=passenger_name,
446
+ has_bicycle=has_bicycle,
447
+ has_dog=has_dog,
448
+ )
449
+
450
+ req = self._build_request_async(
451
+ method="POST",
452
+ path="/bookings",
453
+ base_url=base_url,
454
+ url_variables=url_variables,
455
+ request=request,
456
+ request_body_required=True,
457
+ request_has_path_params=False,
458
+ request_has_query_params=True,
459
+ user_agent_header="user-agent",
460
+ accept_header_value=accept_header_override.value
461
+ if accept_header_override is not None
462
+ else "application/json;q=1, application/xml;q=0",
463
+ http_headers=http_headers,
464
+ security=self.sdk_configuration.security,
465
+ get_serialized_body=lambda: utils.serialize_request_body(
466
+ request, False, False, "json", models.BookingInput
467
+ ),
468
+ allow_empty_value=None,
469
+ timeout_ms=timeout_ms,
470
+ )
471
+
472
+ if retries == UNSET:
473
+ if self.sdk_configuration.retry_config is not UNSET:
474
+ retries = self.sdk_configuration.retry_config
475
+ else:
476
+ retries = utils.RetryConfig(
477
+ "backoff", utils.BackoffStrategy(500, 60000, 1.5, 3600000), True
478
+ )
479
+
480
+ retry_config = None
481
+ if isinstance(retries, utils.RetryConfig):
482
+ retry_config = (retries, ["5XX"])
483
+
484
+ http_res = await self.do_request_async(
485
+ hook_ctx=HookContext(
486
+ config=self.sdk_configuration,
487
+ base_url=base_url or "",
488
+ operation_id="create-booking",
489
+ oauth2_scopes=None,
490
+ security_source=get_security_from_env(
491
+ self.sdk_configuration.security, models.Security
492
+ ),
493
+ ),
494
+ request=req,
495
+ error_status_codes=["400", "401", "404", "409", "429", "4XX", "500", "5XX"],
496
+ retry_config=retry_config,
497
+ )
498
+
499
+ if utils.match_response(http_res, "201", "application/json"):
500
+ return models.CreateBookingResponse(
501
+ result=unmarshal_json_response(
502
+ models.CreateBookingResponseBody, http_res
503
+ ),
504
+ headers={},
505
+ )
506
+ if utils.match_response(http_res, "201", "application/xml"):
507
+ http_res_bytes = await utils.stream_to_bytes_async(http_res)
508
+ return models.CreateBookingResponse(result=http_res_bytes, headers={})
509
+ if utils.match_response(http_res, ["400", "401", "404", "409", "429"], "*"):
510
+ http_res_text = await utils.stream_to_text_async(http_res)
511
+ raise errors.TrainTravelDefaultError(
512
+ "API error occurred", http_res, http_res_text
513
+ )
514
+ if utils.match_response(http_res, "500", "*"):
515
+ http_res_text = await utils.stream_to_text_async(http_res)
516
+ raise errors.TrainTravelDefaultError(
517
+ "API error occurred", http_res, http_res_text
518
+ )
519
+ if utils.match_response(http_res, "4XX", "*"):
520
+ http_res_text = await utils.stream_to_text_async(http_res)
521
+ raise errors.TrainTravelDefaultError(
522
+ "API error occurred", http_res, http_res_text
523
+ )
524
+ if utils.match_response(http_res, "5XX", "*"):
525
+ http_res_text = await utils.stream_to_text_async(http_res)
526
+ raise errors.TrainTravelDefaultError(
527
+ "API error occurred", http_res, http_res_text
528
+ )
529
+
530
+ raise errors.TrainTravelDefaultError("Unexpected response received", http_res)
531
+
532
+ def create_booking_raw(
533
+ self,
534
+ *,
535
+ request: Union[bytes, IO[bytes], io.BufferedReader],
536
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
537
+ server_url: Optional[str] = None,
538
+ timeout_ms: Optional[int] = None,
539
+ accept_header_override: Optional[CreateBookingRawAcceptEnum] = None,
540
+ http_headers: Optional[Mapping[str, str]] = None,
541
+ ) -> models.CreateBookingRawResponse:
542
+ r"""Create a booking
543
+
544
+ A booking is a temporary hold on a trip. It is not confirmed until the payment is processed.
545
+
546
+ :param request: The request object to send.
547
+ :param retries: Override the default retry configuration for this method
548
+ :param server_url: Override the default server URL for this method
549
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
550
+ :param accept_header_override: Override the default accept header for this method
551
+ :param http_headers: Additional headers to set or replace on requests.
552
+ """
553
+ base_url = None
554
+ url_variables = None
555
+ if timeout_ms is None:
556
+ timeout_ms = self.sdk_configuration.timeout_ms
557
+
558
+ if server_url is not None:
559
+ base_url = server_url
560
+ else:
561
+ base_url = self._get_url(base_url, url_variables)
562
+
563
+ req = self._build_request(
564
+ method="POST",
565
+ path="/bookings",
566
+ base_url=base_url,
567
+ url_variables=url_variables,
568
+ request=request,
569
+ request_body_required=True,
570
+ request_has_path_params=False,
571
+ request_has_query_params=True,
572
+ user_agent_header="user-agent",
573
+ accept_header_value=accept_header_override.value
574
+ if accept_header_override is not None
575
+ else "application/json;q=1, application/xml;q=0",
576
+ http_headers=http_headers,
577
+ security=self.sdk_configuration.security,
578
+ get_serialized_body=lambda: utils.serialize_request_body(
579
+ request, False, False, "raw", Union[bytes, IO[bytes], io.BufferedReader]
580
+ ),
581
+ allow_empty_value=None,
582
+ timeout_ms=timeout_ms,
583
+ )
584
+
585
+ if retries == UNSET:
586
+ if self.sdk_configuration.retry_config is not UNSET:
587
+ retries = self.sdk_configuration.retry_config
588
+ else:
589
+ retries = utils.RetryConfig(
590
+ "backoff", utils.BackoffStrategy(500, 60000, 1.5, 3600000), True
591
+ )
592
+
593
+ retry_config = None
594
+ if isinstance(retries, utils.RetryConfig):
595
+ retry_config = (retries, ["5XX"])
596
+
597
+ http_res = self.do_request(
598
+ hook_ctx=HookContext(
599
+ config=self.sdk_configuration,
600
+ base_url=base_url or "",
601
+ operation_id="create-booking_raw",
602
+ oauth2_scopes=None,
603
+ security_source=get_security_from_env(
604
+ self.sdk_configuration.security, models.Security
605
+ ),
606
+ ),
607
+ request=req,
608
+ error_status_codes=["400", "401", "404", "409", "429", "4XX", "500", "5XX"],
609
+ retry_config=retry_config,
610
+ )
611
+
612
+ if utils.match_response(http_res, "201", "application/json"):
613
+ return models.CreateBookingRawResponse(
614
+ result=unmarshal_json_response(
615
+ models.CreateBookingRawResponseBody, http_res
616
+ ),
617
+ headers={},
618
+ )
619
+ if utils.match_response(http_res, "201", "application/xml"):
620
+ http_res_bytes = utils.stream_to_bytes(http_res)
621
+ return models.CreateBookingRawResponse(result=http_res_bytes, headers={})
622
+ if utils.match_response(http_res, ["400", "401", "404", "409", "429"], "*"):
623
+ http_res_text = utils.stream_to_text(http_res)
624
+ raise errors.TrainTravelDefaultError(
625
+ "API error occurred", http_res, http_res_text
626
+ )
627
+ if utils.match_response(http_res, "500", "*"):
628
+ http_res_text = utils.stream_to_text(http_res)
629
+ raise errors.TrainTravelDefaultError(
630
+ "API error occurred", http_res, http_res_text
631
+ )
632
+ if utils.match_response(http_res, "4XX", "*"):
633
+ http_res_text = utils.stream_to_text(http_res)
634
+ raise errors.TrainTravelDefaultError(
635
+ "API error occurred", http_res, http_res_text
636
+ )
637
+ if utils.match_response(http_res, "5XX", "*"):
638
+ http_res_text = utils.stream_to_text(http_res)
639
+ raise errors.TrainTravelDefaultError(
640
+ "API error occurred", http_res, http_res_text
641
+ )
642
+
643
+ raise errors.TrainTravelDefaultError("Unexpected response received", http_res)
644
+
645
+ async def create_booking_raw_async(
646
+ self,
647
+ *,
648
+ request: Union[bytes, IO[bytes], io.BufferedReader],
649
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
650
+ server_url: Optional[str] = None,
651
+ timeout_ms: Optional[int] = None,
652
+ accept_header_override: Optional[CreateBookingRawAcceptEnum] = None,
653
+ http_headers: Optional[Mapping[str, str]] = None,
654
+ ) -> models.CreateBookingRawResponse:
655
+ r"""Create a booking
656
+
657
+ A booking is a temporary hold on a trip. It is not confirmed until the payment is processed.
658
+
659
+ :param request: The request object to send.
660
+ :param retries: Override the default retry configuration for this method
661
+ :param server_url: Override the default server URL for this method
662
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
663
+ :param accept_header_override: Override the default accept header for this method
664
+ :param http_headers: Additional headers to set or replace on requests.
665
+ """
666
+ base_url = None
667
+ url_variables = None
668
+ if timeout_ms is None:
669
+ timeout_ms = self.sdk_configuration.timeout_ms
670
+
671
+ if server_url is not None:
672
+ base_url = server_url
673
+ else:
674
+ base_url = self._get_url(base_url, url_variables)
675
+
676
+ req = self._build_request_async(
677
+ method="POST",
678
+ path="/bookings",
679
+ base_url=base_url,
680
+ url_variables=url_variables,
681
+ request=request,
682
+ request_body_required=True,
683
+ request_has_path_params=False,
684
+ request_has_query_params=True,
685
+ user_agent_header="user-agent",
686
+ accept_header_value=accept_header_override.value
687
+ if accept_header_override is not None
688
+ else "application/json;q=1, application/xml;q=0",
689
+ http_headers=http_headers,
690
+ security=self.sdk_configuration.security,
691
+ get_serialized_body=lambda: utils.serialize_request_body(
692
+ request, False, False, "raw", Union[bytes, IO[bytes], io.BufferedReader]
693
+ ),
694
+ allow_empty_value=None,
695
+ timeout_ms=timeout_ms,
696
+ )
697
+
698
+ if retries == UNSET:
699
+ if self.sdk_configuration.retry_config is not UNSET:
700
+ retries = self.sdk_configuration.retry_config
701
+ else:
702
+ retries = utils.RetryConfig(
703
+ "backoff", utils.BackoffStrategy(500, 60000, 1.5, 3600000), True
704
+ )
705
+
706
+ retry_config = None
707
+ if isinstance(retries, utils.RetryConfig):
708
+ retry_config = (retries, ["5XX"])
709
+
710
+ http_res = await self.do_request_async(
711
+ hook_ctx=HookContext(
712
+ config=self.sdk_configuration,
713
+ base_url=base_url or "",
714
+ operation_id="create-booking_raw",
715
+ oauth2_scopes=None,
716
+ security_source=get_security_from_env(
717
+ self.sdk_configuration.security, models.Security
718
+ ),
719
+ ),
720
+ request=req,
721
+ error_status_codes=["400", "401", "404", "409", "429", "4XX", "500", "5XX"],
722
+ retry_config=retry_config,
723
+ )
724
+
725
+ if utils.match_response(http_res, "201", "application/json"):
726
+ return models.CreateBookingRawResponse(
727
+ result=unmarshal_json_response(
728
+ models.CreateBookingRawResponseBody, http_res
729
+ ),
730
+ headers={},
731
+ )
732
+ if utils.match_response(http_res, "201", "application/xml"):
733
+ http_res_bytes = await utils.stream_to_bytes_async(http_res)
734
+ return models.CreateBookingRawResponse(result=http_res_bytes, headers={})
735
+ if utils.match_response(http_res, ["400", "401", "404", "409", "429"], "*"):
736
+ http_res_text = await utils.stream_to_text_async(http_res)
737
+ raise errors.TrainTravelDefaultError(
738
+ "API error occurred", http_res, http_res_text
739
+ )
740
+ if utils.match_response(http_res, "500", "*"):
741
+ http_res_text = await utils.stream_to_text_async(http_res)
742
+ raise errors.TrainTravelDefaultError(
743
+ "API error occurred", http_res, http_res_text
744
+ )
745
+ if utils.match_response(http_res, "4XX", "*"):
746
+ http_res_text = await utils.stream_to_text_async(http_res)
747
+ raise errors.TrainTravelDefaultError(
748
+ "API error occurred", http_res, http_res_text
749
+ )
750
+ if utils.match_response(http_res, "5XX", "*"):
751
+ http_res_text = await utils.stream_to_text_async(http_res)
752
+ raise errors.TrainTravelDefaultError(
753
+ "API error occurred", http_res, http_res_text
754
+ )
755
+
756
+ raise errors.TrainTravelDefaultError("Unexpected response received", http_res)
757
+
758
+ def get_booking(
759
+ self,
760
+ *,
761
+ booking_id: str,
762
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
763
+ server_url: Optional[str] = None,
764
+ timeout_ms: Optional[int] = None,
765
+ accept_header_override: Optional[GetBookingAcceptEnum] = None,
766
+ http_headers: Optional[Mapping[str, str]] = None,
767
+ ) -> models.GetBookingResponse:
768
+ r"""Get a booking
769
+
770
+ Returns the details of a specific booking.
771
+
772
+ :param booking_id: The ID of the booking to retrieve.
773
+ :param retries: Override the default retry configuration for this method
774
+ :param server_url: Override the default server URL for this method
775
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
776
+ :param accept_header_override: Override the default accept header for this method
777
+ :param http_headers: Additional headers to set or replace on requests.
778
+ """
779
+ base_url = None
780
+ url_variables = None
781
+ if timeout_ms is None:
782
+ timeout_ms = self.sdk_configuration.timeout_ms
783
+
784
+ if server_url is not None:
785
+ base_url = server_url
786
+ else:
787
+ base_url = self._get_url(base_url, url_variables)
788
+
789
+ request = models.GetBookingRequest(
790
+ booking_id=booking_id,
791
+ )
792
+
793
+ req = self._build_request(
794
+ method="GET",
795
+ path="/bookings/{bookingId}",
796
+ base_url=base_url,
797
+ url_variables=url_variables,
798
+ request=request,
799
+ request_body_required=False,
800
+ request_has_path_params=True,
801
+ request_has_query_params=True,
802
+ user_agent_header="user-agent",
803
+ accept_header_value=accept_header_override.value
804
+ if accept_header_override is not None
805
+ else "application/json;q=1, application/xml;q=0",
806
+ http_headers=http_headers,
807
+ security=self.sdk_configuration.security,
808
+ allow_empty_value=None,
809
+ timeout_ms=timeout_ms,
810
+ )
811
+
812
+ if retries == UNSET:
813
+ if self.sdk_configuration.retry_config is not UNSET:
814
+ retries = self.sdk_configuration.retry_config
815
+ else:
816
+ retries = utils.RetryConfig(
817
+ "backoff", utils.BackoffStrategy(500, 60000, 1.5, 3600000), True
818
+ )
819
+
820
+ retry_config = None
821
+ if isinstance(retries, utils.RetryConfig):
822
+ retry_config = (retries, ["5XX"])
823
+
824
+ http_res = self.do_request(
825
+ hook_ctx=HookContext(
826
+ config=self.sdk_configuration,
827
+ base_url=base_url or "",
828
+ operation_id="get-booking",
829
+ oauth2_scopes=None,
830
+ security_source=get_security_from_env(
831
+ self.sdk_configuration.security, models.Security
832
+ ),
833
+ ),
834
+ request=req,
835
+ error_status_codes=["400", "401", "403", "404", "429", "4XX", "500", "5XX"],
836
+ retry_config=retry_config,
837
+ )
838
+
839
+ if utils.match_response(http_res, "200", "application/json"):
840
+ return models.GetBookingResponse(
841
+ result=unmarshal_json_response(models.GetBookingResponseBody, http_res),
842
+ headers=utils.get_response_headers(http_res.headers),
843
+ )
844
+ if utils.match_response(http_res, "200", "application/xml"):
845
+ http_res_bytes = utils.stream_to_bytes(http_res)
846
+ return models.GetBookingResponse(
847
+ result=http_res_bytes,
848
+ headers=utils.get_response_headers(http_res.headers),
849
+ )
850
+ if utils.match_response(http_res, ["400", "401", "403", "404", "429"], "*"):
851
+ http_res_text = utils.stream_to_text(http_res)
852
+ raise errors.TrainTravelDefaultError(
853
+ "API error occurred", http_res, http_res_text
854
+ )
855
+ if utils.match_response(http_res, "500", "*"):
856
+ http_res_text = utils.stream_to_text(http_res)
857
+ raise errors.TrainTravelDefaultError(
858
+ "API error occurred", http_res, http_res_text
859
+ )
860
+ if utils.match_response(http_res, "4XX", "*"):
861
+ http_res_text = utils.stream_to_text(http_res)
862
+ raise errors.TrainTravelDefaultError(
863
+ "API error occurred", http_res, http_res_text
864
+ )
865
+ if utils.match_response(http_res, "5XX", "*"):
866
+ http_res_text = utils.stream_to_text(http_res)
867
+ raise errors.TrainTravelDefaultError(
868
+ "API error occurred", http_res, http_res_text
869
+ )
870
+
871
+ raise errors.TrainTravelDefaultError("Unexpected response received", http_res)
872
+
873
+ async def get_booking_async(
874
+ self,
875
+ *,
876
+ booking_id: str,
877
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
878
+ server_url: Optional[str] = None,
879
+ timeout_ms: Optional[int] = None,
880
+ accept_header_override: Optional[GetBookingAcceptEnum] = None,
881
+ http_headers: Optional[Mapping[str, str]] = None,
882
+ ) -> models.GetBookingResponse:
883
+ r"""Get a booking
884
+
885
+ Returns the details of a specific booking.
886
+
887
+ :param booking_id: The ID of the booking to retrieve.
888
+ :param retries: Override the default retry configuration for this method
889
+ :param server_url: Override the default server URL for this method
890
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
891
+ :param accept_header_override: Override the default accept header for this method
892
+ :param http_headers: Additional headers to set or replace on requests.
893
+ """
894
+ base_url = None
895
+ url_variables = None
896
+ if timeout_ms is None:
897
+ timeout_ms = self.sdk_configuration.timeout_ms
898
+
899
+ if server_url is not None:
900
+ base_url = server_url
901
+ else:
902
+ base_url = self._get_url(base_url, url_variables)
903
+
904
+ request = models.GetBookingRequest(
905
+ booking_id=booking_id,
906
+ )
907
+
908
+ req = self._build_request_async(
909
+ method="GET",
910
+ path="/bookings/{bookingId}",
911
+ base_url=base_url,
912
+ url_variables=url_variables,
913
+ request=request,
914
+ request_body_required=False,
915
+ request_has_path_params=True,
916
+ request_has_query_params=True,
917
+ user_agent_header="user-agent",
918
+ accept_header_value=accept_header_override.value
919
+ if accept_header_override is not None
920
+ else "application/json;q=1, application/xml;q=0",
921
+ http_headers=http_headers,
922
+ security=self.sdk_configuration.security,
923
+ allow_empty_value=None,
924
+ timeout_ms=timeout_ms,
925
+ )
926
+
927
+ if retries == UNSET:
928
+ if self.sdk_configuration.retry_config is not UNSET:
929
+ retries = self.sdk_configuration.retry_config
930
+ else:
931
+ retries = utils.RetryConfig(
932
+ "backoff", utils.BackoffStrategy(500, 60000, 1.5, 3600000), True
933
+ )
934
+
935
+ retry_config = None
936
+ if isinstance(retries, utils.RetryConfig):
937
+ retry_config = (retries, ["5XX"])
938
+
939
+ http_res = await self.do_request_async(
940
+ hook_ctx=HookContext(
941
+ config=self.sdk_configuration,
942
+ base_url=base_url or "",
943
+ operation_id="get-booking",
944
+ oauth2_scopes=None,
945
+ security_source=get_security_from_env(
946
+ self.sdk_configuration.security, models.Security
947
+ ),
948
+ ),
949
+ request=req,
950
+ error_status_codes=["400", "401", "403", "404", "429", "4XX", "500", "5XX"],
951
+ retry_config=retry_config,
952
+ )
953
+
954
+ if utils.match_response(http_res, "200", "application/json"):
955
+ return models.GetBookingResponse(
956
+ result=unmarshal_json_response(models.GetBookingResponseBody, http_res),
957
+ headers=utils.get_response_headers(http_res.headers),
958
+ )
959
+ if utils.match_response(http_res, "200", "application/xml"):
960
+ http_res_bytes = await utils.stream_to_bytes_async(http_res)
961
+ return models.GetBookingResponse(
962
+ result=http_res_bytes,
963
+ headers=utils.get_response_headers(http_res.headers),
964
+ )
965
+ if utils.match_response(http_res, ["400", "401", "403", "404", "429"], "*"):
966
+ http_res_text = await utils.stream_to_text_async(http_res)
967
+ raise errors.TrainTravelDefaultError(
968
+ "API error occurred", http_res, http_res_text
969
+ )
970
+ if utils.match_response(http_res, "500", "*"):
971
+ http_res_text = await utils.stream_to_text_async(http_res)
972
+ raise errors.TrainTravelDefaultError(
973
+ "API error occurred", http_res, http_res_text
974
+ )
975
+ if utils.match_response(http_res, "4XX", "*"):
976
+ http_res_text = await utils.stream_to_text_async(http_res)
977
+ raise errors.TrainTravelDefaultError(
978
+ "API error occurred", http_res, http_res_text
979
+ )
980
+ if utils.match_response(http_res, "5XX", "*"):
981
+ http_res_text = await utils.stream_to_text_async(http_res)
982
+ raise errors.TrainTravelDefaultError(
983
+ "API error occurred", http_res, http_res_text
984
+ )
985
+
986
+ raise errors.TrainTravelDefaultError("Unexpected response received", http_res)
987
+
988
+ def delete_booking(
989
+ self,
990
+ *,
991
+ booking_id: str,
992
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
993
+ server_url: Optional[str] = None,
994
+ timeout_ms: Optional[int] = None,
995
+ http_headers: Optional[Mapping[str, str]] = None,
996
+ ) -> models.DeleteBookingResponse:
997
+ r"""Delete a booking
998
+
999
+ Deletes a booking, cancelling the hold on the trip.
1000
+
1001
+ :param booking_id: The ID of the booking to retrieve.
1002
+ :param retries: Override the default retry configuration for this method
1003
+ :param server_url: Override the default server URL for this method
1004
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
1005
+ :param http_headers: Additional headers to set or replace on requests.
1006
+ """
1007
+ base_url = None
1008
+ url_variables = None
1009
+ if timeout_ms is None:
1010
+ timeout_ms = self.sdk_configuration.timeout_ms
1011
+
1012
+ if server_url is not None:
1013
+ base_url = server_url
1014
+ else:
1015
+ base_url = self._get_url(base_url, url_variables)
1016
+
1017
+ request = models.DeleteBookingRequest(
1018
+ booking_id=booking_id,
1019
+ )
1020
+
1021
+ req = self._build_request(
1022
+ method="DELETE",
1023
+ path="/bookings/{bookingId}",
1024
+ base_url=base_url,
1025
+ url_variables=url_variables,
1026
+ request=request,
1027
+ request_body_required=False,
1028
+ request_has_path_params=True,
1029
+ request_has_query_params=True,
1030
+ user_agent_header="user-agent",
1031
+ accept_header_value="*/*",
1032
+ http_headers=http_headers,
1033
+ security=self.sdk_configuration.security,
1034
+ allow_empty_value=None,
1035
+ timeout_ms=timeout_ms,
1036
+ )
1037
+
1038
+ if retries == UNSET:
1039
+ if self.sdk_configuration.retry_config is not UNSET:
1040
+ retries = self.sdk_configuration.retry_config
1041
+ else:
1042
+ retries = utils.RetryConfig(
1043
+ "backoff", utils.BackoffStrategy(500, 60000, 1.5, 3600000), True
1044
+ )
1045
+
1046
+ retry_config = None
1047
+ if isinstance(retries, utils.RetryConfig):
1048
+ retry_config = (retries, ["5XX"])
1049
+
1050
+ http_res = self.do_request(
1051
+ hook_ctx=HookContext(
1052
+ config=self.sdk_configuration,
1053
+ base_url=base_url or "",
1054
+ operation_id="delete-booking",
1055
+ oauth2_scopes=None,
1056
+ security_source=get_security_from_env(
1057
+ self.sdk_configuration.security, models.Security
1058
+ ),
1059
+ ),
1060
+ request=req,
1061
+ error_status_codes=["400", "401", "403", "404", "429", "4XX", "500", "5XX"],
1062
+ retry_config=retry_config,
1063
+ )
1064
+
1065
+ if utils.match_response(http_res, "204", "*"):
1066
+ return models.DeleteBookingResponse(headers={})
1067
+ if utils.match_response(http_res, ["400", "401", "403", "404", "429"], "*"):
1068
+ http_res_text = utils.stream_to_text(http_res)
1069
+ raise errors.TrainTravelDefaultError(
1070
+ "API error occurred", http_res, http_res_text
1071
+ )
1072
+ if utils.match_response(http_res, "500", "*"):
1073
+ http_res_text = utils.stream_to_text(http_res)
1074
+ raise errors.TrainTravelDefaultError(
1075
+ "API error occurred", http_res, http_res_text
1076
+ )
1077
+ if utils.match_response(http_res, "4XX", "*"):
1078
+ http_res_text = utils.stream_to_text(http_res)
1079
+ raise errors.TrainTravelDefaultError(
1080
+ "API error occurred", http_res, http_res_text
1081
+ )
1082
+ if utils.match_response(http_res, "5XX", "*"):
1083
+ http_res_text = utils.stream_to_text(http_res)
1084
+ raise errors.TrainTravelDefaultError(
1085
+ "API error occurred", http_res, http_res_text
1086
+ )
1087
+
1088
+ raise errors.TrainTravelDefaultError("Unexpected response received", http_res)
1089
+
1090
+ async def delete_booking_async(
1091
+ self,
1092
+ *,
1093
+ booking_id: str,
1094
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
1095
+ server_url: Optional[str] = None,
1096
+ timeout_ms: Optional[int] = None,
1097
+ http_headers: Optional[Mapping[str, str]] = None,
1098
+ ) -> models.DeleteBookingResponse:
1099
+ r"""Delete a booking
1100
+
1101
+ Deletes a booking, cancelling the hold on the trip.
1102
+
1103
+ :param booking_id: The ID of the booking to retrieve.
1104
+ :param retries: Override the default retry configuration for this method
1105
+ :param server_url: Override the default server URL for this method
1106
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
1107
+ :param http_headers: Additional headers to set or replace on requests.
1108
+ """
1109
+ base_url = None
1110
+ url_variables = None
1111
+ if timeout_ms is None:
1112
+ timeout_ms = self.sdk_configuration.timeout_ms
1113
+
1114
+ if server_url is not None:
1115
+ base_url = server_url
1116
+ else:
1117
+ base_url = self._get_url(base_url, url_variables)
1118
+
1119
+ request = models.DeleteBookingRequest(
1120
+ booking_id=booking_id,
1121
+ )
1122
+
1123
+ req = self._build_request_async(
1124
+ method="DELETE",
1125
+ path="/bookings/{bookingId}",
1126
+ base_url=base_url,
1127
+ url_variables=url_variables,
1128
+ request=request,
1129
+ request_body_required=False,
1130
+ request_has_path_params=True,
1131
+ request_has_query_params=True,
1132
+ user_agent_header="user-agent",
1133
+ accept_header_value="*/*",
1134
+ http_headers=http_headers,
1135
+ security=self.sdk_configuration.security,
1136
+ allow_empty_value=None,
1137
+ timeout_ms=timeout_ms,
1138
+ )
1139
+
1140
+ if retries == UNSET:
1141
+ if self.sdk_configuration.retry_config is not UNSET:
1142
+ retries = self.sdk_configuration.retry_config
1143
+ else:
1144
+ retries = utils.RetryConfig(
1145
+ "backoff", utils.BackoffStrategy(500, 60000, 1.5, 3600000), True
1146
+ )
1147
+
1148
+ retry_config = None
1149
+ if isinstance(retries, utils.RetryConfig):
1150
+ retry_config = (retries, ["5XX"])
1151
+
1152
+ http_res = await self.do_request_async(
1153
+ hook_ctx=HookContext(
1154
+ config=self.sdk_configuration,
1155
+ base_url=base_url or "",
1156
+ operation_id="delete-booking",
1157
+ oauth2_scopes=None,
1158
+ security_source=get_security_from_env(
1159
+ self.sdk_configuration.security, models.Security
1160
+ ),
1161
+ ),
1162
+ request=req,
1163
+ error_status_codes=["400", "401", "403", "404", "429", "4XX", "500", "5XX"],
1164
+ retry_config=retry_config,
1165
+ )
1166
+
1167
+ if utils.match_response(http_res, "204", "*"):
1168
+ return models.DeleteBookingResponse(headers={})
1169
+ if utils.match_response(http_res, ["400", "401", "403", "404", "429"], "*"):
1170
+ http_res_text = await utils.stream_to_text_async(http_res)
1171
+ raise errors.TrainTravelDefaultError(
1172
+ "API error occurred", http_res, http_res_text
1173
+ )
1174
+ if utils.match_response(http_res, "500", "*"):
1175
+ http_res_text = await utils.stream_to_text_async(http_res)
1176
+ raise errors.TrainTravelDefaultError(
1177
+ "API error occurred", http_res, http_res_text
1178
+ )
1179
+ if utils.match_response(http_res, "4XX", "*"):
1180
+ http_res_text = await utils.stream_to_text_async(http_res)
1181
+ raise errors.TrainTravelDefaultError(
1182
+ "API error occurred", http_res, http_res_text
1183
+ )
1184
+ if utils.match_response(http_res, "5XX", "*"):
1185
+ http_res_text = await utils.stream_to_text_async(http_res)
1186
+ raise errors.TrainTravelDefaultError(
1187
+ "API error occurred", http_res, http_res_text
1188
+ )
1189
+
1190
+ raise errors.TrainTravelDefaultError("Unexpected response received", http_res)