Skip to content

Commit 31afed7

Browse files
authored
Delete - Flight Order Management (#81)
* initial commit * update tests * fix line errors * add test for delete * update request to accept delete * add delete example * var name update
1 parent 290eb6f commit 31afed7

File tree

8 files changed

+66
-1
lines changed

8 files changed

+66
-1
lines changed

README.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,11 @@ List of supported endpoints
230230
231231
# Flight Order Management
232232
# The flight ID comes from the Flight Create Orders (in test environment it's temporary)
233+
# Retrieve the order based on it's ID
233234
flight_booking = amadeus.booking.flight_orders.post(body).data
234235
amadeus.booking.flight_order(flight_booking['id']).get()
236+
# Delete the order based on it's ID
237+
amadeus.booking.flight_order(flight_booking['id']).delete()
235238
236239
# Flight SeatMap Display GET
237240
amadeus.shopping.seatmaps.get(**{"flight-orderId": "orderid"})

amadeus/booking/_flight_order.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,17 @@ def get(self, **params):
1919
'''
2020
return self.client.get('/v1/booking/flight-orders/{0}'
2121
.format(self.flight_order_id), **params)
22+
23+
def delete(self, **params):
24+
'''
25+
Deletes a flight order based on its ID.
26+
27+
.. code-block:: python
28+
29+
amadeus.booking.flight_order('eJzTd9f3NjIJdzUGAAp%2fAiY=').delete()
30+
31+
:rtype: amadeus.Response
32+
:raises amadeus.ResponseError: if the request could not be completed
33+
'''
34+
return self.client.delete('/v1/booking/flight-orders/{0}'
35+
.format(self.flight_order_id), **params)

amadeus/client/request.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def __build_http_request(self):
101101
# Adds the authentication header since the bearer token has been set
102102
self.headers['Authorization'] = self.bearer_token
103103

104-
if (self.verb == 'GET'):
104+
if (self.verb == 'GET' or self.verb == 'DELETE'):
105105
return HTTPRequest(self.url, headers=self.headers)
106106
else:
107107
return HTTPRequest(self.url,

amadeus/mixins/http.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,29 @@ def post(self, path, params={}):
6565
'''
6666
return self.request('POST', path, params)
6767

68+
def delete(self, path, **params):
69+
'''
70+
A helper function for making generic DELETE requests calls. It is used by
71+
every namespaced API DELETE method.
72+
73+
It can be used to make any generic API call that is automatically
74+
authenticated using your API credentials:
75+
76+
.. code-block:: python
77+
78+
amadeus.delete('/foo/bar', airline='1X')
79+
80+
:param path: path the full path for the API call
81+
:paramtype path: str
82+
83+
:param params: (optional) params to pass to the API
84+
:paramtype params: dict
85+
86+
:rtype: amadeus.Response
87+
:raises amadeus.ResponseError: when the request fails
88+
'''
89+
return self.request('DELETE', path, params)
90+
6891
def request(self, verb, path, params):
6992
'''
7093
A helper function for making generic POST requests calls. It is used by

docs/index.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,5 +148,8 @@ Booking
148148
.. autoclass:: amadeus.booking.FlightOrder
149149
:members: get
150150

151+
.. autoclass:: amadeus.booking.FlightOrder
152+
:members: delete
153+
151154
.. autoclass:: amadeus.booking.HotelBookings
152155
:members: post

examples/flight_create_orders/flight_create_orders.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
# Flight Order Management returns the last-updated version of the booking
4949
# print('Flight Order Management')
5050
updated_booking = amadeus.booking.flight_order(booked_flight['id']).get()
51+
cancelled_booking = amadeus.booking.flight_order(booked_flight['id']).delete()
5152
except ResponseError as error:
5253
# print(error.response.body)
5354
pass

specs/mixins/http_spec.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@
2929
have_been_called_with('GET', '/foo', {'foo': 'bar'})
3030
)
3131

32+
with context('Client.delete'):
33+
with it('should pass all details to the request method'):
34+
self.client.request = self.request_method
35+
response = self.client.delete('/foo', foo='bar')
36+
expect(response).to(equal(self.response))
37+
expect(self.client.request).to(
38+
have_been_called_with('DELETE', '/foo', {'foo': 'bar'})
39+
)
40+
3241
with context('Client.post'):
3342
with it('should pass all details to the request method'):
3443
self.client.request = self.request_method

specs/namespaces/namespaces_spec.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@
111111
expect(client.travel.trip_parser_jobs.result('123').get).not_to(be_none)
112112

113113
expect(client.booking.flight_order('123').get).not_to(be_none)
114+
expect(client.booking.flight_order('123').delete).not_to(be_none)
115+
116+
with it('should define all expected .delete methods'):
117+
client = self.client
118+
expect(client.booking.flight_order('123').delete).not_to(be_none)
114119

115120
with it('should define all expected .post methods'):
116121
client = self.client
@@ -120,6 +125,7 @@
120125
with before.each:
121126
self.client.get = method_returning(None)
122127
self.client.post = method_returning(None)
128+
self.client.delete = method_returning(None)
123129

124130
with it('.reference_data.urls.checkin_links.get'):
125131
self.client.reference_data.urls.checkin_links.get(a='b')
@@ -357,6 +363,12 @@
357363
'/v1/booking/flight-orders/123', a='b'
358364
))
359365

366+
with it('.booking.flight_order().delete'):
367+
self.client.booking.flight_order('123').delete(a='b')
368+
expect(self.client.delete).to(have_been_called_with(
369+
'/v1/booking/flight-orders/123', a='b'
370+
))
371+
360372
with it('.shopping.booking.hotel_bookings.post'):
361373
self.client.booking.hotel_bookings.post('123',
362374
{'foo': 'bar'},

0 commit comments

Comments
 (0)