Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 49382e9

Browse files
committed
add flight availabilities and test
1 parent c340d65 commit 49382e9

5 files changed

Lines changed: 92 additions & 0 deletions

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,9 @@ amadeus.schedule.flights.get(params:["carrierCode":"AZ",
233233
"flightNumber":"319",
234234
"scheduledDepartureDate":"2021-03-13"], onCompletion: { ... })
235235

236+
// Flight Availabilities Search
237+
amadeus.shopping.availability.flightAvailabilities.post(body: jsonBody, onCompletion: { ... })
238+
236239
// Seatmap Display
237240
amadeus.shopping.seatMaps.get(params: ["flight-orderId":"eJzTd9f3NjIJdzUGAAp%2fAiY="],
238241
onCompletion: { ... })

Sources/Amadeus/Shopping.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public class Shopping {
1616
public let hotelOffers: HotelOffers
1717
public let hotelOfferByHotel: HotelOfferByHotel
1818
public let activities: Activities
19+
public let availability: Availability
1920

2021
private let client: Client
2122

@@ -28,6 +29,7 @@ public class Shopping {
2829
hotelOffers = HotelOffers(client: client)
2930
hotelOfferByHotel = HotelOfferByHotel(client: client)
3031
activities = Activities(client: client)
32+
self.availability = Availability(client: client)
3133
self.client = client
3234
}
3335

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import Foundation
2+
3+
/// A namespaced client for the `v1/shopping/availability` endpoints
4+
///
5+
/// Access via the `Amadeus` object
6+
/// ```swift
7+
/// let amadeus = Amadeus(client_id, secret_id)
8+
/// amadeus.shopping.availability
9+
/// ```
10+
public class Availability {
11+
public let flightAvailabilities: FlightAvailabilities
12+
13+
public init(client: Client) {
14+
flightAvailabilities = FlightAvailabilities(client: client)
15+
}
16+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
import Foundation
3+
import SwiftyJSON
4+
5+
public class FlightAvailabilities {
6+
private var client: Client
7+
8+
public init(client: Client) {
9+
self.client = client
10+
}
11+
12+
/// Gets available seats in different fare classes
13+
///
14+
/// - Returns:
15+
/// `JSON` object
16+
///
17+
public func post(body: JSON, params: [String: String] = [:], onCompletion: @escaping AmadeusResponse) {
18+
19+
client.post(path: "/v1/shopping/availability/flight-availabilities", body: body, params: params, onCompletion: { result in
20+
onCompletion(result)
21+
})
22+
}
23+
}

Tests/AmadeusTests/AirShoppingTests.swift

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,54 @@ class AirShoppingTests: XCTestCase {
150150
}
151151
}
152152

153+
func testFlightAvailabilitiesPost() {
154+
let expectation = XCTestExpectation(description: "TimeOut")
155+
156+
let jsonString: String = """
157+
{
158+
"originDestinations": [
159+
{
160+
"id": "1",
161+
"originLocationCode": "MIA",
162+
"destinationLocationCode": "ATL",
163+
"departureDateTime": {
164+
"date": "2021-11-01"
165+
}
166+
}
167+
],
168+
"travelers": [
169+
{
170+
"id": "1",
171+
"travelerType": "ADULT"
172+
}
173+
],
174+
"sources": [
175+
"GDS"
176+
]
177+
}
178+
"""
179+
180+
let dataFromString = jsonString.data(using: .utf8, allowLossyConversion: false)
181+
do {
182+
let body: JSON = try JSON(data: dataFromString!)
183+
184+
amadeus.shopping.availability.flightAvailabilities.post(body: body, onCompletion: {
185+
result in
186+
switch result {
187+
case .success(let response):
188+
XCTAssertEqual(response.statusCode, 200)
189+
case .failure(let error):
190+
fatalError(error.localizedDescription)
191+
}
192+
expectation.fulfill()
193+
})
194+
195+
wait(for: [expectation], timeout: 60)
196+
197+
} catch _ as NSError {
198+
assertionFailure("JSON not valid")
199+
}
200+
}
153201
func testFlightDates() {
154202
let expectation = XCTestExpectation(description: "TimeOut")
155203

0 commit comments

Comments
 (0)