class WeatherClient {
String findCity(long latitude, long longitude) {
return serviceRestClient.forExternalService()
.get()
.onUrl("$cityFindingServiceUrl?lat=${latitude.toInteger()}&lon=${longitude.toInteger()}")
.anObject()
.ofType(String)
}
}
interface WeatherClient {
@GET("cityFindingService/?lat={latitude}&lon={latitude}")
String findCity(long latitude, long longitude);
}
The mess with Fluent Rest client direct usage - without WeatherClient
// with fluent rest client we are allowed to use direct code instead of WeatherClient
for(location : locations)
City city = serviceRestClient.forExternalService()
.get()
.onUrl("$cityFindingServiceUrl?lat=${location.latitude}&lon=${location.longitude}")
.anObject()
.ofType(String)
City capital = serviceRestClient.forExternalService()
.get()
.onUrl("$cityFindingServiceUrl?lat=${latitude}&lon=${longitude}")
.anObject()
.ofType(String)
instead of
for(location : locations)
City city = weatherClient.findCity(location.latitude, location.longitude)
City capital = weatherClient.findCity(latitude, longitude)
You cant make a mess with retrofit