-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: onebusaway-sdk-kotlin examples
- Loading branch information
1 parent
1a37662
commit ce8b134
Showing
23 changed files
with
876 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
plugins { | ||
kotlin("jvm") | ||
} | ||
|
||
group = "org.onebusaway.example" | ||
version = "0.0.1-alpha.0" | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
implementation(project(":onebusaway-sdk-kotlin")) | ||
testImplementation(platform("org.junit:junit-bom:5.9.1")) | ||
testImplementation("org.junit.jupiter:junit-jupiter") | ||
} | ||
|
||
tasks.test { | ||
useJUnitPlatform() | ||
} |
31 changes: 31 additions & 0 deletions
31
onebusaway-sdk-kotlin-example/src/main/kotlin/org/onebusaway/example/AgenciesWithCoverage.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.onebusaway.example | ||
|
||
import org.onebusaway.client.OnebusawaySdkClient | ||
import org.onebusaway.client.okhttp.OnebusawaySdkOkHttpClient | ||
import org.onebusaway.models.* | ||
|
||
object AgenciesWithCoverage { | ||
|
||
// Retrieve constants from environment variables or fallback to default values | ||
private val API_KEY: String = System.getenv("ONEBUSAWAY_API_KEY") ?: "TEST" | ||
private val BASE_URL: String = System.getenv("ONEBUSAWAY_BASE_URL") ?: "https://api.pugetsound.onebusaway.org" | ||
|
||
// Initialize the Onebusaway SDK client | ||
private val client: OnebusawaySdkClient = OnebusawaySdkOkHttpClient.builder() | ||
.apiKey(API_KEY) | ||
.baseUrl(BASE_URL) | ||
.build() | ||
|
||
@JvmStatic | ||
fun main(args: Array<String>) { | ||
// Define the required Params | ||
val params = AgenciesWithCoverageListParams.builder().build() | ||
|
||
// Get the agencies with coverage | ||
val agencies: AgenciesWithCoverageListResponse = client.agenciesWithCoverage().list(params) | ||
|
||
for (agency in agencies.data().list()) { | ||
println(agency) | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
onebusaway-sdk-kotlin-example/src/main/kotlin/org/onebusaway/example/Agency.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package org.onebusaway.example | ||
|
||
import org.onebusaway.client.OnebusawaySdkClient | ||
import org.onebusaway.client.okhttp.OnebusawaySdkOkHttpClient | ||
import org.onebusaway.models.* | ||
|
||
object Agency { | ||
|
||
// Retrieve constants from environment variables or fallback to default values | ||
private val API_KEY: String = System.getenv("ONEBUSAWAY_API_KEY") ?: "TEST" | ||
private val BASE_URL: String = System.getenv("ONEBUSAWAY_BASE_URL") ?: "https://api.pugetsound.onebusaway.org" | ||
|
||
// Initialize the Onebusaway SDK client | ||
private val client: OnebusawaySdkClient = OnebusawaySdkOkHttpClient.builder() | ||
.apiKey(API_KEY) | ||
.baseUrl(BASE_URL) | ||
.build() | ||
|
||
@JvmStatic | ||
fun main(args: Array<String>) { | ||
|
||
println(args) | ||
// Define the agency ID | ||
val agencyId = "1" | ||
|
||
// Define the parameters for the agency retrieval request | ||
val params = AgencyRetrieveParams.builder().agencyId(agencyId).build() | ||
|
||
// Retrieve the agency information | ||
val agency: AgencyRetrieveResponse = client.agency().retrieve(params) | ||
|
||
println(agency) | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...y-sdk-kotlin-example/src/main/kotlin/org/onebusaway/example/ArrivalAndDepartureForStop.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.onebusaway.example | ||
|
||
import org.onebusaway.client.OnebusawaySdkClient | ||
import org.onebusaway.client.okhttp.OnebusawaySdkOkHttpClient | ||
import org.onebusaway.models.* | ||
|
||
object ArrivalAndDepartureForStop { | ||
|
||
// Retrieve constants from environment variables or fallback to default values | ||
private val API_KEY: String = System.getenv("ONEBUSAWAY_API_KEY") ?: "TEST" | ||
private val BASE_URL: String = System.getenv("ONEBUSAWAY_BASE_URL") ?: "https://api.pugetsound.onebusaway.org" | ||
|
||
// Initialize the Onebusaway SDK client | ||
private val client: OnebusawaySdkClient = OnebusawaySdkOkHttpClient.builder() | ||
.apiKey(API_KEY) | ||
.baseUrl(BASE_URL) | ||
.build() | ||
|
||
@JvmStatic | ||
fun main(args: Array<String>) { | ||
// Define the stop ID and trip ID | ||
val stopId = "1_75403" | ||
val tripId = "1_604670535" | ||
|
||
// Define the service date directly as a Unix timestamp (in seconds) | ||
val serviceDate: Long = 1810918000 // Example timestamp | ||
|
||
// Create parameters for arrival and departure request | ||
val params = ArrivalAndDepartureRetrieveParams.builder() | ||
.stopId(stopId) | ||
.tripId(tripId) | ||
.serviceDate(serviceDate) // Use the Unix timestamp directly | ||
.build() | ||
|
||
// Retrieve arrival and departure information | ||
val arrivalAndDepartureForStop: ArrivalAndDepartureRetrieveResponse = client.arrivalAndDeparture().retrieve(params) | ||
println(arrivalAndDepartureForStop) | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...sdk-kotlin-example/src/main/kotlin/org/onebusaway/example/ArrivalsAndDeparturesForStop.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package org.onebusaway.example | ||
|
||
import org.onebusaway.client.OnebusawaySdkClient | ||
import org.onebusaway.client.okhttp.OnebusawaySdkOkHttpClient | ||
import org.onebusaway.models.* | ||
|
||
object ArrivalsAndDeparturesForStop { | ||
|
||
// Retrieve constants from environment variables or fallback to default values | ||
private val API_KEY: String = System.getenv("ONEBUSAWAY_API_KEY") ?: "TEST" | ||
private val BASE_URL: String = System.getenv("ONEBUSAWAY_BASE_URL") ?: "https://api.pugetsound.onebusaway.org" | ||
|
||
// Initialize the Onebusaway SDK client | ||
private val client: OnebusawaySdkClient = OnebusawaySdkOkHttpClient.builder() | ||
.apiKey(API_KEY) | ||
.baseUrl(BASE_URL) | ||
.build() | ||
|
||
@JvmStatic | ||
fun main(args: Array<String>) { | ||
// Define the stop ID | ||
val stopId = "1_75403" | ||
val minutesBefore: Long = 5 | ||
val minutesAfter: Long = 35 | ||
|
||
|
||
// Define the parameters for the arrival and departure list request | ||
val params = ArrivalAndDepartureListParams.builder() | ||
.stopId(stopId) | ||
.minutesBefore(minutesBefore) | ||
.minutesAfter(minutesAfter) | ||
.build() | ||
|
||
// Retrieve arrival and departure information | ||
val arrivalsAndDeparturesForStop: ArrivalAndDepartureListResponse = client.arrivalAndDeparture().list(params) | ||
|
||
for (arrivalAndDeparture in arrivalsAndDeparturesForStop.data().entry().arrivalsAndDepartures()) { | ||
println(arrivalAndDeparture) | ||
} | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
onebusaway-sdk-kotlin-example/src/main/kotlin/org/onebusaway/example/Block.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package org.onebusaway.example | ||
|
||
import org.onebusaway.client.OnebusawaySdkClient | ||
import org.onebusaway.client.okhttp.OnebusawaySdkOkHttpClient | ||
import org.onebusaway.errors.OnebusawaySdkServiceException | ||
import org.onebusaway.models.* | ||
|
||
object Block { | ||
|
||
// Retrieve constants from environment variables or fallback to default values | ||
private val API_KEY: String = System.getenv("ONEBUSAWAY_API_KEY") ?: "TEST" | ||
private val BASE_URL: String = System.getenv("ONEBUSAWAY_BASE_URL") ?: "https://api.pugetsound.onebusaway.org" | ||
|
||
// Initialize the Onebusaway SDK client | ||
private val client: OnebusawaySdkClient = OnebusawaySdkOkHttpClient.builder() | ||
.apiKey(API_KEY) | ||
.baseUrl(BASE_URL) | ||
.build() | ||
|
||
@JvmStatic | ||
fun main(args: Array<String>) { | ||
// Define the block ID | ||
val blockId = "1_7331695" | ||
|
||
try { | ||
// Define the parameters for the block retrieval request | ||
val params = BlockRetrieveParams.builder().blockId(blockId).build() | ||
|
||
// Retrieve the block information | ||
val block: BlockRetrieveResponse = client.block().retrieve(params) | ||
|
||
println(block) | ||
|
||
} catch (e: OnebusawaySdkServiceException) { | ||
// Handle the SDK-specific service exception | ||
println("Error occurred: ${e.message}") | ||
println("Status Code: ${e.statusCode()}") | ||
} catch (e: Exception) { | ||
e.printStackTrace() | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
onebusaway-sdk-kotlin-example/src/main/kotlin/org/onebusaway/example/CurrentTime.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package org.onebusaway.example | ||
|
||
import org.onebusaway.client.OnebusawaySdkClient | ||
import org.onebusaway.client.okhttp.OnebusawaySdkOkHttpClient | ||
import org.onebusaway.models.* | ||
|
||
object CurrentTime { | ||
|
||
// Retrieve constants from environment variables or fallback to default values | ||
private val API_KEY: String = System.getenv("ONEBUSAWAY_API_KEY") ?: "TEST" | ||
private val BASE_URL: String = System.getenv("ONEBUSAWAY_BASE_URL") ?: "https://api.pugetsound.onebusaway.org" | ||
|
||
// Initialize the Onebusaway SDK client | ||
private val client: OnebusawaySdkClient = OnebusawaySdkOkHttpClient.builder() | ||
.apiKey(API_KEY) | ||
.baseUrl(BASE_URL) | ||
.build() | ||
|
||
@JvmStatic | ||
fun main(args: Array<String>) { | ||
// Define the parameters for the current time retrieval request | ||
val params = CurrentTimeRetrieveParams.builder().build() | ||
|
||
// Retrieve the current time information | ||
val currentTime: CurrentTimeRetrieveResponse = client.currentTime().retrieve(params) | ||
|
||
println(currentTime) | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
onebusaway-sdk-kotlin-example/src/main/kotlin/org/onebusaway/example/Route.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package org.onebusaway.example | ||
|
||
import org.onebusaway.client.OnebusawaySdkClient | ||
import org.onebusaway.client.okhttp.OnebusawaySdkOkHttpClient | ||
import org.onebusaway.errors.OnebusawaySdkServiceException | ||
import org.onebusaway.models.* | ||
|
||
object Route { | ||
|
||
// Retrieve constants from environment variables or fallback to default values | ||
private val API_KEY: String = System.getenv("ONEBUSAWAY_API_KEY") ?: "TEST" | ||
private val BASE_URL: String = System.getenv("ONEBUSAWAY_BASE_URL") ?: "https://api.pugetsound.onebusaway.org" | ||
|
||
// Initialize the Onebusaway SDK client | ||
private val client: OnebusawaySdkClient = OnebusawaySdkOkHttpClient.builder() | ||
.apiKey(API_KEY) | ||
.baseUrl(BASE_URL) | ||
.build() | ||
|
||
@JvmStatic | ||
fun main(args: Array<String>) { | ||
// Define the route ID | ||
val routeId = "1_100224" | ||
|
||
try { | ||
val params = RouteRetrieveParams.builder().routeId(routeId).build() | ||
|
||
val route: RouteRetrieveResponse = client.route().retrieve(params) | ||
|
||
println(route) | ||
|
||
} catch (e: OnebusawaySdkServiceException) { | ||
// Handle the SDK-specific service exception | ||
System.err.println("Error occurred: ${e.message}") | ||
System.err.println("Status Code: ${e.statusCode()}") | ||
} | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
onebusaway-sdk-kotlin-example/src/main/kotlin/org/onebusaway/example/RouteForAgency.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package org.onebusaway.example | ||
|
||
import org.onebusaway.client.OnebusawaySdkClient | ||
import org.onebusaway.client.okhttp.OnebusawaySdkOkHttpClient | ||
import org.onebusaway.errors.OnebusawaySdkServiceException | ||
import org.onebusaway.models.* | ||
|
||
object RouteForAgency { | ||
|
||
// Retrieve constants from environment variables or fallback to default values | ||
private val API_KEY: String = System.getenv("ONEBUSAWAY_API_KEY") ?: "TEST" | ||
private val BASE_URL: String = System.getenv("ONEBUSAWAY_BASE_URL") ?: "https://api.pugetsound.onebusaway.org" | ||
|
||
// Initialize the Onebusaway SDK client | ||
private val client: OnebusawaySdkClient = OnebusawaySdkOkHttpClient.builder() | ||
.apiKey(API_KEY) | ||
.baseUrl(BASE_URL) | ||
.build() | ||
|
||
@JvmStatic | ||
fun main(args: Array<String>) { | ||
try { | ||
// Define the agency ID | ||
val agencyId = "1" | ||
|
||
// Create the parameters for the routes for agency list request | ||
val params = RoutesForAgencyListParams.builder() | ||
.agencyId(agencyId) | ||
.build() | ||
|
||
// Retrieve the routes for the agency | ||
val routesForAgency: RoutesForAgencyListResponse = client.routesForAgency().list(params) | ||
|
||
for (route in routesForAgency.data().list()) { | ||
println(route) | ||
} | ||
} catch (e: OnebusawaySdkServiceException) { | ||
// Handle the SDK-specific service exception | ||
System.err.println("Error occurred: ${e.message}") | ||
System.err.println("Status Code: ${e.statusCode()}") | ||
} catch (e: Exception) { | ||
System.err.println("Error occurred: ${e.message}") | ||
} | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
onebusaway-sdk-kotlin-example/src/main/kotlin/org/onebusaway/example/RoutesForLocation.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package org.onebusaway.example | ||
|
||
import org.onebusaway.client.OnebusawaySdkClient | ||
import org.onebusaway.client.okhttp.OnebusawaySdkOkHttpClient | ||
import org.onebusaway.models.* | ||
|
||
object RoutesForLocation { | ||
|
||
// Retrieve constants from environment variables or fallback to default values | ||
private val API_KEY: String = System.getenv("ONEBUSAWAY_API_KEY") ?: "TEST" | ||
private val BASE_URL: String = System.getenv("ONEBUSAWAY_BASE_URL") ?: "https://api.pugetsound.onebusaway.org" | ||
|
||
// Initialize the Onebusaway SDK client | ||
private val client: OnebusawaySdkClient = OnebusawaySdkOkHttpClient.builder() | ||
.apiKey(API_KEY) | ||
.baseUrl(BASE_URL) | ||
.build() | ||
|
||
@JvmStatic | ||
fun main(args: Array<String>) { | ||
try { | ||
// Define the location parameters | ||
val lat = 47.653435 | ||
val lon = -122.305641 | ||
val radius = 1000.0 | ||
|
||
// Create the parameters for the routes for location request | ||
val params = RoutesForLocationListParams.builder() | ||
.lat(lat) | ||
.lon(lon) | ||
.radius(radius) | ||
.build() | ||
|
||
// Retrieve the routes for location | ||
val routesForLocation: RoutesForLocationListResponse = client.routesForLocation().list(params) | ||
|
||
for (route in routesForLocation.data().list()) { | ||
println(route) | ||
} | ||
} catch (e: Exception) { | ||
System.err.println("Error occurred: ${e.message}") | ||
} | ||
} | ||
} |
Oops, something went wrong.