Skip to content

Commit e81cfa5

Browse files
committed
Move OkHttp to HttpUtil (part 2)
1 parent 2140c2a commit e81cfa5

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/main/java/org/maxgamer/quickshop/util/HttpUtil.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package org.maxgamer.quickshop.util;
22

3-
import okhttp3.Cache;
4-
import okhttp3.OkHttpClient;
3+
import okhttp3.*;
4+
import org.jetbrains.annotations.NotNull;
55

66
import java.io.File;
77
import java.io.IOException;
@@ -11,7 +11,7 @@ public class HttpUtil {
1111
private final OkHttpClient client = new OkHttpClient.Builder()
1212
.cache(new Cache(getCacheFolder(),50L * 1024L * 1024L)).build();
1313

14-
public static HttpUtil instance(){
14+
public static HttpUtil create(){
1515
return new HttpUtil();
1616
}
1717

@@ -30,4 +30,12 @@ private File getCacheFolder(){
3030
public OkHttpClient getClient() {
3131
return client;
3232
}
33+
34+
public static Response makeGet(@NotNull String url) throws IOException {
35+
return HttpUtil.create().getClient().newCall(new Request.Builder().get().url(url).build()).execute();
36+
}
37+
38+
public static Response makePost(@NotNull String url, @NotNull RequestBody body) throws IOException {
39+
return HttpUtil.create().getClient().newCall(new Request.Builder().post(body).url(url).build()).execute();
40+
}
3341
}

src/main/java/org/maxgamer/quickshop/util/language/text/distributions/crowdin/CrowdinOTA.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public String getManifestJson() {
6363
if (requestCachePool.getIfPresent(url) != null) {
6464
return requestCachePool.getIfPresent(url);
6565
}
66-
try (Response response = HttpUtil.instance().getClient().newCall(new Request.Builder().get().url(url).build()).execute()) {
66+
try (Response response = HttpUtil.create().getClient().newCall(new Request.Builder().get().url(url).build()).execute()) {
6767
val body = response.body();
6868
if (body == null) {
6969
return null;
@@ -172,7 +172,7 @@ public String getFile(String fileCrowdinPath, String crowdinLocale, boolean forc
172172
if (forceFlush || data == null || localeTimestamp != manifest.getTimestamp()) {
173173
String url = CROWDIN_OTA_HOST + "content" + fileCrowdinPath.replace("%locale%", crowdinLocale);
174174
Util.debugLog("Reading data from remote server: " + url);
175-
try (Response response = HttpUtil.instance().getClient().newCall(new Request.Builder().get().url(url).build()).execute()) {
175+
try (Response response = HttpUtil.create().getClient().newCall(new Request.Builder().get().url(url).build()).execute()) {
176176
val body = response.body();
177177
if (body == null) {
178178
throw new OTAException(response.code(), ""); // Returns empty string (failed to getting content)

0 commit comments

Comments
 (0)