Skip to content

Commit

Permalink
Format
Browse files Browse the repository at this point in the history
  • Loading branch information
jdamcd committed Nov 20, 2024
1 parent c632590 commit fd327a8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 26 deletions.
36 changes: 18 additions & 18 deletions shared/src/commonMain/kotlin/com/jdamcd/tflarrivals/TflApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,26 @@ internal class TflApi {
}
}

suspend fun fetchArrivals(station: String): List<ApiArrival> {
return client.get("$BASE_URL/StopPoint/$station/Arrivals") {
parameter("app_key", BuildKonfig.TFL_APP_KEY)
}.body()
}
suspend fun fetchArrivals(station: String): List<ApiArrival> =
client
.get("$BASE_URL/StopPoint/$station/Arrivals") {
parameter("app_key", BuildKonfig.TFL_APP_KEY)
}.body()

suspend fun searchStations(query: String): ApiSearchResult {
return client.get("$BASE_URL/StopPoint/Search") {
parameter("app_key", BuildKonfig.TFL_APP_KEY)
parameter("query", query)
parameter("modes", "dlr,elizabeth-line,overground,tube,tram")
parameter("tflOperatedNationalRailStationsOnly", true)
}.body()
}
suspend fun searchStations(query: String): ApiSearchResult =
client
.get("$BASE_URL/StopPoint/Search") {
parameter("app_key", BuildKonfig.TFL_APP_KEY)
parameter("query", query)
parameter("modes", "dlr,elizabeth-line,overground,tube,tram")
parameter("tflOperatedNationalRailStationsOnly", true)
}.body()

suspend fun stopDetails(id: String): ApiStopPoint {
return client.get("$BASE_URL/StopPoint/$id") {
parameter("app_key", BuildKonfig.TFL_APP_KEY)
}.body()
}
suspend fun stopDetails(id: String): ApiStopPoint =
client
.get("$BASE_URL/StopPoint/$id") {
parameter("app_key", BuildKonfig.TFL_APP_KEY)
}.body()
}

@Serializable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ internal class TflArrivals(
}

@Throws(CancellationException::class)
override suspend fun searchStops(query: String): List<StopResult> {
return api.searchStations(query).matches
override suspend fun searchStops(query: String): List<StopResult> =
api
.searchStations(query)
.matches
.map { StopResult(it.id, it.name, it.id.startsWith("HUB")) }
}

@Throws(CancellationException::class)
override suspend fun stopDetails(id: String): StopDetails {
Expand All @@ -61,12 +62,10 @@ internal class TflArrivals(
.filter {
settings.platformFilter.isEmpty() ||
it.platformName.contains(settings.platformFilter, ignoreCase = true)
}
.filter { arrival ->
}.filter { arrival ->
settings.directionFilter == SettingsConfig.DIRECTION_FILTER_DEFAULT ||
arrival.direction.contains(settings.directionFilter)
}
.take(3)
}.take(3)
.map {
Arrival(
// DLR arrivals all have the same ID, so use hash
Expand Down Expand Up @@ -116,7 +115,9 @@ data class StopDetails(
val children: List<StopResult>
)

class NoDataException(message: String) : Throwable(message = message)
class NoDataException(
message: String
) : Throwable(message = message)

private fun formatTime(seconds: Int) =
if (seconds < 60) {
Expand Down

0 comments on commit fd327a8

Please sign in to comment.