-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
260 additions
and
505 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
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
91 changes: 91 additions & 0 deletions
91
app/src/androidTest/java/nl/ovfietsbeschikbaarheid/StationsDownloader.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,91 @@ | ||
package nl.ovfietsbeschikbaarheid | ||
|
||
import io.ktor.client.HttpClient | ||
import io.ktor.client.call.body | ||
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation | ||
import io.ktor.client.request.get | ||
import io.ktor.client.request.header | ||
import io.ktor.serialization.kotlinx.json.json | ||
import kotlinx.coroutines.runBlocking | ||
import kotlinx.serialization.Serializable | ||
import kotlinx.serialization.encodeToString | ||
import kotlinx.serialization.json.Json | ||
import java.io.File | ||
|
||
/** | ||
* Not a test, rather a tool. Added in the test folder to prevent it being added in the app. | ||
*/ | ||
object LocationsCrawler { | ||
private val json = Json { | ||
ignoreUnknownKeys = true | ||
// Pretty print would help in git diff, but it rarely changes and is otherwise a waste of space and CPU cycles | ||
// prettyPrint = true | ||
} | ||
|
||
private val httpClient = HttpClient { | ||
install(ContentNegotiation) { | ||
json(json) | ||
} | ||
} | ||
|
||
@JvmStatic | ||
fun main(args: Array<String>): Unit = runBlocking { | ||
// NOTE: don't commit your real key | ||
val subscriptionKey = "" | ||
|
||
// Alternative: download from https://data.ndovloket.nl/haltes/ It's a big blob of XML and it also contains needless stuff like | ||
// bus stops, but it seems to have a little more info like the street name. | ||
val loaded = httpClient.get("https://gateway.apiportal.ns.nl/nsapp-stations/v3") { | ||
this.header( | ||
"Ocp-Apim-Subscription-Key", | ||
subscriptionKey | ||
) | ||
}.body<StationsDTO>() | ||
val inNlMapped = loaded.payload | ||
.filter { it.country == "NL" } | ||
.map { MyStationDTO(it.id.code, it.names.long, it.location.lat, it.location.lng) } | ||
|
||
val asJson = json.encodeToString(inNlMapped) | ||
val file = File("app/src/main/res/raw/stations.json") | ||
file.writeText(asJson) | ||
} | ||
} | ||
|
||
@Serializable | ||
data class MyStationDTO( | ||
val code: String, | ||
val name: String, | ||
val lat: Double, | ||
val lng: Double, | ||
) | ||
|
||
@Serializable | ||
data class StationsDTO( | ||
val payload: List<StationDTO> | ||
) | ||
|
||
@Serializable | ||
data class StationDTO( | ||
val country: String, | ||
val id: StationID, | ||
val names: StationNames, | ||
val location: LocationDTO | ||
) | ||
|
||
@Serializable | ||
data class StationID( | ||
val code: String | ||
) | ||
|
||
@Serializable | ||
data class StationNames( | ||
val long: String, | ||
val medium: String, | ||
val short: String | ||
) | ||
|
||
@Serializable | ||
data class LocationDTO( | ||
val lat: Double, | ||
val lng: Double, | ||
) |
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
11 changes: 11 additions & 0 deletions
11
app/src/main/java/nl/ovfietsbeschikbaarheid/dto/Station.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,11 @@ | ||
package nl.ovfietsbeschikbaarheid.dto | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class Station( | ||
val code: String, | ||
val name: String, | ||
val lat: Double, | ||
val lng: Double, | ||
) |
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
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
Oops, something went wrong.