AviasalesSDK 4.0.1

AviasalesSDK 4.0.1

TestsTested
LangLanguage Obj-CObjective C
License MIT
ReleasedLast Release Mar 2020

Maintained by Seva Billevich, Dmitriy Baklanov, Vasiliy Yanguzin.



  • By
  • Aviasales iOS Team

Aviasales/Jetradar iOS SDK Core

CocoaPods CocoaPods Travis

Example

As an example, you are welcome to use our Template Project from Aviasales-iOS-SDK repo.

⚙ Installation

The easiest way is to use CocoaPods. It takes care of all required frameworks and third party dependencies:

pod 'AviasalesSDK', '~> 4.0.0'

We recommend to import AviasalesSDK.h in each file where you use objects or protocols from SDK.

#import <AviasalesSDK/AviasalesSDK.h>

Configure AviasalesSDK object before interaction with SDK like this:

AviasalesSDKInitialConfiguration *configuration = [AviasalesSDKInitialConfiguration configurationWithAPIToken:@"Your api token here"
                                                                                                    APILocale:[NSLocale currentLocale].localeIdentifier
                                                                                                partnerMarker:@"Your partner marker here"];
[AviasalesSDK setupWithConfiguration:configuration];

Don't forget to replace two placeholders in this example with the actual values.

Features

✈️ Flight Tickets Search

Specify search parameters using a JRSDKSearchInfoBuilder object. Take a look at the example below.

Create search info

Create simple object that describes new search:

JRSDKConfigurableSearchInfo *searchInfoBuilder = [[JRSDKSearchInfoBuilder alloc] init];

Set necessary parameters for the search (adults = 2 and travelClass = Business means that two adults would like to travel in business class):

searchInfoBuilder.adults = 2;
searchInfoBuilder.travelClass = JRSDKTravelClassBusiness;

Set travel dates and airports (using airports storage from the SDK):

JRSDKTravelSegmentBuilder *travelSegmentBuilder = [JRSDKTravelSegmentBuilder new]
travelSegmentBuilder.departureDate = [NSDate date];
travelSegmentBuilder.originAirport = [[AviasalesSDK sharedInstance].airportsStorage findAnythingByIATA:@"LED"];
travelSegmentBuilder.destinationAirport = [[AviasalesSDK sharedInstance].airportsStorage findAnythingByIATA:@"MOW"];

Save that travel segment to the search info:

searchInfoBuilder.travelSegments = [NSOrderedSet orderedSetWithObject:[travelSegmentBuilder build]];

And finally we can build a JRSDKSearchInfo object for further usage:

JRSDKSearchInfo *searchInfo = [searchInfoBuilder build];

That's it. Search info is ready for search.

Perform search request

To perform search request use SearchPerformer received from the SDK and send search info to it. Don't forget to store this performer somewhere during the search process.

JRSDKSearchPerformer *searchPerformer = [[AviasalesSDK sharedInstance] createSearchPerformer];

To retrieve live and final search results set delegate (JRSDKSearchPerformerDelegate) to this search performer:

searchPerformer.delegate = self;

This delegate requires to implement two methods:

First one is called when the search is finished and results are ready to be displayed. After its call, you can release SearchPerformer because it is not reusable.:

- (void)searchPerformer:(JRSDKSearchPerformer *)searchPerformer didFinishSearch:(JRSDKSearchInfo *)searchInfo withResult:(JRSDKSearchResult *)result andMetropolitanResult:(JRSDKSearchResult *)metropolitanResult;

Second needed to receive error if it occures during the search

- (void)searchPerformer:(JRSDKSearchPerformer *)searchPerformer didFailSearchWithError:(NSError *)error;

Optional method is called when a new chunk of tickets is received from server:

- (void)searchPerformer:(JRSDKSearchPerformer *)searchPerformer didFindSomeTickets:(JRSDKSearchResultsChunk *)newTickets inSearchInfo:(JRSDKSearchInfo *)searchInfo temporaryResult:(JRSDKSearchResult *)temporaryResult temporaryMetropolitanResult:(JRSDKSearchResult *)temporaryMetropolitanResult;

Start search performing:

[searchPerformer performSearchWithSearchInfo:searchInfo];

Parsing search result

Search results are received as JRSDKSearchResult objects. If a search is started with a specific airport as a parameter, result и metropolitanResult will be different — tha last one will contain tickets to any airport of the given city.

💸 Tickets purchase

AviasalesSDKPurchasePerformer is object used to perform ticket purchase. Each ticket contains different proposals from different agencies, you should use one of them as an input parameter. Create performer using price and searchId (JRSDKSearchResult > JRSDKSearchResultInfo) that was returned with the search result.

- (instancetype)initWithPrice:(id <JRSDKPrice>)price
                     searchId:(NSString *)searchId;

Generate a link for the purchase:

- (void)performWithDelegate:(id <AviasalesSDKPurchasePerformerDelegate>)delegate;

Open link received by delegate in browser to provide user purchase form.

Other Utils by SDK

Name How to retrieve object Description
Airports storage [AviasalesSDK sharedInstance].airportsStorage Finds airport by IATA, provides a list of airports
AviasalesAirportsSearchPerformer [[AviasalesAirportsSearchPerformer alloc] init] Finds airports by string
AviasalesNearestAirportsManager [AviasalesSDK sharedInstance].nearestAirportsManager Finds nearest airports to the current user.
JRSDKModelUtils [JRSDKModelUtils <method name here>] Util methods that help you to work with SDK objects