Skip to content

Latest commit

History

History
126 lines (88 loc) 路 3.29 KB

migrating-from-chuck.md

File metadata and controls

126 lines (88 loc) 路 3.29 KB

Migrating from Chuck

Please refer to this page if you're migrating from chuck to chucker

The following guide is written assuming you're planning to use Chucker version 3.0.0.

1. Update the Gradle dependency

If you're using Chuck you need to update your gradle dependencies block from this:

dependencies {
    debugCompile "com.readystatesoftware.chuck:library:1.1.0"
    releaseCompile "com.readystatesoftware.chuck:library-no-op:1.1.0"
}

to this:

repositories {
    // Other repositories here.
    maven { url "https://jitpack.io" }
}

dependencies {
    debugImplementation "com.github.ChuckerTeam.Chucker:library:3.0.1"
    releaseImplementation "com.github.ChuckerTeam.Chucker:library-no-op:3.0.1"
}

Please note that Chucker is distributed on JitPack at the moment so you need to specify it in the repositories block.

2. Update the Interceptor initialization code

You need to update the initialization code of Chuck from this:

import com.readystatesoftware.chuck.ChuckInterceptor;

val client = OkHttpClient.Builder()
  .addInterceptor(new ChuckInterceptor(context))
  .build()

to this:

import com.chuckerteam.chucker.api.ChuckerInterceptor;

val client = OkHttpClient.Builder()
  .addInterceptor(new ChuckerInterceptor(context))
  .build()

3. Update the code to configure the interceptor

Chuck used to use a Builder pattern to configure your interceptor. Chucker instead is using Kotlin named parameters with default values to configure the interceptor. Multiple builder methods have been removed and you need to replace them with parameters from the constructors.

Moreover the functions retainDataFor and showNotification on the interceptor have been moved to the ChuckerCollector class. Please note that those methods are not available on the Interceptor anymore and you need to update your code accordingly.

Java

The following code:

ChuckInterceptor interceptor = new ChuckInterceptor(context)
    .showNotification(true)
    .retainDataFor(Period.ONE_HOUR)
    .maxContentLength(120000L);

should be updated to:

ChuckerCollector collector = new ChuckerCollector(
    context, true, RetentionManager.Period.ONE_HOUR)

ChuckerInterceptor interceptor = new ChuckerInterceptor(
    context, collector, 120000L);

Kotlin

We suggest to use Kotlin to configure your interceptor as it makes the code more clean/elegant.

The following code:

val interceptor = ChuckInterceptor(context)
    .showNotification(true)
    .retainDataFor(Period.ONE_HOUR)
    .maxContentLength(120000L)

should be updated to:

val collector = ChuckerCollector(
    context = this,
    showNotification = true,
    retentionPeriod = RetentionManager.Period.ONE_HOUR
)

val interceptor = ChuckerInterceptor(
    context = context,
    collector = collector,
    maxContentLength = 120000L
)

Naming

Generally name of classes from Chuck (e.g. ChuckInterceptor) got udpated to Chucker (e.g. ChuckerInterceptor). This is valid for all the classes in the library.

So if to launch the UI of Chuck, you would normally call:

Chuck.getLaunchIntent(...)

now you will call

Chucker.getLaunchIntent(...)