Skip to content

Instantly share code, notes, and snippets.

@hafs-r
Created October 7, 2019 13:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hafs-r/53037e40d86fafd5ea560994033bb388 to your computer and use it in GitHub Desktop.
Save hafs-r/53037e40d86fafd5ea560994033bb388 to your computer and use it in GitHub Desktop.
import android.content.Context
import com.apptualizer.fakeapi.helper.ResourcesHelper
import com.apptualizer.fakeapi.helper.ResponseHelper
import okhttp3.*
import java.io.IOException
class FakeInterceptor @JvmOverloads constructor(val context: Context) : Interceptor {
@Throws(IOException::class)
override fun intercept(chain: Interceptor.Chain): Response {
val url = chain.request().url()
val path = ResponseHelper.mapProperResponse(url.encodedPath(), chain.request())
val outPutString = ResourcesHelper.loadFileAsString(path)
return Response.Builder()
.code(ResponseHelper.errorCode)
.message(outPutString)
.request(chain.request())
.protocol(Protocol.HTTP_2)
.body(ResponseBody.create(
MediaType.parse("application/json"),outPutString))
.addHeader("content-type", "application/json").build()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment