Slowly phasing out use of Unirest in favor of OkHTTP

This commit is contained in:
NovaFox161
2018-07-07 23:12:58 -05:00
parent e7cb694ab9
commit fc639c6bab
2 changed files with 27 additions and 4 deletions

View File

@@ -134,7 +134,6 @@
<version>1.7.21</version>
<scope>compile</scope>
</dependency>
<!--Thymeleaf-->
<dependency>
<groupId>org.thymeleaf</groupId>
@@ -155,6 +154,13 @@
<version>1.1.1</version>
<scope>compile</scope>
</dependency>
<!--OkHTTP API-->
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.10.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>

View File

@@ -3,9 +3,7 @@ package com.cloudcraftgaming.discal.bot.internal.network.discordpw;
import com.cloudcraftgaming.discal.api.DisCalAPI;
import com.cloudcraftgaming.discal.api.object.BotSettings;
import com.cloudcraftgaming.discal.logger.Logger;
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.JsonNode;
import com.mashape.unirest.http.Unirest;
import okhttp3.*;
import org.json.JSONObject;
import java.util.Timer;
@@ -19,6 +17,8 @@ import java.util.TimerTask;
public class UpdateDisPwData {
private static Timer timer;
private static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
public static void init() {
if (BotSettings.UPDATE_SITES.get().equalsIgnoreCase("true")) {
timer = new Timer(true);
@@ -42,8 +42,25 @@ public class UpdateDisPwData {
JSONObject json = new JSONObject().put("server_count", serverCount);
/*
//noinspection unused
HttpResponse<JsonNode> response = Unirest.post("https://bots.discord.pw/api/bots/265523588918935552/stats").header("Authorization", BotSettings.PW_TOKEN.get()).header("Content-Type", "application/json").body(json).asJson();
*/
OkHttpClient client = new OkHttpClient();
RequestBody body = RequestBody.create(JSON, json.toString());
Request request = new Request.Builder()
.url("https://bots.discord.pw/api/bots/265523588918935552/stats")
.post(body)
.header("Authorization", BotSettings.PW_TOKEN.get())
.header("Content-Type", "application/json")
.build();
Response response = client.newCall(request).execute();
if (response.code() == 200)
Logger.getLogger().debug("Successfully updated Discord PW List!");
} catch (Exception e) {
//Handle issue.
System.out.println("Failed to update Discord PW list metadata!");