-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Trackernet on TfL Cloud decommissioned (#292)
- Loading branch information
1 parent
46ce4f9
commit efbd5a0
Showing
10 changed files
with
124 additions
and
92 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
60 changes: 0 additions & 60 deletions
60
common/feed/feeds/src/main/java/net/twisterrob/blt/io/feeds/TFLUrlBuilder.java
This file was deleted.
Oops, something went wrong.
68 changes: 68 additions & 0 deletions
68
common/feed/feeds/src/main/java/net/twisterrob/blt/io/feeds/TFLUrlBuilder.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,68 @@ | ||
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 | ||
import java.net.URL | ||
import java.util.Locale | ||
|
||
/** | ||
* From email: Thank you for registering for Transport for London (TfL) syndicated feeds. | ||
*/ | ||
class TFLUrlBuilder( | ||
private val email: String, | ||
private val trackerNetData: TrackerNetData, | ||
) : net.twisterrob.blt.io.feeds.URLBuilder { | ||
|
||
@Throws(MalformedURLException::class) | ||
fun getSyncdicationFeed(feedId: Int): URL { | ||
val query = "?email=%s&feedId=%d".format(Locale.ROOT, email, feedId) | ||
return URL(Feed.Type.Syndication.baseUrl, query) | ||
} | ||
|
||
@Throws(MalformedURLException::class) | ||
fun getSyncdicationFeed(feed: Feed): URL { | ||
require(feed.type == Feed.Type.Syndication) { | ||
"Only syndication feeds are allowed here, got ${feed}." | ||
} | ||
return getSyncdicationFeed(feed.feedId) | ||
} | ||
|
||
@Throws(MalformedURLException::class) | ||
override fun getFeedUrl(feed: Feed, args: Map<String, *>): URL { | ||
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 | ||
appendPathSegments(trackerNetData.getTrackerNetCodeOf(line)) | ||
} | ||
|
||
Feed.TubeDepartureBoardsPredictionDetailed -> { | ||
val line = args["line"] as Line | ||
require(line in Line.UNDERGROUND) { | ||
"${line} line is not Underground, cannot request prediction for it." | ||
} | ||
val code = trackerNetData.getTrackerNetCodeOf(line) | ||
appendPathSegments(code, args["station"] as String) | ||
} | ||
|
||
else -> { | ||
this // No special handling. | ||
} | ||
} | ||
} |
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
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
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
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