- Print
- DarkLight
Summary
Discovery API is used for searching attractions, venues,events and classifications. We can even fetch detailed information of any attraction or venue orevent, by passing its identifier.
Features
List of APIs provided by DiscoveryAPI
1. Attractions Search
2. Venues Search
3. Event Search
4. Classification Search
5. Event Details
6. Attraction Details
7. Venue Details
DiscoveryAPI Setup
TMDiscoveryAPI.shared.apiKey = "<API KEY HERE>"
Accessing Discovery service
/// Note: remember to setup `TMDiscoveryAPI` before accessing this variable
TMDiscoveryAPI.shared.discoveryService
Search Methods with Examples:
1.Attractions Search
Call below method to return a list of attractions using discoveryService
/// returns a paginated array of `DiscoveryAttraction`s for given Attraction `DiscoveryAttractionSearchCriteria`
///
/// - Parameters:
/// - criteria: a `DiscoveryAttractionSearchCriteria` model object
/// - completion: a "page" containing an array of `DiscoveryAttraction`s matching the given criteria
/// - response: The API response, which may be either an array of `PaginatedDiscoveryAttractionResponse` or an error.
@discardableResult
func attractionSearch(_ criteria: DiscoveryAttractionSearchCriteria,
completion: @escaping (_ response: PaginatedDiscoveryAttractionResponse) -> Void) -> URLSessionTask?
Example:
let searchText = “<SEARCH TEXT HERE>”
var criteria = DiscoveryAttractionSearchCriteria()
criteria.keywordsFilter = [searchText]
discoveryService?.attractionSearch(criteria) { response in
switch response {
case .success(let results):
print("Success: \(results)")
case .failure(let error):
print("Error: \(error.localizedDescription)")
}
}
2. Venues Search
Call below method to return a list of venues using discoveryService
/// returns a paginated array of `DiscoveryVenue`s for given `DiscoveryVenueSearchCriteria`
///
/// - Parameters:
/// - criteria: a `DiscoveryVenueSearchCriteria` model object
/// - completion: a "page" containing an array of `DiscoveryVenue`s matching the given criteria
/// - response: The API response, which may be either an array of `PaginatedDiscoveryVenueResponse` or an error.
@discardableResult
func venueSearch(_ criteria: DiscoveryVenueSearchCriteria,
completion: @escaping (_ response: PaginatedDiscoveryVenueResponse) -> Void) -> URLSessionTask?
Example:
let searchText = “<SEARCH TEXT HERE>”
var criteria = DiscoveryVenueSearchCriteria()
criteria.keywordsFilter = [searchText]
discoveryService?.venueSearch(criteria) { response in
switch response {
case .success(let results):
print("Success: \(results)")
case .failure(let error):
print("Error: \(error.localizedDescription)")
}
}
3. Event Search
Call below method to return a list of Events using discoveryService
/// returns a paginated array of `DiscoveryEvent`s for given `DiscoveryEventSearchCriteria`
///
/// - Parameters:
/// - criteria: a `DiscoveryEventSearchCriteria` model object
/// - completion: a "page" containing an array of `DiscoveryEvent`s matching the given criteria
/// - response: The API response, which may be either an array of `PaginatedDiscoveryEventResponse` or an error.
@discardableResult
func eventSearch(_ criteria: DiscoveryEventSearchCriteria,
completion: @escaping (_ response: PaginatedDiscoveryEventResponse) -> Void) -> URLSessionTask?
Example:
let searchText = “<SEARCH TEXT HERE>”
var criteria = DiscoveryEventSearchCriteria()
criteria.keywordsFilter = [text]
discoveryService?.eventSearch(criteria) { response in
switch response {
case .success(let results):
print("Success: \(results)")
case .failure(let error):
print("Error: \(error.localizedDescription)")
}
}
4. Classification Search
Call below method to return a list of classification using discoveryService
/// returns a paginated array of `DiscoveryClassification`s for given `DiscoveryClassificationSearchCriteria`
///
/// - Parameters:
/// - criteria: a `DiscoveryClassificationSearchCriteria` model object
/// - completion: a "page" containing an array of `DiscoveryClassification`s matching the given criteria
/// - response: The API response, which may be either an array of `PaginatedDiscoveryClassificationResponse` or an error.
@discardableResult
func classificationSearch(_ criteria: DiscoveryClassificationSearchCriteria,
completion: @escaping (_ response: PaginatedDiscoveryClassificationResponse) -> Void)
Example:
let searchText = “<SEARCH TEXT HERE>”
var criteria = DiscoveryClassificationSearchCriteria()
criteria.keywordsFilter = [searchText]
discoveryService?.classificationSearch(criteria) { response in
switch response {
case .success(let results):
print("Success: \(results)")
case .failure(let error):
print("Error: \(error.localizedDescription)")
}
}
5. Event Details
Call below method to fetch event details using discoveryService
/// returns a `DiscoveryEvent` for the given Event identifier `String`
///
/// - Parameters:
/// - identifier: The Event's identifier as a `String`. This may an identifier in either the Discovery sytem or the Host system.
/// - completion: a `DiscoveryEvent` matching the given identifier
/// - response: The API response, which may be either a `DiscoveryEvent` or an error.
func eventDetails(_ identifier: String,
completion: @escaping (_ response: APIResponse<DiscoveryEvent>) -> Void)
Example:
Example:
let criteria = “<EVENT IDENTIFIER>”
discoveryService?.eventDetails(criteria) { response in
switch response {
case .success(let results):
print("Success: \(results)")
case .failure(let error):
print("Error: \(error.localizedDescription)")
}
}
6. Attraction Details
Call below method to fetch attraction details using discoveryService.
// returns a `DiscoveryAttraction` with given Attraction `DiscoveryIdentifier`
///
/// - Parameters:
/// - identifier: Attraction `DiscoveryIdentifier`
/// - completion: a `DiscoveryAttraction` matching the given identifier
/// - response: The API response, which may be either a `DiscoveryAttraction` or an error.
func attractionDetails(_ identifier: DiscoveryIdentifier,
completion: @escaping (_ response: APIResponse<DiscoveryAttraction>) -> Void)
Example:
let identifier = “<ATTRACTION IDENTIFIER>”
let criteria = DiscoveryIdentifier(identifier)
discoveryService?.attractionDetails(criteria) { response in
switch response {
case .success(let results):
print("Success: \(results)")
case .failure(let error):
print("Error: \(error.localizedDescription)")
}
}
7. Venue Details
Call below method to fetch Venue details using discoveryService.
/// returns a `DiscoveryVenue` with given Venue `DiscoveryIdentifier`
///
/// - Parameters:
/// - identifier: Venue `DiscoveryIdentifier`
/// - completion: a `DiscoveryVenue` matching the given identifier
/// - response: The API response, which may be either a `DiscoveryVenue` or an error.
func venueDetails(_ identifier: DiscoveryIdentifier,
completion: @escaping (_ response: APIResponse<DiscoveryVenue>) -> Void)
Example:
let identifier = “<VENUE IDENTIFIER>”
let criteria = DiscoveryIdentifier(identifier)
discoveryService?.venueDetails(criteria) { response in
switch response {
case .success(let results):
print("Success: \(results)")
case .failure(let error):
print("Error: \(error.localizedDescription)")
}
}