Skip to content
This repository has been archived by the owner on May 27, 2024. It is now read-only.

A Kotlin Multiplatform Mobile client library for the OpenTripPlanner project (http://www.opentripplanner.org/) server (v2 and higher)

License

Notifications You must be signed in to change notification settings

CUTR-at-USF/opentripplanner-client-library

Repository files navigation

OpenTripPlanner Client Library Gradle CI

A Kotlin Multiplatform library for making API requests and parsing responses from an OpenTripPlanner v2 server for the following OTP2 REST API endpoints:

  • /plan - Trip planning from an origin to a destination
  • /bike_rental - List of bike rental stations
  • /otp - Provides information about the OTP server (version, etc.)

Supported platforms are:

  • Android
  • iOS
  • JVM (Java/Kotlin)

Example use (Android)

Plan API

private lateinit var planApi: PlanApi
...
val requestParameters = RequestParameters(
  fromPlace = latLong(41.84712, -87.64678),
  toPlace = latLong(41.84584, -87.65214),
  arriveBy = "false")
planApi = PlanApi("https://10.0.2.2:8080/otp/routers/default/plan",  requestParameters)
planApi.getPlan(
    success = { launch (Main) {
        Log.d(TAG, "logData: $it")
    } },
    failure = ::handleError
)

You can set a URL parameter for an API key name and value (e.g., plan?...&key=ABCD...) if needed with:

...
planApi = PlanApi(...)
planApi.apiKey("key", "ABCD")
planApi.getPlan(
...

Bike Rental API

private lateinit var bikeRentalApi: BikeRentalApi
...
bikeRentalApi = BikeRentalApi("https://10.0.2.2:8080/otp/routers/default/bike_rental",
    lowerLeft = latLong(41.81712, -87.62678),
    upperRight = latLong(41.84584, -87.65214))

bikeRentalApi.getBikeRental(
    success = {launch (Main) { 
        Log.d(TAG, "logData: $it") 
    }},
    failure = ::handleError
)

Server Info API

private lateinit var serverInfoApi: ServerInfoApi
...
serverInfoApi = ServerInfoApi("https://10.0.2.2:8080/otp")
serverInfoApi.getServerInfo(
    success = {launch (Main) { logData(it) }},
    failure = ::handleError
)

Prerequisites

If you use Android Studio:

  1. Install Android Studio (preferably version 4.1.3 or higher).
  2. Before you import the project, install Kotlin MultiPlatform Mobile plugin via Settings (Preferences if on MacOS) -> Plugins -> Kotlin Multplatform Mobile -> Install

If you build from the command line using Gradle:

  1. Install Java JDK 8 or higher

Build

Import the project into Android Studio

Alternately, you can build from the command line using Gradle:

./gradlew build

Testing

  1. Set up an OTP2 server on your local machine, or get the URL for a public OTP2 server
  2. If you're testing the demo Android app on an emulator, you can use the default hard-coded host in MainActivity.kt of 10.0.2.2:8080. If you're testing on a physical device, make sure to change the host and port number in the API constructors to match the computer on your local network running OTP.
  3. Click on the green play button on top to run the Android demo app. OTP API responses will be logged in LogCat with the tag MainActivity.

Release

To create a release of the library on each platform, run the following commands.

Android

This command generates AAR files in otp-client-library/build/outputs/aar:

./gradlew :otp-client-library:build

iOS

This command generates Swift package files in common/swiftpackage directory:

./gradlew createSwiftPackage

Desktop Java/Kotlin

This command generates four JAR files in library/build/libs and we encourage you to use library-jvm-1.0.0.jar for manually including dependencies:

./gradlew :otp-client-library:build

To install to your local Maven repository you can run:

./gradlew publishToMavenLocal

...and include the dependency on this library in your application as:

implementation "edu.usf.cutr.otp:otp-client-library-jvm:1.0.0"

License

/*
 * Copyright (C) 2021 University of South Florida
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

Releases

No releases published

Packages

No packages published

Languages