Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trackernet on TfL Cloud decommissioned #292

Merged
merged 13 commits into from
Nov 1, 2024
Prev Previous commit
Next Next commit
Use ktor URLBuilder
  • Loading branch information
TWiStErRob committed Oct 14, 2024
commit 478bd3767cad25fb101d0633f6a097446259e28e
1 change: 1 addition & 0 deletions common/feed/feeds/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ dependencies {
implementation(projects.common.feed.trackernet)
implementation(projects.common.feed.timetable)
implementation(libs.jsr305)
implementation(libs.ktor.http)
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package net.twisterrob.blt.io.feeds

import io.ktor.http.URLBuilder
import io.ktor.http.appendPathSegments
import io.ktor.http.takeFrom
import io.ktor.http.toURI
import net.twisterrob.blt.io.feeds.trackernet.TrackerNetData
import net.twisterrob.blt.model.Line
import java.net.MalformedURLException
Expand All @@ -12,7 +16,7 @@ import java.util.Locale
class TFLUrlBuilder(
private val email: String,
private val trackerNetData: TrackerNetData,
) : URLBuilder {
) : net.twisterrob.blt.io.feeds.URLBuilder {

@Throws(MalformedURLException::class)
fun getSyncdicationFeed(feedId: Int): URL {
Expand All @@ -33,10 +37,19 @@ class TFLUrlBuilder(
if (feed.type == Feed.Type.Syndication) {
return getSyncdicationFeed(feed)
}
return URLBuilder()
.takeFrom(feed.url)
.run { handleArgs(feed, args) }
.build()
.toURI()
.toURL()
}

private fun URLBuilder.handleArgs(feed: Feed, args: Map<String, *>): URLBuilder =
when (feed) {
Feed.TubeDepartureBoardsPredictionSummary -> {
val line = args["line"] as Line
return URL(feed.url, trackerNetData.getTrackerNetCodeOf(line))
appendPathSegments(trackerNetData.getTrackerNetCodeOf(line))
}

Feed.TubeDepartureBoardsPredictionDetailed -> {
Expand All @@ -45,12 +58,11 @@ class TFLUrlBuilder(
"${line} line is not Underground, cannot request prediction for it."
}
val code = trackerNetData.getTrackerNetCodeOf(line)
return URL(URL(feed.url, "$code/"), args["station"] as String)
appendPathSegments(code, args["station"] as String)
}

else -> {
return feed.url
this // No special handling.
}
}
}
}
4 changes: 4 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ kotlin-ksp = "2.0.21-1.0.25"
kotlin-datetime = "0.6.1"
kotlin-serialization = "1.7.3"

ktor = "3.0.0"

jsr305 = "3.0.2"
kxml2 = "2.3.0"

Expand Down Expand Up @@ -56,6 +58,8 @@ plugin-gretty = { module = "org.gretty:gretty", version.ref = "gretty" }
plugin-kotlin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
plugin-ksp = { module = "com.google.devtools.ksp:com.google.devtools.ksp.gradle.plugin", version.ref = "kotlin-ksp" }

ktor-http = { module = "io.ktor:ktor-http", version.ref = "ktor" }

plugin-micronaut = { module = "io.micronaut.application:io.micronaut.application.gradle.plugin", version.ref = "micronaut-gradle" }
#noinspection unused versions.micronaut is used for micronaut { version = ... }, micronaut-platform is added here to help Renovate.
micronaut-platform = { module = "io.micronaut.platform:micronaut-platform", version.ref = "micronaut" }
Expand Down