Skip to content
This repository has been archived by the owner on Sep 12, 2024. It is now read-only.

Add max_connections to OfferRequest creation #213

Merged
merged 2 commits into from
Jan 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions duffel_api/api/booking/offer_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,16 @@ class InvalidPassenger(Exception):
class InvalidSlice(Exception):
"""Invalid slice data provided"""

class InvalidMaxConnectionValue(Exception):
"""Invalid max connection value provided"""

def __init__(self, client):
self._client = client
self._return_offers = "false"
self._cabin_class = "economy"
self._passengers = []
self._slices = []
self._max_connections = 1

@staticmethod
def _validate_cabin_class(cabin_class):
Expand Down Expand Up @@ -85,6 +89,12 @@ def _validate_slices(slices):
):
raise OfferRequestCreate.InvalidSlice(travel_slice)

@staticmethod
def _validate_max_connections(max_connections):
"""Validate the max connection number"""
if not isinstance(max_connections, int) or max_connections < 0:
raise OfferRequestCreate.InvalidMaxConnectionValue(max_connections)

def return_offers(self):
"""Set return_offers to 'true'"""
self._return_offers = "true"
Expand All @@ -108,6 +118,12 @@ def slices(self, slices):
self._slices = slices
return self

def max_connections(self, max_connections):
"""Set the max_connections for the journey we want to travel"""
OfferRequestCreate._validate_max_connections(max_connections)
self._max_connections = max_connections
return self

def execute(self):
"""POST /air/offer_requests - trigger the call to create the offer_request"""
OfferRequestCreate._validate_passengers(self._passengers)
Expand All @@ -119,6 +135,7 @@ def execute(self):
"data": {
"cabin_class": self._cabin_class,
"passengers": self._passengers,
"max_connections": self._max_connections,
"slices": self._slices,
}
},
Expand Down