discord-jadx/app/src/main/java/com/discord/restapi/RestAPIBuilder.java

229 lines
9.2 KiB
Java

package com.discord.restapi;
import androidx.annotation.VisibleForTesting;
import c.a.b.a;
import c.i.d.c;
import c.i.d.e;
import com.discord.models.domain.Model;
import com.discord.models.experiments.dto.UserExperimentDto;
import com.discord.restapi.PayloadJSON;
import com.discord.restapi.RestAPIParams;
import com.google.gson.Gson;
import d0.z.d.m;
import f0.p;
import f0.w;
import f0.x;
import i0.d0.a.g;
import i0.e0.b.k;
import i0.i;
import i0.q;
import i0.u;
import i0.y;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.Proxy;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.Executor;
import java.util.concurrent.TimeUnit;
import kotlin.Unit;
import kotlin.jvm.functions.Function2;
import kotlin.jvm.internal.DefaultConstructorMarker;
import okhttp3.Interceptor;
/* compiled from: RestAPIBuilder.kt */
public final class RestAPIBuilder {
private static final int API_VERSION = 9;
public static final String CONTENT_TYPE_JSON = "application/json";
public static final String CONTENT_TYPE_TEXT = "text/plain";
public static final Companion Companion = new Companion(null);
private static final long DEFAULT_TIMEOUT_MILLIS = 10000;
private static Function2<? super String, ? super x, Unit> clientCallback = RestAPIBuilder$Companion$clientCallback$1.INSTANCE;
private final String baseApiUrl;
private final p cookieJar;
/* compiled from: RestAPIBuilder.kt */
public static final class Companion {
private Companion() {
}
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
this();
}
@VisibleForTesting
public static /* synthetic */ void getClientCallback$annotations() {
}
public final Function2<String, x, Unit> getClientCallback() {
return RestAPIBuilder.access$getClientCallback$cp();
}
public final void setClientCallback(Function2<? super String, ? super x, Unit> function2) {
m.checkNotNullParameter(function2, "<set-?>");
RestAPIBuilder.access$setClientCallback$cp(function2);
}
}
public RestAPIBuilder(String str, p pVar) {
m.checkNotNullParameter(str, "baseApiUrl");
m.checkNotNullParameter(pVar, "cookieJar");
this.baseApiUrl = str;
this.cookieJar = pVar;
}
public static final /* synthetic */ Function2 access$getClientCallback$cp() {
return clientCallback;
}
public static final /* synthetic */ void access$setClientCallback$cp(Function2 function2) {
clientCallback = function2;
}
public static /* synthetic */ Object build$default(RestAPIBuilder restAPIBuilder, Class cls, boolean z2, long j, List list, String str, boolean z3, String str2, int i, Object obj) {
boolean z4 = (i & 2) != 0 ? false : z2;
long j2 = (i & 4) != 0 ? 10000 : j;
String str3 = null;
List list2 = (i & 8) != 0 ? null : list;
if ((i & 16) == 0) {
str3 = str;
}
return restAPIBuilder.build(cls, z4, j2, list2, str3, (i & 32) != 0 ? true : z3, (i & 64) != 0 ? CONTENT_TYPE_JSON : str2);
}
private final <T> T buildApi(x xVar, Class<T> cls, String str, boolean z2, boolean z3, String str2) {
String str3;
String str4;
e eVar = new e();
eVar.f1429c = c.LOWER_CASE_WITH_UNDERSCORES;
m.checkNotNullExpressionValue(eVar, "GsonBuilder()\n .s…ER_CASE_WITH_UNDERSCORES)");
a.a(eVar);
eVar.e.add(new Model.TypeAdapterFactory());
eVar.e.add(UserExperimentDto.TypeAdapterFactory.INSTANCE);
eVar.b(RestAPIParams.ChannelPosition.class, new RestAPIParams.ChannelPosition.Serializer());
if (z2) {
eVar.g = true;
}
Gson a = eVar.a();
if (z3) {
str4 = "v9/";
str3 = str;
} else {
str3 = str;
str4 = "";
}
String v = c.d.b.a.a.v(str3, str4);
u uVar = u.a;
ArrayList arrayList = new ArrayList();
ArrayList arrayList2 = new ArrayList();
Objects.requireNonNull(xVar, "client == null");
arrayList2.add(new g(null, false));
arrayList.add(new k());
m.checkNotNullExpressionValue(a, "gson");
arrayList.add(new PayloadJSON.ConverterFactory(a));
if (m.areEqual(str2, CONTENT_TYPE_JSON)) {
arrayList.add(new i0.e0.a.a(a));
}
Objects.requireNonNull(v, "baseUrl == null");
m.checkParameterIsNotNull(v, "$this$toHttpUrl");
w.a aVar = new w.a();
aVar.e(null, v);
w b = aVar.b();
List<String> list = b.i;
if ("".equals(list.get(list.size() - 1))) {
Executor a2 = uVar.a();
ArrayList arrayList3 = new ArrayList(arrayList2);
i iVar = new i(a2);
arrayList3.addAll(uVar.b ? Arrays.asList(i0.g.a, iVar) : Collections.singletonList(iVar));
ArrayList arrayList4 = new ArrayList(arrayList.size() + 1 + (uVar.b ? 1 : 0));
arrayList4.add(new i0.c());
arrayList4.addAll(arrayList);
arrayList4.addAll(uVar.b ? Collections.singletonList(q.a) : Collections.emptyList());
y yVar = new y(xVar, b, Collections.unmodifiableList(arrayList4), Collections.unmodifiableList(arrayList3), a2, false);
if (cls.isInterface()) {
ArrayDeque arrayDeque = new ArrayDeque(1);
arrayDeque.add(cls);
while (!arrayDeque.isEmpty()) {
Class<T> cls2 = (Class) arrayDeque.removeFirst();
if (cls2.getTypeParameters().length != 0) {
StringBuilder sb = new StringBuilder("Type parameters are unsupported on ");
sb.append(cls2.getName());
if (cls2 != cls) {
sb.append(" which is an interface of ");
sb.append(cls.getName());
}
throw new IllegalArgumentException(sb.toString());
}
Collections.addAll(arrayDeque, cls2.getInterfaces());
}
if (yVar.f) {
u uVar2 = u.a;
Method[] declaredMethods = cls.getDeclaredMethods();
for (Method method : declaredMethods) {
if (!(uVar2.b && method.isDefault()) && !Modifier.isStatic(method.getModifiers())) {
yVar.b(method);
}
}
}
return (T) Proxy.newProxyInstance(cls.getClassLoader(), new Class[]{cls}, new i0.x(yVar, cls));
}
throw new IllegalArgumentException("API declarations must be interfaces.");
}
throw new IllegalArgumentException("baseUrl must end in /: " + b);
}
public static /* synthetic */ Object buildApi$default(RestAPIBuilder restAPIBuilder, x xVar, Class cls, String str, boolean z2, boolean z3, String str2, int i, Object obj) {
return restAPIBuilder.buildApi(xVar, cls, str, (i & 8) != 0 ? false : z2, z3, str2);
}
private final x buildOkHttpClient(Long l, List<? extends Interceptor> list) {
x.a aVar = new x.a();
if (list != null) {
for (Interceptor interceptor : list) {
m.checkParameterIsNotNull(interceptor, "interceptor");
aVar.f2880c.add(interceptor);
}
}
if (l != null) {
long longValue = l.longValue();
TimeUnit timeUnit = TimeUnit.MILLISECONDS;
aVar.a(longValue, timeUnit);
long longValue2 = l.longValue();
m.checkParameterIsNotNull(timeUnit, "unit");
aVar.f2884z = f0.e0.c.b("timeout", longValue2, timeUnit);
long longValue3 = l.longValue();
m.checkParameterIsNotNull(timeUnit, "unit");
aVar.f2882x = f0.e0.c.b("timeout", longValue3, timeUnit);
}
p pVar = this.cookieJar;
m.checkParameterIsNotNull(pVar, "cookieJar");
aVar.j = pVar;
return new x(aVar);
}
/* JADX DEBUG: Multi-variable search result rejected for r1v0, resolved type: com.discord.restapi.RestAPIBuilder */
/* JADX WARN: Multi-variable type inference failed */
public static /* synthetic */ x buildOkHttpClient$default(RestAPIBuilder restAPIBuilder, Long l, List list, int i, Object obj) {
if ((i & 1) != 0) {
l = null;
}
if ((i & 2) != 0) {
list = null;
}
return restAPIBuilder.buildOkHttpClient(l, list);
}
public final <T> T build(Class<T> cls, boolean z2, long j, List<? extends Interceptor> list, String str, boolean z3, String str2) {
m.checkNotNullParameter(cls, "apiDefinition");
m.checkNotNullParameter(str2, "contentType");
x buildOkHttpClient = buildOkHttpClient(Long.valueOf(j), list);
if (str != null) {
clientCallback.invoke(str, buildOkHttpClient);
}
return (T) buildApi(buildOkHttpClient, cls, this.baseApiUrl, z2, z3, str2);
}
}