val artApi: ArtApi by lazy {
Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build()
.create(ArtApi::class.java)
}
interface ArtApi {
@POST("/api/v4/dreambooth")
fun makeApiRequest(@Body requestBody: DreamBoothRequest): Call<ApiResponse>
}
fun makeApiRequest(requestBody: DreamBoothRequest, onResponse: (ApiResponse?) -> Unit) {
val call = artApi.makeApiRequest(requestBody)
call.enqueue(object : Callback<ApiResponse> {
override fun onResponse(call: Call<ApiResponse>, response: Response<ApiResponse>) {
if(response.isSuccessful)
{
Log.d(TAG, "onResponse: ${response.body()!!.status}")
onResponse(response.body())
}else{
Log.d(TAG, "onResponse: not successful")
}
}
override fun onFailure(call: Call<ApiResponse>, t: Throwable) {
onResponse(ApiResponse(t.message.toString(), 0.0, 0, emptyList()))
}
})
}