Files
plexjava/src/main/java/com/plexsdk/services/BaseService.java
2023-10-26 21:45:53 -05:00

49 lines
1.2 KiB
Java

package com.plexsdk.services;
import com.plexsdk.Configuration;
import com.plexsdk.exceptions.ApiException;
import com.plexsdk.http.ModelConverter;
import com.plexsdk.models.*;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import okhttp3.Headers;
import okhttp3.HttpUrl;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
public class BaseService {
protected OkHttpClient httpClient;
protected String serverUrl;
public BaseService(OkHttpClient httpClient, String serverUrl) {
this.httpClient = httpClient;
this.serverUrl = serverUrl;
}
public void setBaseUrl(String serverUrl) {
this.serverUrl = serverUrl;
}
protected Response execute(Request request) throws ApiException {
Response response;
try {
response = this.httpClient.newCall(request).execute();
} catch (IOException e) {
ApiException apiException = new ApiException(e.getMessage());
throw apiException;
}
if (response.isSuccessful()) {
return response;
} else {
ApiException apiException = new ApiException(response.code());
throw apiException;
}
}
}