Skip to content

Commit 1f62bef

Browse files
authored
Adds support for Flight Offers Price (#58)
* initial commit * update specs of new path * update docs * implement post with get parameters in the url and docs * add tests for post and update post method
1 parent 57c11a4 commit 1f62bef

File tree

6 files changed

+58
-1
lines changed

6 files changed

+58
-1
lines changed

README.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,12 @@ List of supported endpoints
296296
# Flight Offers Search POST
297297
amadeus.shopping.flight_offers_search.post(body)
298298
299+
# Flight Offers Price
300+
flights = amadeus.shopping.flight_offers_search.get(originLocationCode='SYD', destinationLocationCode='BKK', departureDate='2020-05-01', adults=1).data
301+
amadeus.shopping.flight_offers.pricing.post(flights[0])
302+
amadeus.shopping.flight_offers.pricing.post(flights[0:2], include='credit-card-fees,other-services')
303+
304+
299305
Development & Contributing
300306
--------------------------
301307

amadeus/shopping/_flight_offers.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
from amadeus.client.decorator import Decorator
22
from amadeus.shopping.flight_offers._prediction import FlightChoicePrediction
3+
from amadeus.shopping.flight_offers._pricing import FlightOffersPrice
34

45

56
class FlightOffers(Decorator, object):
67
def __init__(self, client):
78
Decorator.__init__(self, client)
89
self.prediction = FlightChoicePrediction(client)
10+
self.pricing = FlightOffersPrice(client)
911

1012
def get(self, **params):
1113
'''
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
from ._prediction import FlightChoicePrediction
2+
from ._pricing import FlightOffersPrice
23

3-
__all__ = ['FlightChoicePrediction']
4+
__all__ = ['FlightChoicePrediction', 'FlightOffersPrice']
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from amadeus.client.decorator import Decorator
2+
try:
3+
from urllib.parse import urlencode
4+
except ImportError: # pragma: no cover
5+
from urllib import urlencode # pragma: no cover
6+
7+
8+
class FlightOffersPrice(Decorator, object):
9+
def post(self, body, **params):
10+
'''
11+
Gets a confirmed price and availability of a flight
12+
13+
.. code-block:: python
14+
15+
amadeus.shopping.flight_offers.pricing.post(body, params)
16+
17+
:rtype: amadeus.Response
18+
:raises amadeus.ResponseError: if the request could not be completed
19+
'''
20+
url = '/v1/shopping/flight-offers/pricing'
21+
flight_offers = []
22+
23+
if params is not None:
24+
url = '/v1/shopping/flight-offers/pricing?'
25+
if type(body) is not list:
26+
flight_offers.append(body)
27+
else:
28+
flight_offers.extend(body)
29+
30+
return self.client.post(url + urlencode(params),
31+
{'data':
32+
{'type': 'flight-offers-pricing',
33+
'flightOffers': flight_offers}})

docs/index.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ Shopping/Hotels
6565
.. autoclass:: amadeus.shopping.hotel.Offer
6666
:members: get
6767

68+
Shopping/Flight Offers
69+
===============
70+
71+
.. autoclass:: amadeus.shopping.FlightOffersPrice
72+
:members: post
73+
6874
Travel/Analytics
6975
================
7076

specs/namespaces/namespaces_spec.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
expect(client.shopping.flight_destinations).not_to(be_none)
4545
expect(client.shopping.flight_offers).not_to(be_none)
4646
expect(client.shopping.flight_offers_search).not_to(be_none)
47+
expect(client.shopping.flight_offers.pricing).not_to(be_none)
4748

4849
expect(client.shopping.hotel_offers).not_to(be_none)
4950
expect(client.shopping.hotel_offer).not_to(be_none)
@@ -297,3 +298,11 @@
297298
expect(self.client.post).to(have_been_called_with(
298299
'/v2/shopping/flight-offers', {'foo': 'bar'}
299300
))
301+
302+
with it('.shopping.flight_offers.pricing.post'):
303+
self.client.shopping.flight_offers.pricing.post({'foo': 'bar'})
304+
expect(self.client.post).to(have_been_called_with(
305+
'/v1/shopping/flight-offers/pricing?',
306+
{'data': {'type': 'flight-offers-pricing',
307+
'flightOffers': [{'foo': 'bar'}]}}
308+
))

0 commit comments

Comments
 (0)