DataService
public class DataService
Main API class to interact with the National Park Service API
-
Required API key which can be requested for free from NPS Developer website
Declaration
Swift
public let apiKey: String
-
Initializer
Declaration
Swift
public init(apiKey: String)
-
fetch single park information from the National Park Service Data API
Declaration
Swift
public func fetchPark(_ parkCode: String) -> AnyPublisher<Park?, DataServiceError>
Parameters
parkCode
The National Park Service uses four letter codes - Alpha Codes - to abbreviate the names of its parks. If a park has one name in its title, like Yosemite National Park, the code word would be the first four letters of the name - YOSE. If the park has two names or more in its title, like Grand Canyon National Park, the code word would be the first two letters of each name - GRCA.
Return Value
a respective publisher which outputs an array of parks
-
fetch park information from the National Park Service Data API
Declaration
Swift
public func fetchParks(by parkCodes: [String]? = [], in states: [StateInUSA]? = [], _ requestOptions: RequestOptions<RequestableParkField>? = nil) -> AnyPublisher<(data: [Park], total: Int), DataServiceError>
Parameters
parkCodes
to limit results for certain parks only. Array of park codes, e.g. [“yell”]. Can be nil or empty
states
to limit results for certain states only. Array of US states, e.g [.california]. Can be nil or empty
requestOptions
to specify result amount (default: 50) and further influence search critierias
Return Value
a respective publisher which outputs a tuple containing an array of parks as well as the total count of matching items on the server
-
fetch alert release information from the National Park Service Data API
Declaration
Swift
public func fetchAlerts(by parkCodes: [String]? = [], in states: [StateInUSA]? = [], _ requestOptions: RequestOptions<RequestableAlertField>? = nil) -> AnyPublisher<(data: [Alert], total: Int), DataServiceError>
Parameters
parkCodes
to limit results for certain parks only. Array of park codes, e.g. [“yell”]. Can be nil or empty
states
to limit results for certain states only. Array of US states, e.g [.california]. Can be nil or empty
requestOptions
to specify result amount (default: 50) and further influence search critierias
Return Value
a respective publisher which outputs a tuple containing an array of alerts as well as the total count of matching items on the server
-
fetch news release information from the National Park Service Data API
Declaration
Swift
public func fetchNewsReleases(by parkCodes: [String]? = [], in states: [StateInUSA]? = [], _ requestOptions: RequestOptions<RequestableNewsReleaseField>? = nil) -> AnyPublisher<(data: [NewsRelease], total: Int), DataServiceError>
Parameters
parkCodes
to limit results for certain parks only. Array of park codes, e.g. [“yell”]. Can be nil or empty
states
to limit results for certain states only. Array of US states, e.g [.california]. Can be nil or empty
requestOptions
to specify result amount (default: 50) and further influence search critierias
Return Value
a respective publisher which outputs a tuple containing an array of news releases as well as the total count of matching items on the server
-
fetch visitor center information from the National Park Service Data API
Declaration
Swift
public func fetchVisitorCenters(by parkCodes: [String]? = [], in states: [StateInUSA]? = [], _ requestOptions: RequestOptions<RequestableVisitorCenterField>? = nil) -> AnyPublisher<(data: [VisitorCenter], total: Int), DataServiceError>
Parameters
parkCodes
to limit results for certain parks only. Array of park codes, e.g. [“yell”]. Can be nil or empty
states
to limit results for certain states only. Array of US states, e.g [.california]. Can be nil or empty
requestOptions
to specify result amount (default: 50) and further influence search critierias
Return Value
a respective publisher which outputs a tuple containing an array of visitor centers as well as the total count of matching items on the server
-
fetch asset (place) information from the National Park Service Data API
Declaration
Swift
public func fetchAssets(by parkCodes: [String]? = [], in states: [StateInUSA]? = [], _ requestOptions: RequestOptions<RequestableAssetField>? = nil) -> AnyPublisher<(data: [Asset], total: Int), DataServiceError>
Parameters
parkCodes
to limit results for certain parks only. Array of park codes, e.g. [“yell”]. Can be nil or empty
states
to limit results for certain states only. Array of US states, e.g [.california]. Can be nil or empty
requestOptions
to specify result amount (default: 50) and further influence search critierias
Return Value
a respective publisher which outputs a tuple containing an array of assets as well as the total count of matching items on the server