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

Commit

Permalink
Merge pull request #213 from duffelhq/OfferRequest-max-connections
Browse files Browse the repository at this point in the history
Add max_connections to OfferRequest creation
  • Loading branch information
cianyleow authored Jan 25, 2023
2 parents 55506b5 + 881b46d commit 922fd8a
Showing 1 changed file with 17 additions and 0 deletions.
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

0 comments on commit 922fd8a

Please sign in to comment.