Skip to content
This repository was archived by the owner on Feb 28, 2024. It is now read-only.

Commit c4dc384

Browse files
committed
places: internal parse* methods takes InputStream instead of String
1 parent 6cc3ec1 commit c4dc384

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/main/java/com/sygic/travel/sdk/places/facade/PlacesFacade.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import com.sygic.travel.sdk.places.model.geo.LatLngBounds
77
import com.sygic.travel.sdk.places.model.media.Medium
88
import com.sygic.travel.sdk.places.service.PlacesService
99
import com.sygic.travel.sdk.utils.checkNotRunningOnMainThread
10+
import java.io.InputStream
1011

1112
/**
1213
* Places facade provides interface for fetching places data from the API.
@@ -71,7 +72,7 @@ class PlacesFacade internal constructor(
7172
* Parses list of places as Place instances.
7273
* @internal
7374
*/
74-
fun parsePlacesList(json: String): List<Place> {
75+
fun parsePlacesList(json: InputStream): List<Place> {
7576
checkNotRunningOnMainThread()
7677
return placesService.parsePlacesList(json)
7778
}
@@ -80,7 +81,7 @@ class PlacesFacade internal constructor(
8081
* Parses list of places as DetailedPlace instances.
8182
* @internal
8283
*/
83-
fun parseDetailedPlacesList(json: String): List<DetailedPlace> {
84+
fun parseDetailedPlacesList(json: InputStream): List<DetailedPlace> {
8485
checkNotRunningOnMainThread()
8586
return placesService.parseDetailedPlacesList(json)
8687
}

src/main/java/com/sygic/travel/sdk/places/service/PlacesService.kt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import com.sygic.travel.sdk.places.model.Place
1313
import com.sygic.travel.sdk.places.model.geo.LatLng
1414
import com.sygic.travel.sdk.places.model.geo.LatLngBounds
1515
import com.sygic.travel.sdk.places.model.media.Medium
16+
import okio.Okio
17+
import java.io.InputStream
1618

1719
internal class PlacesService constructor(
1820
private val sygicTravelApiClient: SygicTravelApiClient,
@@ -70,13 +72,15 @@ internal class PlacesService constructor(
7072
return request.checkedExecute().body()!!.data!!.fromApi()
7173
}
7274

73-
fun parsePlacesList(json: String): List<Place> {
75+
fun parsePlacesList(json: InputStream): List<Place> {
76+
val input = Okio.buffer(Okio.source(json))
7477
val apiPlaceType = Types.newParameterizedType(List::class.java, ApiPlaceListItemResponse::class.java)
75-
return moshi.adapter<List<ApiPlaceListItemResponse>>(apiPlaceType).fromJson(json)!!.map { it.fromApi() }
78+
return moshi.adapter<List<ApiPlaceListItemResponse>>(apiPlaceType).fromJson(input)!!.map { it.fromApi() }
7679
}
7780

78-
fun parseDetailedPlacesList(json: String): List<DetailedPlace> {
81+
fun parseDetailedPlacesList(json: InputStream): List<DetailedPlace> {
82+
val input = Okio.buffer(Okio.source(json))
7983
val apiDetailedPlaceType = Types.newParameterizedType(List::class.java, ApiPlaceItemResponse::class.java)
80-
return moshi.adapter<List<ApiPlaceItemResponse>>(apiDetailedPlaceType).fromJson(json)!!.map { it.fromApi() }
84+
return moshi.adapter<List<ApiPlaceItemResponse>>(apiDetailedPlaceType).fromJson(input)!!.map { it.fromApi() }
8185
}
8286
}

0 commit comments

Comments
 (0)