Skip to content

Commit 57c11a4

Browse files
authored
Adds support for Flight Offers Search (#57)
* add support docs and tests for flight offers search * update readme * remove init * add test for post
1 parent c114ca6 commit 57c11a4

File tree

6 files changed

+79
-2
lines changed

6 files changed

+79
-2
lines changed

README.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,11 @@ List of supported endpoints
291291
# Get the result of the process by jobId
292292
amadeus.travel.trip_parser_jobs.result(response.data['id']).get()
293293
294+
# Flight Offers Search GET
295+
amadeus.shopping.flight_offers_search.get(originLocationCode='SYD', destinationLocationCode='BKK', departureDate='2020-05-01', adults=1)
296+
# Flight Offers Search POST
297+
amadeus.shopping.flight_offers_search.post(body)
298+
294299
Development & Contributing
295300
--------------------------
296301

amadeus/namespaces/_shopping.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from amadeus.shopping._flight_dates import FlightDates
33
from amadeus.shopping._flight_destinations import FlightDestinations
44
from amadeus.shopping._flight_offers import FlightOffers
5+
from amadeus.shopping._flight_offers_search import FlightOffersSearch
56
from amadeus.shopping._hotel_offers import HotelOffers
67
from amadeus.shopping._hotel_offers_by_hotel import HotelOffersByHotel
78
from amadeus.shopping._hotel_offer import HotelOffer
@@ -15,9 +16,11 @@ def __init__(self, client):
1516
self.flight_offers = FlightOffers(client)
1617
self.hotel_offers = HotelOffers(client)
1718
self.hotel_offers_by_hotel = HotelOffersByHotel(client)
19+
self.flight_offers_search = FlightOffersSearch(client)
1820

1921
def hotel_offer(self, offer_id):
2022
return HotelOffer(self.client, offer_id)
2123

2224

23-
__all__ = ['FlightDates', 'FlightDestinations', 'FlightOffers']
25+
__all__ = ['FlightDates', 'FlightDestinations', 'FlightOffers',
26+
'FlightOffersSearch']

amadeus/shopping/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
from ._flight_offers import FlightOffers
22
from ._flight_dates import FlightDates
33
from ._flight_destinations import FlightDestinations
4+
from ._flight_offers_search import FlightOffersSearch
45
from ._hotel_offers import HotelOffers
56
from ._hotel_offers_by_hotel import HotelOffersByHotel
67
from ._hotel_offer import HotelOffer
78

8-
__all__ = ['FlightOffers', 'FlightDates', 'FlightDestinations',
9+
__all__ = ['FlightOffers', 'FlightDates',
10+
'FlightDestinations', 'FlightOffersSearch',
911
'HotelOffers', 'HotelOffersByHotel', 'HotelOffer']
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
from amadeus.client.decorator import Decorator
2+
3+
4+
class FlightOffersSearch(Decorator, object):
5+
def get(self, **params):
6+
'''
7+
Get the cheapest flights on a given journey
8+
9+
.. code-block:: python
10+
11+
amadeus.shopping.flight_offers_search.get(
12+
origin='MAD',
13+
destination='NYC',
14+
departureDate='2019-08-01',
15+
adults='1'
16+
)
17+
18+
:param origin: the City/Airport IATA code from which the flight will
19+
depart. ``"MAD"``, for example for Madrid.
20+
21+
:param destination: the City/Airport IATA code to which the flight is
22+
going. ``"BOS"``, for example for Boston.
23+
24+
:param departureDate: the date on which to fly out, in `YYYY-MM-DD`
25+
format
26+
27+
:param adults: the number of adult passengers with age 12 or older
28+
29+
:rtype: amadeus.Response
30+
:raises amadeus.ResponseError: if the request could not be completed
31+
'''
32+
return self.client.get('/v2/shopping/flight-offers', **params)
33+
34+
def post(self, body):
35+
'''
36+
Get the cheapest flights on a given journey.
37+
38+
.. code-block:: python
39+
40+
amadeus.shopping.flight_offers_search.post(body)
41+
42+
:param body: the parameters to send to the API
43+
44+
:rtype: amadeus.Response
45+
:raises amadeus.ResponseError: if the request could not be completed
46+
'''
47+
return self.client.post('/v2/shopping/flight-offers', body)

docs/index.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ Shopping/Flights
4747
.. autoclass:: amadeus.shopping.FlightOffers
4848
:members: get
4949

50+
.. autoclass:: amadeus.shopping.FlightOffersSearch
51+
:members: get
52+
53+
.. autoclass:: amadeus.shopping.FlightOffersSearch
54+
:members: post
55+
5056
Shopping/Hotels
5157
===============
5258

specs/namespaces/namespaces_spec.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
expect(client.shopping.flight_dates).not_to(be_none)
4444
expect(client.shopping.flight_destinations).not_to(be_none)
4545
expect(client.shopping.flight_offers).not_to(be_none)
46+
expect(client.shopping.flight_offers_search).not_to(be_none)
4647

4748
expect(client.shopping.hotel_offers).not_to(be_none)
4849
expect(client.shopping.hotel_offer).not_to(be_none)
@@ -95,6 +96,7 @@
9596
expect(client.shopping.flight_dates.get).not_to(be_none)
9697
expect(client.shopping.flight_destinations.get).not_to(be_none)
9798
expect(client.shopping.flight_offers.get).not_to(be_none)
99+
expect(client.shopping.flight_offers_search.get).not_to(be_none)
98100

99101
expect(client.shopping.hotel_offers.get).not_to(be_none)
100102
expect(client.shopping.hotel_offers_by_hotel.get).not_to(be_none)
@@ -224,6 +226,12 @@
224226
'/v1/shopping/flight-offers', a='b'
225227
))
226228

229+
with it('.shopping.flight_offers_search.get'):
230+
self.client.shopping.flight_offers_search.get(a='b')
231+
expect(self.client.get).to(have_been_called_with(
232+
'/v2/shopping/flight-offers', a='b'
233+
))
234+
227235
with it('.shopping.hotel_offers.get'):
228236
self.client.shopping.hotel_offers.get(cityCode='MAD')
229237
expect(self.client.get).to(have_been_called_with(
@@ -283,3 +291,9 @@
283291
expect(self.client.post).to(have_been_called_with(
284292
'/v2/travel/trip-parser-jobs', {'foo': 'bar'}
285293
))
294+
295+
with it('.shopping.flight_offers_search.post'):
296+
self.client.shopping.flight_offers_search.post({'foo': 'bar'})
297+
expect(self.client.post).to(have_been_called_with(
298+
'/v2/shopping/flight-offers', {'foo': 'bar'}
299+
))

0 commit comments

Comments
 (0)