WMATAFetcher language Version License Platform

Description

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.

Requirements

  • iOS 8.0+
  • macOS 10.9+
  • tvOS 9.0+
  • watchOS 2.0+

Installation

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

Usage

Instantiation

First, create a new WMATAFetcher object, passing it your WMATA API key:

var WMATAfetcher = WMATAFetcher(WMATA_API_KEY: "[YOUR_WMATA_KEY]")

Spaces between groups

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 creating 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

Fetching

Pass WMATAfetcher a station code to get predictions. Implement onCompleted to handle the TrainResponse returned by getPrediction().

String stationCode = Station(description: "Metro Center")!.rawValue
WMATAfetcher.getPrediction(stationCode, onCompleted: {
trainResponse in
	if trainResponse.error == nil {
		self.trains = trainResponse.trains!
	} else {
		// handle fetch error
	}
})

Error Handling

TrainResponse.error is a String? that has three possible values:

  1. nil
  • Fetch was successful
  1. "Internet connection is offline"
  2. "Prediction fetch failed (Code: [HTTP STATUS CODE])"
  • If the status code returned by the request is not 200 (success), this error will be thrown. It can be any HTTP status code, but will most likely be a 401 (Unauthorized) error, caused by an invalid WMATA API key.

Use these values to notify your user about the error.

Dependencies

Notable Projects

  • DC Metro Widget
  • Today extension for macOS' Notification Center
  • Inspiration for this Pod

License

WMATAFetcher is available under the MIT license. See the LICENSE file for more info.

Description
No description provided
Readme MIT 70 KiB
Languages
Swift 91.3%
Objective-C 4.9%
Ruby 3.8%