Skip to content

Commit ebea727

Browse files
committed
Merge branch “feature-ors”
2 parents 522cc71 + c7c5a24 commit ebea727

File tree

3 files changed

+7
-14
lines changed

3 files changed

+7
-14
lines changed

app/src/main/java/org/nitri/opentopo/ors/Directions.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@ import kotlinx.coroutines.CoroutineScope
44
import kotlinx.coroutines.Dispatchers
55
import kotlinx.coroutines.launch
66
import kotlinx.coroutines.withContext
7-
import okhttp3.ResponseBody
87
import org.nitri.ors.api.OpenRouteServiceApi
98
import org.nitri.ors.repository.RouteRepository
10-
import retrofit2.Response
119

1210
class Directions(val api: OpenRouteServiceApi, private val profile: String) {
1311

@@ -16,9 +14,8 @@ class Directions(val api: OpenRouteServiceApi, private val profile: String) {
1614
fun getRouteGpx(coordinates: List<List<Double>>, language: String, result: RouteGpResult) {
1715
CoroutineScope(Dispatchers.IO).launch {
1816
try {
19-
val response : Response<ResponseBody> = repository.getRouteGpx(coordinates, language, profile)
17+
val gpxXml = repository.getRouteGpx(coordinates, language, profile)
2018
withContext(Dispatchers.Main) {
21-
val gpxXml = response.body()?.string() ?: ""
2219
if (gpxXml.isNotBlank()) {
2320
result.onSuccess(gpxXml)
2421
} else {

ors-client/src/androidTest/java/org/nitri/ors/RouteRepositoryInstrumentedTest.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,10 @@ class RouteRepositoryInstrumentedTest {
4444
val start = Pair(8.681495, 49.41461)
4545
val end = Pair(8.687872, 49.420318)
4646

47-
val response: Response<ResponseBody> = repository.getRouteGpx(start, end,"driving-car")
48-
49-
val gpxXml = response.body()?.string()
47+
val gpxXml = repository.getRouteGpx(start, end,"driving-car")
5048

5149
assertNotNull("GPX response body should not be null", gpxXml)
52-
assert(gpxXml!!.contains("<gpx")) { "Response does not appear to be valid GPX" }
50+
assert(gpxXml.contains("<gpx")) { "Response does not appear to be valid GPX" }
5351
}
5452

5553
@Test

ors-client/src/main/java/org/nitri/ors/repository/RouteRepository.kt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
package org.nitri.ors.repository
22

3-
import okhttp3.ResponseBody
43
import org.nitri.ors.api.OpenRouteServiceApi
54
import org.nitri.ors.model.route.GeoJsonRouteResponse
65
import org.nitri.ors.model.route.RouteRequest
76
import org.nitri.ors.model.route.RouteResponse
8-
import retrofit2.Response
97

108
class RouteRepository(private val api: OpenRouteServiceApi) {
119
suspend fun getRoute(start: Pair<Double, Double>, end: Pair<Double, Double>, profile: String): RouteResponse {
@@ -16,17 +14,17 @@ class RouteRepository(private val api: OpenRouteServiceApi) {
1614
return api.getRoute(profile, request)
1715
}
1816

19-
suspend fun getRouteGpx(start: Pair<Double, Double>, end: Pair<Double, Double>, profile: String): Response<ResponseBody> {
17+
suspend fun getRouteGpx(start: Pair<Double, Double>, end: Pair<Double, Double>, profile: String): String {
2018
val request = RouteRequest(coordinates = listOf(
2119
listOf(start.first, start.second),
2220
listOf(end.first, end.second)
2321
))
24-
return api.getRouteGpx(profile, request)
22+
return api.getRouteGpx(profile, request).body()?.string() ?: ""
2523
}
2624

27-
suspend fun getRouteGpx(coordinates: List<List<Double>>, language: String, profile: String): Response<ResponseBody> {
25+
suspend fun getRouteGpx(coordinates: List<List<Double>>, language: String, profile: String): String {
2826
val request = RouteRequest(coordinates = coordinates, language = language)
29-
return api.getRouteGpx(profile, request)
27+
return api.getRouteGpx(profile, request).body()?.string() ?: ""
3028
}
3129

3230
suspend fun getRouteGeoJson(start: Pair<Double, Double>, end: Pair<Double, Double>, profile: String): GeoJsonRouteResponse {

0 commit comments

Comments
 (0)