use of no.stelar7.api.r4j.pojo.val.content.Content in project L4J8 by stelar7.
the class TestVALContent method testGetContent.
@Test
public void testGetContent() {
R4J api = new R4J(SecretFile.CREDS);
VALContentAPI content = api.getVALAPI().getContentAPI();
Content data = content.getContent(ValorantShard.EU, Optional.empty());
System.out.println(data);
}
use of no.stelar7.api.r4j.pojo.val.content.Content in project L4J8 by stelar7.
the class VALContentAPI method getContent.
public Content getContent(ValorantShard server, Optional<String> locale) {
DataCallBuilder builder = new DataCallBuilder().withURLParameter(Constants.REGION_PLACEHOLDER, server.name()).withHeader(Constants.X_RIOT_TOKEN_HEADER_KEY, DataCall.getCredentials().getVALAPIKey()).withEndpoint(URLEndpoint.V1_VAL_CONTENT).withPlatform(server);
locale.ifPresent(s -> builder.withQueryParameter(Constants.LOCALE_PLACEHOLDER_DATA, s));
Map<String, Object> data = new TreeMap<>();
data.put("platform", server);
data.put("locale", locale.orElse("null"));
Optional<?> chl = DataCall.getCacheProvider().get(URLEndpoint.V1_VAL_CONTENT, data);
if (chl.isPresent()) {
return (Content) chl.get();
}
try {
Object ret = builder.build();
Content cont = (Content) ret;
data.put("value", cont);
DataCall.getCacheProvider().store(URLEndpoint.V1_VAL_CONTENT, data);
return cont;
} catch (ClassCastException e) {
return null;
}
}
use of no.stelar7.api.r4j.pojo.val.content.Content in project L4J8 by stelar7.
the class LCUApi method createNotification.
/**
* Creates a notification
*
* @param title title of notification
* @param content body of notification
* @param icon icon of notification
* @param background background image of notification
* @param dismissable true if able to dismiss
* @param state read or unread
* @return the notification id
*/
public static int createNotification(String title, String content, String icon, String background, boolean dismissable, String state) {
Pair<String, String> header = LCUConnection.getAuthorizationHeader();
StringWriter sw = new StringWriter();
try {
JsonWriter jw = new JsonWriter(sw);
jw.beginObject().name("backgroundUrl").value(background).name("created").value(LocalDateTime.now().toString()).name("dismissible").value(dismissable).name("detailKey").value("pre_translated_details").name("titleKey").value("pre_translated_title").name("data").beginObject().name("title").value(title).name("content").value(content).endObject().name("iconUrl").value(icon).name("state").value(state).endObject();
} catch (IOException e) {
e.printStackTrace();
}
String postData = sw.toString();
JsonObject obj = (JsonObject) new DataCallBuilder().withLimiters(false).withProxy(LCUConnection.getConnectionString() + Constants.GSVR).withEndpoint(URLEndpoint.LCU_CREATE_NOTIFICATION).withRequestMethod("POST").withPostData(postData).withHeader(header.getKey(), header.getValue()).build();
return obj.get("id").getAsInt();
}
use of no.stelar7.api.r4j.pojo.val.content.Content in project L4J8 by stelar7.
the class LCUSocketReader method setupConnection.
private void setupConnection(String password, String port) {
try {
String url = String.format("wss://localhost:%s/", port);
WebSocketFactory factory = new WebSocketFactory();
factory.setSSLContext(SimpleSSLContext.getInstance("TLS"));
factory.setVerifyHostname(false);
socket = factory.createSocket(url);
socket.setUserInfo("riot", password);
socket.addListener(new WebSocketAdapter() {
@Override
public void onTextMessage(WebSocket websocket, String text) {
JsonElement elem = new JsonParser().parse(text);
JsonArray data = elem.getAsJsonArray();
String id = data.get(0).toString();
String event = data.get(1).getAsString();
String content = data.get(2).getAsJsonObject().toString();
List<Consumer<String>> headerConsumers = headerHandlers.getOrDefault(event, Collections.emptyList());
List<Consumer<String>> rawConsumers = rawHandlers.getOrDefault(event, Collections.emptyList());
try {
StringWriter holder = new StringWriter();
JsonWriter jw = new JsonWriter(holder);
jw.beginObject();
jw.name(event).jsonValue(content);
jw.endObject();
jw.flush();
jw.close();
headerConsumers.forEach(c -> c.accept(holder.toString()));
rawConsumers.forEach(c -> c.accept(content));
} catch (IOException e) {
e.printStackTrace();
}
}
});
} catch (IOException | NoSuchAlgorithmException e) {
e.printStackTrace();
}
}
Aggregations