Kotlin/Fuel - Unresolved reference: responseString when using apply

253 Views Asked by At

I would like to make creation of FuelManager instance flexible by using apply with it. So, for example, the properties that are common for all instances would be created with this function:

fun createFuelManagerInstance(ctx: Ctx, url: String) = FuelManager().apply {
  this.request(Method.POST, url)
  this.timeoutReadInMillisecond = 8_000
  this.timeoutInMillisecond = 4_000
  this.baseHeaders = mapOf(
      "Content-Type" to "application/json",
      "X-API-Key" to ctx.conf.get(ConfValues.ApiSecret)
  )
}

And then I would create an instance and add properties like this for example:

val manager = createFuelManagerInstance(ctx, url)
if (payload != null) {
  manager.apply { this.request(Method.POST, url).body(payload.toString()) }
}

If I do that, I don't know how to actually call responseString to get a response from the request, because I get Unresolved reference: responseString if I do this:

val (_, response, data) = manager.responseString()

What am I doing wrong here, how can I fix this?

0

There are 0 best solutions below