TestsTested | ✗ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Dec 2016 |
SwiftSwift Version | 3.0 |
SPMSupports SPM | ✗ |
Maintained by Christopher Rung.
A cross-platform CocoaPod that fetches information from WMATA’s API and stores it in Train
objects, which are modeled after the API’s AIMPredictionTrainInfo object.
WMATAFetcher is available via CocoaPods. To install it, add the following to your Podfile
:
target 'TargetName' do
pod 'WMATAFetcher'
end
Next, run the following in a Terminal:
$ pod install
First, create a new WMATAFetcher
object, passing it your WMATA API key:
var wmataFetcher = WMATAFetcher(WMATA_API_KEY: "[YOUR_WMATA_KEY]")
The isSpaceInTrainArray
BOOL
determines if a Station.Space
object will separate each group in the Train
array (default: true
).
You may initialize this value when instantiating a new WMATAFetcher
object:
var wmataFetcher = WMATAFetcher(WMATA_API_KEY: "[YOUR_WMATA_KEY]", isSpaceInTrainArray: false)
You may also change the value of isSpaceInTrainArray
directly:
wmataFetcher.isSpaceInTrainArray = false
Pass wmataFetcher.getStationPredictions
a station code to get predictions. Implement onCompleted
to handle the TrainResponse
returned.
If trainResponse.errorCode
is nil
, we can safely force upwrap trainResponse.trains?
.
let wmataFetcher = WMATAFetcher(WMATA_API_KEY: "[API KEY HERE]")
let metroCenterStationCode = Station(description: "Metro Center")!.rawValue
wmataFetcher.getStationPredictions(stationCode: metroCenterStationCode, onCompleted: {
trainResponse in
if trainResponse.errorCode == nil {
for train in trainResponse.trains! {
print(train.debugDescription);
}
} else {
switch trainResponse.errorCode! {
case -1009:
print("Internet connection is offline")
default:
print("Prediction fetch failed (Code: \(trainResponse.errorCode!))")
}
})
TrainResponse.errorCode
is an Int?
representing the HTTP status code returned by WMATA’s API. If it is nil
, the fetch was successful. The most common error codes are:
Pod
WMATAFetcher is available under the MIT license. See the LICENSE file for more info.