Skip to content

Commit 67e933b

Browse files
authored
Flight offers search and flight choice prediction v2 (#48)
* Add support for Flight Offers Search and Flight Choice Prediction v2
1 parent 012d1f3 commit 67e933b

File tree

10 files changed

+134
-106
lines changed

10 files changed

+134
-106
lines changed

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,12 @@ amadeus.shopping.flight_destinations.get(origin: 'MAD')
180180
# Flight Cheapest Date Search
181181
amadeus.shopping.flight_dates.get(origin: 'MAD', destination: 'MUC')
182182

183-
# Flight Low-fare Search
184-
amadeus.shopping.flight_offers.get(origin: 'NYC', destination: 'MAD', departureDate: '2020-08-01')
183+
# Flight Offers Search
184+
amadeus.shopping.flight_offers_search.get(originLocationCode: 'NYC', destinationLocationCode: 'MAD', departureDate: '2020-10-01', adults: 1)
185185

186-
# Flight Choice Prediction / Be careful, this example combines 2 API calls: 1. Flight Low-fare Search then Flight Choice Prediction
187-
amadeus.shopping.flight_offers.prediction.post(amadeus.shopping.flight_offers.get(origin: 'NYC', destination: 'MAD', departureDate: '2020-11-01').body)
186+
# Flight Choice Prediction / Be careful, this example combines 2 API calls: 1. Flight Offers Search then Flight Choice Prediction
187+
flight_offers = amadeus.shopping.flight_offers_search.get(originLocationCode: 'NYC', destinationLocationCode: 'MAD', departureDate: '2020-10-01', adults: 1, max: 1).body
188+
amadeus.shopping.flight_offers_search.prediction.post(flight_offers)
188189

189190
# Flight Delay Prediction
190191
amadeus.travel.predictions.flight_delay.get(originLocationCod: 'NCE', destinationLocationCod: 'IST', departureDat: '2020-08-01', departureTim: '18:20:00', arrivalDat: '2020-08-01', arrivalTim: '22:15:00', aircraftCod: '321', carrierCod: 'TK', flightNumber: '1816', duration: 'PT31H10M')

lib/amadeus.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
require 'amadeus/namespaces/reference_data/locations/points_of_interest'
2929
require 'amadeus/namespaces/reference_data/locations/points_of_interest/by_square'
3030
require 'amadeus/namespaces/shopping/flight_destinations'
31-
require 'amadeus/namespaces/shopping/flight_offers'
32-
require 'amadeus/namespaces/shopping/flight_offers/prediction'
31+
require 'amadeus/namespaces/shopping/flight_offers_search'
32+
require 'amadeus/namespaces/shopping/flight_offers_search/prediction'
3333
require 'amadeus/namespaces/shopping/flight_dates'
3434
require 'amadeus/namespaces/shopping/hotel_offers'
3535
require 'amadeus/namespaces/shopping/hotel_offer'

lib/amadeus/namespaces/shopping.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ def flight_destinations
2323

2424
# The namespace for the FlightOffers API:
2525
#
26-
# @return [Amadeus::Namespaces::Shopping::FlightOffers]
26+
# @return [Amadeus::Namespaces::Shopping::FlightOffersSearch]
2727
# @example
28-
# amadeus.shopping.flight_offers
28+
# amadeus.shopping.flight_offers_search
2929
#
30-
def flight_offers
31-
Amadeus::Namespaces::Shopping::FlightOffers.new(client)
30+
def flight_offers_search
31+
Amadeus::Namespaces::Shopping::FlightOffersSearch.new(client)
3232
end
3333

3434
# The namespace for the FlightDates API:

lib/amadeus/namespaces/shopping/flight_offers.rb

Lines changed: 0 additions & 47 deletions
This file was deleted.
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# frozen_string_literal: true
2+
3+
module Amadeus
4+
module Namespaces
5+
class Shopping
6+
# A namespaced client for the
7+
# +/v2/shopping/flight-offers+ endpoints
8+
#
9+
# Access via the +Amadeus::Client+ object
10+
#
11+
# amadeus = Amadeus::Client.new
12+
# amadeus.shopping.flight_offers_search
13+
#
14+
class FlightOffersSearch < Amadeus::Client::Decorator
15+
# The namespace for the Prediction API:
16+
#
17+
# @return [Amadeus::Namespaces::Shopping::FlightOffersSearch::Prediction]
18+
# @example
19+
# amadeus.shopping.flight_offers_search.prediction
20+
#
21+
def prediction
22+
Amadeus::Namespaces::Shopping::FlightOffersSearch::Prediction.new(client)
23+
end
24+
# Find the cheapest bookable flights.
25+
#
26+
# @option params [String] :origin City/Airport IATA code from which the
27+
# flight will depart. BOS, for example.
28+
# @option params [String] :destination City/Airport IATA code to which
29+
# the traveler is going. PAR, for example
30+
# @return [Amadeus::Response] a parsed response
31+
# @raise [Amadeus::Base] an exception if the call failed
32+
# @example Find the cheapest flight offers from New-York to Madrid,
33+
# for the first of October 2020
34+
# amadeus.shopping.flight_offers_search.get(
35+
# originLocationCode: 'NYC',
36+
# destinationLocationCode: 'MAD',
37+
# departureDate: '2020-10-01',
38+
# adults: 1
39+
# )
40+
#
41+
42+
def get(params = {})
43+
client.get('/v2/shopping/flight-offers', params)
44+
end
45+
46+
# Find the cheapest bookable flights.
47+
#
48+
# @option body [JSON] :body flight search parameters
49+
# @return [Amadeus::Response] a parsed response
50+
# @raise [Amadeus::Base] an exception if the call
51+
# failed
52+
# @example
53+
# amadeus.shopping.flight_offers_search.post(body)
54+
#
55+
def post(params = {})
56+
client.post('/v2/shopping/flight-offers', params)
57+
end
58+
end
59+
end
60+
end
61+
end

lib/amadeus/namespaces/shopping/flight_offers/prediction.rb renamed to lib/amadeus/namespaces/shopping/flight_offers_search/prediction.rb

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,28 @@
33
module Amadeus
44
module Namespaces
55
class Shopping
6-
class FlightOffers
6+
class FlightOffersSearch
77
# A namespaced client for the
8-
# +/v1/shopping/flight-offers/prediction+ endpoints
8+
# +/v2/shopping/flight-offers/prediction+ endpoints
99
#
1010
# Access via the +Amadeus::Client+ object
1111
#
1212
# amadeus = Amadeus::Client.new
13-
# amadeus.shopping.flight-offers.prediction
13+
# amadeus.shopping.flight_offers_search.prediction
1414
#
1515
class Prediction < Amadeus::Client::Decorator
1616
# Returns a list of flight offers including a choice prediction for each itineary.
1717
#
18-
# @option body [JSON] :body JSON response of the Flight Low-fare Search API
18+
# @option body [JSON] :body JSON response of the Flight Offers Search API
1919
# @return [Amadeus::Response] a parsed response
2020
# @raise [Amadeus::Base] an exception if the call
2121
# failed
2222
# @example
23-
# amadeus.shopping.flight_offers.prediction.post(flight_offers_response.body)
23+
# amadeus.shopping.flight_offers_search.prediction.post(
24+
# flight_offers_search_response.body)
2425
#
2526
def post(params = {})
26-
client.post('/v1/shopping/flight-offers/prediction', params)
27+
client.post('/v2/shopping/flight-offers/prediction', params)
2728
end
2829
end
2930
end

spec/namespaces/namespaces_spec.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,18 +99,18 @@
9999
end
100100
end
101101

102-
describe '.shopping.flight_offers' do
103-
it 'should return a FlightOffers object' do
104-
expect(@amadeus.shopping.flight_offers).to(
105-
be_instance_of Amadeus::Namespaces::Shopping::FlightOffers
102+
describe '.shopping.flight_offers_search' do
103+
it 'should return a FlightOffersSearch object' do
104+
expect(@amadeus.shopping.flight_offers_search).to(
105+
be_instance_of Amadeus::Namespaces::Shopping::FlightOffersSearch
106106
)
107107
end
108108
end
109109

110-
describe '.shopping.flight_offers.prediction' do
110+
describe '.shopping.flight_offers_search.prediction' do
111111
it 'should return a Prediction object' do
112-
expect(@amadeus.shopping.flight_offers.prediction).to(
113-
be_instance_of Amadeus::Namespaces::Shopping::FlightOffers::Prediction
112+
expect(@amadeus.shopping.flight_offers_search.prediction).to(
113+
be_instance_of Amadeus::Namespaces::Shopping::FlightOffersSearch::Prediction
114114
)
115115
end
116116
end

spec/namespaces/shopping/flight_offers/prediction_spec.rb renamed to spec/namespaces/shopping/flight_offers_search/prediction_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,26 @@
22

33
require 'spec_helper'
44

5-
RSpec.describe Amadeus::Namespaces::Shopping::FlightOffers::Prediction do
5+
RSpec.describe Amadeus::Namespaces::Shopping::FlightOffersSearch::Prediction do
66
before do
77
@client = double('Amadeus::Client')
8-
@api = Amadeus::Namespaces::Shopping::FlightOffers::Prediction.new(@client)
8+
@api = Amadeus::Namespaces::Shopping::FlightOffersSearch::Prediction.new(@client)
99
end
1010

1111
describe '.post' do
1212
it 'should call client.post with the right body' do
1313
body = { foo: :bar }
1414

1515
expect(@client).to receive(:post).with(
16-
'/v1/shopping/flight-offers/prediction', body
16+
'/v2/shopping/flight-offers/prediction', body
1717
)
1818

1919
@api.post(body)
2020
end
2121

2222
it 'should default to an empty hash' do
2323
expect(@client).to receive(:post).with(
24-
'/v1/shopping/flight-offers/prediction', {}
24+
'/v2/shopping/flight-offers/prediction', {}
2525
)
2626

2727
@api.post
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
4+
5+
RSpec.describe Amadeus::Namespaces::Shopping::FlightOffersSearch do
6+
before do
7+
@client = double('Amadeus::Client')
8+
@api = Amadeus::Namespaces::Shopping::FlightOffersSearch.new(@client)
9+
end
10+
11+
describe '.get' do
12+
it 'should call client.get with the right params' do
13+
params = { originLocationCode: 'LHR',
14+
destinationLocationCode: 'LAX',
15+
departureDate: '202020-12-01' }
16+
17+
expect(@client).to receive(:get).with(
18+
'/v2/shopping/flight-offers', params
19+
)
20+
21+
@api.get(params)
22+
end
23+
end
24+
25+
describe '.post' do
26+
it 'should call client.get with the right params' do
27+
body = { foo: :bar }
28+
29+
expect(@client).to receive(:post).with(
30+
'/v2/shopping/flight-offers', body
31+
)
32+
33+
@api.post(body)
34+
end
35+
36+
it 'should default to an empty hash' do
37+
expect(@client).to receive(:get).with(
38+
'/v2/shopping/flight-offers', {}
39+
)
40+
41+
@api.get
42+
end
43+
end
44+
end

spec/namespaces/shopping/flight_offers_spec.rb

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)