Swiftpack.co - Package - emma-foster/WMATA.swift

WMATA.swift

WMATA.swift is a lightweight Swift interface to the Washington Metropolitan Area Transit Authority API.

Contents

Requirements

  • Swift 5.1+

Installation

Swift Package Manager

dependencies: [
    .package(url: "https://github.com/emma-foster/WMATA.swift.git", from: "1.0.0")
]

Usage

Getting Started

import WMATA

WMATA(apiKey: apiKey)[.A01].nextTrains { (nextTrains, error) in
    print(nextTrains, error)

}

Design

WMATA.swift breaks the WMATA API into three pieces for each of MetroRail and MetroBus.

| MetroRail | MetroBus | | ------------- | ------------- | | Rail | Bus | | Line | Route | | Station | Stop | | WMATA|

WMATA

WMATA provides quick access to Rail and Bus objects, as well as provides a convienince subscripting for Line, Station and Routes via enums and Bus via String.

MetroRail

Rail provides general methods applicable to the entire MetroRail system. Line provides methods applicable to MetroRail lines (I.E. Blue, Red, Green). Station provides methods applicable to individual MetroRail stations (Metro Center).

MetroBus

Bus provides general methods applicable to the entire MetroBus system. Route provides methods applicable to a particular route (I.E. A12) Stop provides methods applicable to individual stops (I.E. 1001195)

Using Rail

Rail provides general methods applicable to the entire MetroRail system.

lines

WMATA Documentation
Returns basic information on all MetroRail lines.

Rail(apiKey: apiKey).lines { (lines, error) in
   print(lines, error)
}

entrances

WMATA Documentation
Station entrances within a latlong pair and radius (in meters). Omit all parameters to receive all entrances.

Rail(apiKey: apiKey).entrances(latitude: nil, longitude: nil, radius: nil) { (entrances, error) in
    print(entrances, error)
}

stations

WMATA Documentation
Stations along a Line (optional)

Rail(apiKey: apiKey).stations(for: .BL) { (stations, error) in
    print(stations, error)
}

station

WMATA Documentation
Distance, fare information and estimated travel time between two stations. Omit both station codes for all possible trips.

Rail(apiKey: apiKey).station(.A01, to: .A02) { (stationToStationInfos, error) in 
    print(stationToStationInfos, error)
}

positions

WMATA Documentation
Uniquely identifiable trains in service and what track circuits they currently occupy

Rail(apiKey: apiKey).positions { (positions, error) in
    print(positions, error)
}

routes

WMATA Documentation
Ordered list of track circuits, arranged by line and track number

Rail(apiKey: apiKey).routes { (routes, error) in 
    print(routes, error)
}

circuits

WMATA Documentation
List of all track circuits - also see TrainPositionsFAQ

Rail(apiKey: apiKey).circuits { (circuits, error) in 
    print(ciruits, error)
}

elevatorAndEscalatorIncidents

WMATA Documentation
Reported elevator and escalator incidents

Rail(apiKey: apiKey).elevatorAndEscalatorIncidents(at: .A01) { (incidents, error) in
    print(incidents, error)
}

incidents

WMATA Documentation
Reported MetroRail incidents at a particular station (optional)

Rail(apiKey: apiKey).incidents(at: nil) { (incidents, error) in
    print(incidents, error)
}

Using Line

Line provides methods applicable to MetroRail lines (I.E. Blue, Red, Green).

Line provides the Line.Code enum to refer to each MetroRail line.

stations

WMATA Documentation
Stations along a Line

Line(apiKey: apiKey, line: .BL).stations { (stations, error) in 
   print(stations, error)
}

Using Station

Station provides methods applicable to individual MetroRail stations (Metro Center).

Station defines Station.Code for identifying MetroRail stations.

nextTrains

WMATA Documentation
Next train arrivals for this station.

Station(apiKey: apiKey, code: .A01).nextTrains { (nextTrains, error) in
  print(nextTrains, error)
}

information

WMATA Documentation
Location and address information for this station.

Station(apiKey: apiKey, code: .A01).information { (information, error) in
  print(information, error)
}

parkingInformation

WMATA Documentation
Parking information for this station.

Station(apiKey: apiKey, code: .A01).parkingInformation { (parkingInformation, error} in
    print(parkingInformation)
}

path

WMATA Documentation
Returns a set of ordered stations and distances between stations on the same line

Station(apiKey: apiKey, code: .A01).path(to: .A02) { (pathBetweenStations, error) in
    print(pathBetweenStations, error))
}

timings

WMATA Documentation
Opening times and scheduled first and last trains for this station

Station(apiKey: apiKey, code: .A01).timings { (timings, error) in
    print(timings, error)
}

to

WMATA Documentation
Distance, fare and estimated travel time between this and another station, including stations on a different line

Station(apiKey: apiKey, code: .A01).to(.A02) { (stationToStationInfos, error) in
    print(stationToStationInfos, error)
}

Using Bus

Bus provides general methods applicable to the entire MetroBus system.

positions

WMATA Documentation
Bus positions along a route (optional), at a latlong and within a radius (in meters)

Bus(apiKey: apiKey).positions(routeId: ._10A, latitude: nil, longitude: nil, radius: nil) { (positions, error) in
    print(positions, error)
}

routes

WMATA Documentation
All bus routes

Bus(apiKey: apiKey).routes { (routes, error) in
    print(routes, error)
}

searchStops

WMATA Documentation
Stops near a given latlong and within a given radius. Omit all parameters to receive all stops.

Bus(apiKey: apiKey).searchStops(latitude: nil, longitude: nil, radius: nil) { (stops, error) in
    print(stops, error)
}

incidents

WMATA Documentation
MetroBus incidents along an optional route.

Bus(apiKey: apiKey).incidents(route: ._10A) { (incidents, error) in
    print(incidents, error)
}

Using Route

Route provides methods applicable to a particular route (I.E. A12)

Route defines Route.Id to identify routes. Note: Ids which start with a number are prefixed by an underscore (I.E. .10A is actually ._10A due to Swift naming limitations. This does not effect the rawValue of the value.

positions

WMATA Documentation
Bus positions along this route, within an optional latlong and radius (in meters).

Route(apiKey: apiKey, routeId: ._10A).positions(latitude: nil, longitude: nil, radius: nil) { (positions, error) in
    print(positions, error)
}

pathDetails

WMATA Documentation
Ordered latlong points along this Route for a given date (in YYYY-MM-DD format). Omit for today.

Route(apiKey: apiKey, routeId: ._10A).pathDetails { (pathDetails, error) in
    print(pathDetails, error)
}

schedule

WMATA Documentation
Scheduled stops for this Route

Route(apiKey: apiKey, routeId: ._10A).schedule { (stops, error) in
    print(stops, error))
}

Using Stop

Stop provides methods applicable to individual stops (I.E. 1001195). Note that Stops are identified by 7-character regional stop IDs.

nextBuses

WMATA Documentation
Next bus arrivals at this Stop

Stop(apiKey: apiKey, stopId: "1001195").nextBuses { (buses, error) in
    print(buses, error)
}

schedule

WMATA Documentation
Buses scheduled to arrival at this Stop at a given date (in YYYY-MM-DD format, optional)

Stop(apiKey: apiKey, stopId: "1001195").schedule { (schedule, error) in
    print(schedule, error)
}

Dependencies

None!

Contact

Feel free to email questions and comments to emma@emma.sh

License

WMATA.swift is released under the MIT license. See LICENSE for details.

Github

link
Stars: 4
Help us keep the lights on

Dependencies

Used By

Total: 0