diff --git a/onebusaway-sdk-kotlin-example/build.gradle.kts b/onebusaway-sdk-kotlin-example/build.gradle.kts new file mode 100644 index 0000000..53a8a2b --- /dev/null +++ b/onebusaway-sdk-kotlin-example/build.gradle.kts @@ -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() +} \ No newline at end of file diff --git a/onebusaway-sdk-kotlin-example/src/main/kotlin/org/onebusaway/example/AgenciesWithCoverage.kt b/onebusaway-sdk-kotlin-example/src/main/kotlin/org/onebusaway/example/AgenciesWithCoverage.kt new file mode 100644 index 0000000..3beae6d --- /dev/null +++ b/onebusaway-sdk-kotlin-example/src/main/kotlin/org/onebusaway/example/AgenciesWithCoverage.kt @@ -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) { + // 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) + } + } +} diff --git a/onebusaway-sdk-kotlin-example/src/main/kotlin/org/onebusaway/example/Agency.kt b/onebusaway-sdk-kotlin-example/src/main/kotlin/org/onebusaway/example/Agency.kt new file mode 100644 index 0000000..2abade0 --- /dev/null +++ b/onebusaway-sdk-kotlin-example/src/main/kotlin/org/onebusaway/example/Agency.kt @@ -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) { + + 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) + } +} diff --git a/onebusaway-sdk-kotlin-example/src/main/kotlin/org/onebusaway/example/ArrivalAndDepartureForStop.kt b/onebusaway-sdk-kotlin-example/src/main/kotlin/org/onebusaway/example/ArrivalAndDepartureForStop.kt new file mode 100644 index 0000000..92b80c1 --- /dev/null +++ b/onebusaway-sdk-kotlin-example/src/main/kotlin/org/onebusaway/example/ArrivalAndDepartureForStop.kt @@ -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) { + // 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) + } +} diff --git a/onebusaway-sdk-kotlin-example/src/main/kotlin/org/onebusaway/example/ArrivalsAndDeparturesForStop.kt b/onebusaway-sdk-kotlin-example/src/main/kotlin/org/onebusaway/example/ArrivalsAndDeparturesForStop.kt new file mode 100644 index 0000000..0d85f59 --- /dev/null +++ b/onebusaway-sdk-kotlin-example/src/main/kotlin/org/onebusaway/example/ArrivalsAndDeparturesForStop.kt @@ -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) { + // 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) + } + } +} diff --git a/onebusaway-sdk-kotlin-example/src/main/kotlin/org/onebusaway/example/Block.kt b/onebusaway-sdk-kotlin-example/src/main/kotlin/org/onebusaway/example/Block.kt new file mode 100644 index 0000000..36debeb --- /dev/null +++ b/onebusaway-sdk-kotlin-example/src/main/kotlin/org/onebusaway/example/Block.kt @@ -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) { + // 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() + } + } +} diff --git a/onebusaway-sdk-kotlin-example/src/main/kotlin/org/onebusaway/example/CurrentTime.kt b/onebusaway-sdk-kotlin-example/src/main/kotlin/org/onebusaway/example/CurrentTime.kt new file mode 100644 index 0000000..295ae2b --- /dev/null +++ b/onebusaway-sdk-kotlin-example/src/main/kotlin/org/onebusaway/example/CurrentTime.kt @@ -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) { + // 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) + } +} diff --git a/onebusaway-sdk-kotlin-example/src/main/kotlin/org/onebusaway/example/Route.kt b/onebusaway-sdk-kotlin-example/src/main/kotlin/org/onebusaway/example/Route.kt new file mode 100644 index 0000000..e80f920 --- /dev/null +++ b/onebusaway-sdk-kotlin-example/src/main/kotlin/org/onebusaway/example/Route.kt @@ -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) { + // 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()}") + } + } +} diff --git a/onebusaway-sdk-kotlin-example/src/main/kotlin/org/onebusaway/example/RouteForAgency.kt b/onebusaway-sdk-kotlin-example/src/main/kotlin/org/onebusaway/example/RouteForAgency.kt new file mode 100644 index 0000000..32be48f --- /dev/null +++ b/onebusaway-sdk-kotlin-example/src/main/kotlin/org/onebusaway/example/RouteForAgency.kt @@ -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) { + 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}") + } + } +} diff --git a/onebusaway-sdk-kotlin-example/src/main/kotlin/org/onebusaway/example/RoutesForLocation.kt b/onebusaway-sdk-kotlin-example/src/main/kotlin/org/onebusaway/example/RoutesForLocation.kt new file mode 100644 index 0000000..219f438 --- /dev/null +++ b/onebusaway-sdk-kotlin-example/src/main/kotlin/org/onebusaway/example/RoutesForLocation.kt @@ -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) { + 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}") + } + } +} diff --git a/onebusaway-sdk-kotlin-example/src/main/kotlin/org/onebusaway/example/ScheduleForRoute.kt b/onebusaway-sdk-kotlin-example/src/main/kotlin/org/onebusaway/example/ScheduleForRoute.kt new file mode 100644 index 0000000..036f864 --- /dev/null +++ b/onebusaway-sdk-kotlin-example/src/main/kotlin/org/onebusaway/example/ScheduleForRoute.kt @@ -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 ScheduleForRoute { + + // 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) { + // Define the route ID + val routeId = "1_100223" + + try { + // Define the parameters for the schedule for route request + val params = ScheduleForRouteRetrieveParams.builder() + .routeId(routeId) + .build() + + // Retrieve the schedule for the route + val scheduleForRoute: ScheduleForRouteRetrieveResponse = client.scheduleForRoute().retrieve(params) + + println(scheduleForRoute) + + } catch (e: OnebusawaySdkServiceException) { + // Handle HTTP errors + System.err.println("Error occurred: ${e.message}") + System.err.println("Status Code: ${e.statusCode()}") + } catch (e: Exception) { + // Handle general errors + System.err.println("Error occurred: ${e.message}") + } + } +} diff --git a/onebusaway-sdk-kotlin-example/src/main/kotlin/org/onebusaway/example/SearchForRoute.kt b/onebusaway-sdk-kotlin-example/src/main/kotlin/org/onebusaway/example/SearchForRoute.kt new file mode 100644 index 0000000..e2fca8e --- /dev/null +++ b/onebusaway-sdk-kotlin-example/src/main/kotlin/org/onebusaway/example/SearchForRoute.kt @@ -0,0 +1,34 @@ +package org.onebusaway.example + +import org.onebusaway.client.OnebusawaySdkClient +import org.onebusaway.client.okhttp.OnebusawaySdkOkHttpClient +import org.onebusaway.models.* + +object SearchForRoute { + + // 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) { + // Define the search input + val searchInput = "crysta" + + // Create the parameters for the route search request + val params = SearchForRouteListParams.builder() + .input(searchInput) + .build() + + // Retrieve the route search results + val searchForRouteListResponse: SearchForRouteListResponse = client.searchForRoute().list(params) + + println(searchForRouteListResponse) + } +} diff --git a/onebusaway-sdk-kotlin-example/src/main/kotlin/org/onebusaway/example/SearchForStop.kt b/onebusaway-sdk-kotlin-example/src/main/kotlin/org/onebusaway/example/SearchForStop.kt new file mode 100644 index 0000000..bdf29db --- /dev/null +++ b/onebusaway-sdk-kotlin-example/src/main/kotlin/org/onebusaway/example/SearchForStop.kt @@ -0,0 +1,34 @@ +package org.onebusaway.example + +import org.onebusaway.client.OnebusawaySdkClient +import org.onebusaway.client.okhttp.OnebusawaySdkOkHttpClient +import org.onebusaway.models.* + +object SearchForStop { + + // 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) { + // Define the search input + val searchInput = "crysta" + + // Create the parameters for the stop search request + val params = SearchForStopListParams.builder() + .input(searchInput) + .build() + + // Retrieve the stop search results + val searchForStopListResponse: SearchForStopListResponse = client.searchForStop().list(params) + + println(searchForStopListResponse) + } +} diff --git a/onebusaway-sdk-kotlin-example/src/main/kotlin/org/onebusaway/example/Shape.kt b/onebusaway-sdk-kotlin-example/src/main/kotlin/org/onebusaway/example/Shape.kt new file mode 100644 index 0000000..25bb207 --- /dev/null +++ b/onebusaway-sdk-kotlin-example/src/main/kotlin/org/onebusaway/example/Shape.kt @@ -0,0 +1,34 @@ +package org.onebusaway.example + +import org.onebusaway.client.OnebusawaySdkClient +import org.onebusaway.client.okhttp.OnebusawaySdkOkHttpClient +import org.onebusaway.models.* + +object Shape { + + // 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) { + // Define the shape ID + val shapeId = "1_10002005" + + // Define the parameters for the shape retrieval request + val params = ShapeRetrieveParams.builder() + .shapeId(shapeId) + .build() + + // Retrieve the shape information + val shape: ShapeRetrieveResponse = client.shape().retrieve(params) + + println(shape.data()) + } +} diff --git a/onebusaway-sdk-kotlin-example/src/main/kotlin/org/onebusaway/example/Stop.kt b/onebusaway-sdk-kotlin-example/src/main/kotlin/org/onebusaway/example/Stop.kt new file mode 100644 index 0000000..0408bab --- /dev/null +++ b/onebusaway-sdk-kotlin-example/src/main/kotlin/org/onebusaway/example/Stop.kt @@ -0,0 +1,34 @@ +package org.onebusaway.example + +import org.onebusaway.client.OnebusawaySdkClient +import org.onebusaway.client.okhttp.OnebusawaySdkOkHttpClient +import org.onebusaway.models.* + +object Stop { + + // 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) { + // Define the stop ID + val stopID = "1_75403" + + // Define the parameters for the stop retrieval request + val params = StopRetrieveParams.builder() + .stopId(stopID) + .build() + + // Retrieve the stop information + val stop: StopRetrieveResponse = client.stop().retrieve(params) + + println(stop) + } +} diff --git a/onebusaway-sdk-kotlin-example/src/main/kotlin/org/onebusaway/example/StopsForLocation.kt b/onebusaway-sdk-kotlin-example/src/main/kotlin/org/onebusaway/example/StopsForLocation.kt new file mode 100644 index 0000000..4ea76f0 --- /dev/null +++ b/onebusaway-sdk-kotlin-example/src/main/kotlin/org/onebusaway/example/StopsForLocation.kt @@ -0,0 +1,82 @@ +package org.onebusaway.example + +import org.onebusaway.client.OnebusawaySdkClient +import org.onebusaway.client.okhttp.OnebusawaySdkOkHttpClient +import org.onebusaway.models.* + +object StopsForLocation { + + // 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) { + // Define location parameters (example: Space Needle) + val lat = 47.6205 + val lon = -122.3493 + val radius = 500.0 + + // Build request parameters for fetching stops + val params = StopsForLocationListParams.builder() + .lat(lat) + .lon(lon) + .radius(radius) + .build() + + // Fetch stops for the given location + val response: StopsForLocationListResponse = client.stopsForLocation().list(params) + + // Extract the data and references from the response + val data = response.data() + val references = data.references() + val stops = data.list() + + // Create a map to reference routes by their IDs for faster lookup + val referenceMap: MutableMap = mutableMapOf() + for (route in references.routes()) { + referenceMap[route.id()] = route + } + + // Print information for each stop + for (stop in stops) { + println("${stop.name()} (${stop.lat()}, ${stop.lon()})") + println(" Routes:") + + // For each stop, print associated routes + for (routeId in stop.routeIds()) { + val route = referenceMap[routeId] ?: continue // Skip if route is not found + + // Build a description for the route + val routeDescription = buildRouteDescription(route) + println(" $routeDescription") + } + + println() + } + } + + // Helper method to build the route description using optional values + private fun buildRouteDescription(route: References.Route): String { + val description = StringBuilder() + + // Append short name if present + route.shortName()?.let { description.append(it) } + + // Append description if present + route.description()?.let { desc -> + if (description.isNotEmpty()) { + description.append(" - ") + } + description.append(desc) + } + + return description.toString() + } +} diff --git a/onebusaway-sdk-kotlin-example/src/main/kotlin/org/onebusaway/example/StopsForRoute.kt b/onebusaway-sdk-kotlin-example/src/main/kotlin/org/onebusaway/example/StopsForRoute.kt new file mode 100644 index 0000000..5910574 --- /dev/null +++ b/onebusaway-sdk-kotlin-example/src/main/kotlin/org/onebusaway/example/StopsForRoute.kt @@ -0,0 +1,32 @@ +package org.onebusaway.example + +import org.onebusaway.client.OnebusawaySdkClient +import org.onebusaway.client.okhttp.OnebusawaySdkOkHttpClient +import org.onebusaway.models.* + +object StopsForRoute { + + // 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) { + // Define the route ID + val routeId = "1_100229" + + // Build request parameters for fetching stops for the route + val params = StopsForRouteListParams.builder().routeId(routeId).build() + + // Get the stops for the route + val stops: StopsForRouteListResponse = client.stopsForRoute().list(params) + + println(stops) + } +} diff --git a/onebusaway-sdk-kotlin-example/src/main/kotlin/org/onebusaway/example/StopsIdsForAgency.kt b/onebusaway-sdk-kotlin-example/src/main/kotlin/org/onebusaway/example/StopsIdsForAgency.kt new file mode 100644 index 0000000..504af13 --- /dev/null +++ b/onebusaway-sdk-kotlin-example/src/main/kotlin/org/onebusaway/example/StopsIdsForAgency.kt @@ -0,0 +1,34 @@ +package org.onebusaway.example + +import org.onebusaway.client.OnebusawaySdkClient +import org.onebusaway.client.okhttp.OnebusawaySdkOkHttpClient +import org.onebusaway.models.* + +object StopsIdsForAgency { + + // 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) { + // Define the agency ID + val agencyId = "1" + + // Build request parameters for fetching stop IDs for the agency + val params = StopIdsForAgencyListParams.builder().agencyId(agencyId).build() + + // Get the list of stop IDs for the agency + val stopIds: StopIdsForAgencyListResponse = client.stopIdsForAgency().list(params) + + for (stopId in stopIds.data().list()) { + println(stopId) + } + } +} diff --git a/onebusaway-sdk-kotlin-example/src/main/kotlin/org/onebusaway/example/Trip.kt b/onebusaway-sdk-kotlin-example/src/main/kotlin/org/onebusaway/example/Trip.kt new file mode 100644 index 0000000..59230a6 --- /dev/null +++ b/onebusaway-sdk-kotlin-example/src/main/kotlin/org/onebusaway/example/Trip.kt @@ -0,0 +1,42 @@ +package org.onebusaway.example + +import org.onebusaway.client.OnebusawaySdkClient +import org.onebusaway.client.okhttp.OnebusawaySdkOkHttpClient +import org.onebusaway.errors.OnebusawaySdkException +import org.onebusaway.models.* + +object Trip { + + // 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) { + + try { + // Define the trip ID + val tripId = "40_608344966" + + // Create the parameters for the trip retrieve request + val params = TripRetrieveParams.builder() + .tripId(tripId) + .build() + + // Retrieve the trip + val trip: TripRetrieveResponse = client.trip().retrieve(params) + + println(trip) + } + catch (onebusawayException: OnebusawaySdkException) { + println(onebusawayException) + } + + } +} diff --git a/onebusaway-sdk-kotlin-example/src/main/kotlin/org/onebusaway/example/TripDetails.kt b/onebusaway-sdk-kotlin-example/src/main/kotlin/org/onebusaway/example/TripDetails.kt new file mode 100644 index 0000000..ab3e8eb --- /dev/null +++ b/onebusaway-sdk-kotlin-example/src/main/kotlin/org/onebusaway/example/TripDetails.kt @@ -0,0 +1,40 @@ +package org.onebusaway.example + +import org.onebusaway.client.OnebusawaySdkClient +import org.onebusaway.client.okhttp.OnebusawaySdkOkHttpClient +import org.onebusaway.errors.OnebusawaySdkException +import org.onebusaway.models.* + +object TripDetails { + + // 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) { + try { + // Define the trip ID + val tripId = "40_608344966" + + // Create the parameters for the trip details request + val params = TripDetailRetrieveParams.builder() + .tripId(tripId) + .build() + + // Retrieve the trip details + val tripDetails: TripDetailRetrieveResponse = client.tripDetails().retrieve(params) + + println(tripDetails) + } + catch (onebusawayException: OnebusawaySdkException) { + println(onebusawayException) + } + } +} diff --git a/onebusaway-sdk-kotlin-example/src/main/kotlin/org/onebusaway/example/TripForVehicle.kt b/onebusaway-sdk-kotlin-example/src/main/kotlin/org/onebusaway/example/TripForVehicle.kt new file mode 100644 index 0000000..f55da55 --- /dev/null +++ b/onebusaway-sdk-kotlin-example/src/main/kotlin/org/onebusaway/example/TripForVehicle.kt @@ -0,0 +1,34 @@ +package org.onebusaway.example + +import org.onebusaway.client.OnebusawaySdkClient +import org.onebusaway.client.okhttp.OnebusawaySdkOkHttpClient +import org.onebusaway.models.* + +object TripForVehicle { + + // 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) { + // Define the vehicle ID + val vehicleId = "40_9801" + + // Create the parameters for the trip retrieval request + val params = TripForVehicleRetrieveParams.builder() + .vehicleId(vehicleId) + .build() + + // Retrieve the trip for the vehicle + val tripForVehicle: TripForVehicleRetrieveResponse = client.tripForVehicle().retrieve(params) + + println(tripForVehicle) + } +} diff --git a/onebusaway-sdk-kotlin-example/src/main/kotlin/org/onebusaway/example/TripsForRoute.kt b/onebusaway-sdk-kotlin-example/src/main/kotlin/org/onebusaway/example/TripsForRoute.kt new file mode 100644 index 0000000..89840b8 --- /dev/null +++ b/onebusaway-sdk-kotlin-example/src/main/kotlin/org/onebusaway/example/TripsForRoute.kt @@ -0,0 +1,34 @@ +package org.onebusaway.example + +import org.onebusaway.client.OnebusawaySdkClient +import org.onebusaway.client.okhttp.OnebusawaySdkOkHttpClient +import org.onebusaway.models.* + +object TripsForRoute { + + // 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) { + // Define the route ID + val routeId = "1_100224" + + // Create the parameters for fetching trips for the route + val params = TripsForRouteListParams.builder() + .routeId(routeId) + .build() + + // Get the trips for the route + val trips: TripsForRouteListResponse = client.tripsForRoute().list(params) + + println(trips) + } +} diff --git a/onebusaway-sdk-kotlin-example/src/main/kotlin/org/onebusaway/example/VehiclesForAgency.kt b/onebusaway-sdk-kotlin-example/src/main/kotlin/org/onebusaway/example/VehiclesForAgency.kt new file mode 100644 index 0000000..2f1fee9 --- /dev/null +++ b/onebusaway-sdk-kotlin-example/src/main/kotlin/org/onebusaway/example/VehiclesForAgency.kt @@ -0,0 +1,34 @@ +package org.onebusaway.example + +import org.onebusaway.client.OnebusawaySdkClient +import org.onebusaway.client.okhttp.OnebusawaySdkOkHttpClient +import org.onebusaway.models.* + +object VehiclesForAgency { + + // 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) { + // Define the agency ID + val agencyId = "1" + + // Create the parameters for fetching vehicles for the agency + val params = VehiclesForAgencyListParams.builder() + .agencyId(agencyId) + .build() + + // Get the vehicles for the agency + val vehicles: VehiclesForAgencyListResponse = client.vehiclesForAgency().list(params) + + println(vehicles) + } +}