All Projects → alexander-albers → tripkit

alexander-albers / tripkit

Licence: MIT license
Swift library for querying data from public transport providers.

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to tripkit

kiel-live
This app allows you to view live updates of bus arrivals.
Stars: ✭ 20 (-60%)
Mutual labels:  public-transport, public-transit
gtfstools
General Transit Feed Specification (GTFS) Editing and Analysing Tools
Stars: ✭ 31 (-38%)
Mutual labels:  public-transport
Tire-a-part
Digital repository for the papers of a research organization.
Stars: ✭ 24 (-52%)
Mutual labels:  open-access
realtime-transport-dashboards
Serverless APIs for AWS to build and display public transports real time data (Serverless application example)
Stars: ✭ 23 (-54%)
Mutual labels:  public-transport
OA-signalling
A project to coordinate implementing a system to signal whether references cited on Wikipedia are free to reuse
Stars: ✭ 19 (-62%)
Mutual labels:  open-access
linked-connections-server
Express based server that exposes Linked Connections.
Stars: ✭ 12 (-76%)
Mutual labels:  public-transport
oabot
Adding links to full text in Wikipedia references
Stars: ✭ 33 (-34%)
Mutual labels:  open-access
european-transport-operators
NOT UP-TO-DATE ANYMORE, UNMAINTAINED. CHECK european-transport-feeds INSTEAD. List of european long-distance transport operators, available API endpoints, GTFS feeds and client modules.
Stars: ✭ 47 (-6%)
Mutual labels:  public-transport
hepdata
Repository for main HEPData web application
Stars: ✭ 33 (-34%)
Mutual labels:  open-access
comboios
Comboios de Portugal (CP, Portugese Railways) API client.
Stars: ✭ 32 (-36%)
Mutual labels:  public-transport
raptor
Implementation of the Route Based Public Transit Algorithm (Raptor)
Stars: ✭ 64 (+28%)
Mutual labels:  public-transport
From Python To Numpy
An open-access book on numpy vectorization techniques, Nicolas P. Rougier, 2017
Stars: ✭ 1,728 (+3356%)
Mutual labels:  open-access
PubMed2PDF
A Python package to download full article PDFs from OA publications
Stars: ✭ 19 (-62%)
Mutual labels:  open-access
roadoi
Use Unpaywall with R
Stars: ✭ 60 (+20%)
Mutual labels:  open-access
unpywall
Interfacing the Unpaywall Database with Python
Stars: ✭ 22 (-56%)
Mutual labels:  open-access
site
Website for the Open Scholarship Strategy
Stars: ✭ 21 (-58%)
Mutual labels:  open-access
transport-apis
machine-readable list of transport API endpoints
Stars: ✭ 32 (-36%)
Mutual labels:  public-transport
interrail
Find european train stations and routes. Client for the European Interrail / EuRail API.
Stars: ✭ 24 (-52%)
Mutual labels:  public-transport
db-prices
Find journey prices using the DB Sparpreise API.
Stars: ✭ 82 (+64%)
Mutual labels:  public-transport
sdk
🔧 TypeScript SDK for Entur APIs
Stars: ✭ 36 (-28%)
Mutual labels:  public-transport

TripKit

TripKit is a Swift-port of https://github.com/schildbach/public-transport-enabler with some additional enhancements. This library allows you to get data from public transport providers. You can get an overview of all supported transit providers here: https://navigatorapp.net/coverage. Look into NetworkProvider.swift for an overview of the API.

TripKit is built using Swift 5.0 and requires iOS 10.0/watchOS 3.0/tvOS 10.0/macOS 10.12.

This library is currently used by the ÖPNV Navigator app in the iOS App Store.

Static tests Provider tests

Integration

Use the Swift Package Manager to install TripKit into your project. If you have a Package.swift file, add the following entry to your dependencies:

import PackageDescription

let package = Package(
    name: "YOUR_PROJECT_NAME",
    dependencies: [
        // Insert the following line into your Swift package dependencies.
        .package(url: "https://github.com/alexander-albers/tripkit.git", .branch("main")),
    ],
)

If you are using a regular Xcode project, you can select "File" -> "Add Packages…" from the menu bar and paste the url of this git repository.

The tagged commits of this repository correspond to the released versions of the ÖPNV Navigator app and have no other meaning. I try to avoid code-breaking changes between releases as far as possible, but since this project is still under active development there is not guarantee that some minor things might break.

Example Usage

Create a new instance of a network provider:

let provider: NetworkProvider = KvvProvider() // Karlsruher Verkehrsverbund

Find locations for a given keyword:

let (request, result) = await provider.suggestLocations(constraint: "Marktplatz")
switch result {
case .success(let locations):
    for suggestedLocation in locations {
        print(suggestedLocation.location.getUniqueShortName())
    }
case .failure(let error):
    print(error)
}

Find locations near a coordinate (Marktplatz):

let (request, result) = await provider.queryNearbyLocations(location: Location(lat: 49009656, lon: 8402383))
switch result {
case .success(let locations):
    for location in locations {
        print(location.getUniqueShortName())
    }
case .failure(let error):
    print(error)
}

Query departures from Marktplatz (id=7001003):

let (request, result) = await provider.queryDepartures(stationId: "7001003")
switch result {
case .success(let departures):
    for departure in departures.flatMap { $0.departures } {
        let label = departure.line.label ?? "?"
        let destination = departure.destination?.getUniqueShortName() ?? "?"
        let time = departure.getTime()
        print("\(time): \(line) --> \(destination)")
    }
case .invalidStation:
    print("invalid station id")
case .failure(let error):
    print(error)
}

Query trips between Marktplatz (7001003) and Kronenplatz (7001002):

let (request, result) = await provider.queryTrips(from: Location(id: "7001003"), via: nil, to: Location(id: "7001002"))
switch result {
case .success(let context, let from, let via, let to, let trips, let messages):
    for trip in trips {
        print(trip.id)
    }
default:
    print("no trips could be found")
}

Query all intermediate stops of a line:

// journeyContext can be obtained from a PublicLeg instance.
let (request, result) = await provider.queryJourneyDetail(context: journeyContext)
switch result {
case .success(let trip, let leg):
    print(leg.intermediateStops)
case .invalidId:
    print("invalid context")
case .failure(let error):
    print(error)
}

More api methods can be found in NetworkProvider.swift and NetworkProvider+Async.swift.

Using providers that require secrets

For some providers a secret like an API key is required to use their API. You need to request the secrets directly from the provider or use the same ones that are used by the official apps.

For unit testing, you need to specify all required secrets in a secrets.json file. A template can be found here.

Contributing and future plans

Feel free to add further transit providers to the project, as long as they don't overlap with already existing ones and don't require too much maintenance or a server to be used. Since this project is based on the public-transport-enabler, my intention is to have this project as close to it as possible. For now, I'd like to stick to transit providers in German-speaking countries, but a further expansion to other countries is imaginable for the future.

Related Projects

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].