scape.fashion WIP
This commit is contained in:
parent
a179bf02c0
commit
806ea326ec
@ -28,7 +28,7 @@ public class TestCommand extends Command {
|
|||||||
ScapeFashionConnection conn = new ScapeFashionConnection();
|
ScapeFashionConnection conn = new ScapeFashionConnection();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ctx.reply(conn.osrsColor("#00ff00").toString(2));
|
conn.osrsColor("#00ff00");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
ctx.reply(e.getMessage());
|
ctx.reply(e.getMessage());
|
||||||
}
|
}
|
||||||
|
@ -13,8 +13,13 @@ import org.json.JSONObject;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.net.URI;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
|
import java.net.http.HttpClient;
|
||||||
|
import java.net.http.HttpRequest;
|
||||||
|
import java.net.http.HttpResponse;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
public class ScapeFashionConnection {
|
public class ScapeFashionConnection {
|
||||||
private final String RS3_REQUEST_URL = "https://api.rune.scape.fashion";
|
private final String RS3_REQUEST_URL = "https://api.rune.scape.fashion";
|
||||||
@ -36,11 +41,11 @@ public class ScapeFashionConnection {
|
|||||||
|
|
||||||
// Uses the color endpoint to search for items
|
// Uses the color endpoint to search for items
|
||||||
// Returns an object with a list of the top results, and a link redirect to see full list
|
// Returns an object with a list of the top results, and a link redirect to see full list
|
||||||
public JSONArray osrsColor(String color) throws IOException {
|
public void osrsColor(String color) throws IOException {
|
||||||
String url = OSRS_REQUEST_URL + "/colors/" + encode(color);
|
String url = OSRS_REQUEST_URL + "/colors/" + encode(color);
|
||||||
System.out.println(url);
|
System.out.println(url);
|
||||||
|
|
||||||
return makeRequest(url);
|
makeRequestNEW(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void osrsColor(String color, String slot) {
|
private void osrsColor(String color, String slot) {
|
||||||
@ -81,6 +86,19 @@ public class ScapeFashionConnection {
|
|||||||
return new JSONObject(response.body().string()).getJSONArray("items");
|
return new JSONObject(response.body().string()).getJSONArray("items");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void makeRequestNEW(String url) {
|
||||||
|
var client = HttpClient.newBuilder().version(HttpClient.Version.HTTP_2).build();
|
||||||
|
|
||||||
|
HttpRequest request = HttpRequest.newBuilder(URI.create(url))
|
||||||
|
.header("Content-Type", "application/json")
|
||||||
|
.header("User-Agent", USER_AGENT)
|
||||||
|
.GET()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
CompletableFuture<HttpResponse<String>> response = client.sendAsync(request, HttpResponse.BodyHandlers.ofString());
|
||||||
|
response.thenAcceptAsync(res -> System.out.println(res.body()));
|
||||||
|
}
|
||||||
|
|
||||||
private String encode(String value) throws UnsupportedEncodingException {
|
private String encode(String value) throws UnsupportedEncodingException {
|
||||||
return URLEncoder.encode(value, StandardCharsets.UTF_8.toString());
|
return URLEncoder.encode(value, StandardCharsets.UTF_8.toString());
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,26 @@ public class ScapeFashionItem {
|
|||||||
this.match = builder.match;
|
this.match = builder.match;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSlot() {
|
||||||
|
return slot;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLink() {
|
||||||
|
return link;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String[] getColors() {
|
||||||
|
return colors;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getMatch() {
|
||||||
|
return match;
|
||||||
|
}
|
||||||
|
|
||||||
public static class Builder {
|
public static class Builder {
|
||||||
private String name;
|
private String name;
|
||||||
private String slot;
|
private String slot;
|
||||||
|
Loading…
Reference in New Issue
Block a user