Giter Club home page Giter Club logo

wmata.swift's Introduction

WMATA.swift

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

Install

Requirements

  • Swift 5.9
  • Xcode 15

Swift Package Manager

dependencies: [
    .package(
        name: "WMATA",
        url: "https://github.com/emma-k-alexandra/WMATA.swift.git", 
        .upToNextMajor(from: "15.0.0")
    )
]

Usage

Standard API

To work with WMATA's Standard API use the WMATA package.

import WMATA

let nextTrains = Rail.NextRails(
    key: YOUR_API_KEY,
    station: .waterfront
)

nextTrains.request { result in 
    switch result {
    case let .success(response):
        print(response.trains)
    case let .failure(error):
        print(error)
    }
}

GTFS Static

To work with GTFS Static data use the MetroGTFS package.

import MetroGTFS

let ashburn = try GTFSStop("STN_N12")

print(ashburn.name) // "ASHBURN METRORAIL STATION"

Documentation

Full documentation is available at https://emma-k-alexandra.github.io/WMATA.swift/documentation/wmata/ or within Xcode.

To view documentation within Xcode, within the menu navigate to Product > Build Documentation. WMATA's documentation will appear under Workspace Documentation within the Developer Documentation window. Navigate to Window > Developer Documentation to open this window.

OS Support

WMATA.swift commits to supporting current minus 2 OS versions.

Currently, WMATA.swift is compatible with macOS 12, iOS 15, tvOS 15, watchOS 8 or higher.

Versioning

WMATA.swift uses semantic versioning. Only major versions will contain breaking changes.

Dependencies

Contact

Feel free to email questions and comments to [email protected]

Contributing

Todo:

  • Support all GTFS Static data in MetroGTFS
  • Convert async functions from a Result to return or throw behavior, the dominant async pattern in Swift

Developer

To generate documentation for deploying to Github Pages, run ./docs.sh.

License

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

This package is not distributed by or affiliated with WMATA.

wmata.swift's People

Contributors

emma-k-alexandra avatar rhwood avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

rhwood

wmata.swift's Issues

Improve GTFS support

Currently, using GTFS feeds in the package is awful. There's no real way to get the data from the feeds. WMATA is focusing heavily on GTFS feeds. For example coming January 28th, 2022:

As of January 28, 2022, WMATA is proud to announce some major enhancements to the station data with the launch of platforms, levels, pathways, and more precise stop locations in GTFS feed. These features will deliver more accurate travel times for trips, easier wayfinding, and real-time accessible trip planning.

Developers can use this new information for a variety of improvements , such as:

· Improving wayfinding for trip plans by showing names and locations of station entrances, as well as platform information

· Displaying more details on maps, like separate entrance locations (and their accessibility) and platforms

· Providing more accurate station guides for users

· Delivering more accurate travel times for trips by incorporating pathways information and varying the time for accessible trips

Due to these enhancements, Stops Times and Trips in the GTFS feed will refer to new stops (platforms). Consequently, GTFS Static and GTFS RT will use these new stop ids. An example of the new GTFS feed can be found here.

Source https://developer.wmata.com

Allow parsing of GTFS APIs into structures a la standard API.

MetroBus.searchStops func errors with certain results

The WMATA result for https://api.wmata.com/Bus.svc/json/jStops?Lat=38.898303&Lon=-77.028099&Radius=100 returns

{
  "Stops": [{
    "StopID": "1001051",
    "Name": "F ST NW + 12TH ST NW",
    "Lon": -77.027878,
    "Lat": 38.897441,
    "Routes": ["54", "54*1"]
  }]
}

but this result leads to an error "The operation couldn’t be completed. (WMATA.WMATAError error 1.)" using this package.

Rework `Route` type

Since v11 of WMATA.swift, Route has been a typealias for String. Prior to v11, Route was a struct, and before that Route was an enum similar to Station, and way, way back Route was actually a class.

There's been a lot of shifting to figure out what the right type for this rather simple piece of data is. I think today's String value is the closest to correct so far, but it still isn't quite satisfactory. Some sharp edges remain with Routes that I think can be alleviated.

A Route has two fundamental parts: The actual route and the variant. Examples:

Route values: A4, Z8 W2

Variants values: /*2, *4, /

Both values can change often as new routes and variants are introduced. Currently, the String value of Route handles these frequent changes. However, several of WMATA's APIs like Bus.Positions and Bus.Incidents do not allow for variants when calling them. This is documented, but it's still possible to call the APIs using routes with variants since Route is just a String.

Here, the package can improve developer experience. If Route was its own type with knowledge of the route value and the variant provided by the developer, the package could choose to use the correct Route information in each endpoint. This would move guidance from documentation into typed checks in code, which is almost always preferable.

Here's the type I think could work well for Route:

struct Route: Codable, RawRepresentable {
    var route: String
    var variant: String?

    init(_ route: String, variant: String? = nil) {
       ...
    }
    
    init?(rawValue: String) {
        ...
    }
}

Route(rawValue: "Z8*4")
Route("10A")
Route("Z8", variant: "*4")

I think it could be a pain to parse the routes coming out go WMATA's API into their two parts because the WMATA is super inconsistent about naming route variants.

Overall though, I think this struct would allow the package to help the developer more and more accurately represent what a Route actually is.

Any input welcome.

v9 changed encoding of Route instances

When encoding a Route instance with JSONEncoder, previously a Route would be encoded as

"route": "10A"

under v9, Routes are encoded as

"route": { "id": "10A" }

which breaks Decoding & is a breaking change

Use `var` instead of `let` for `Endpoint.Response` properties

Currently I think the usage of let is a bit onerous in the data coming back from the API. I think it's fine if they're moved to vars, and could make some development a bit easier.

There currently isn't a great mechanism to modify the data you receive from the API without creating a brand new struct, which can be tedious. If your project uses the data structures provided by this package, and it needs to modify the data it gets in some way, I think it should be able to do that.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.