Search in sources :

Example 1 with Content

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);
}
Also used : Content(no.stelar7.api.r4j.pojo.val.content.Content) VALContentAPI(no.stelar7.api.r4j.impl.val.VALContentAPI) R4J(no.stelar7.api.r4j.impl.R4J) Test(org.junit.jupiter.api.Test)

Example 2 with Content

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;
    }
}
Also used : Content(no.stelar7.api.r4j.pojo.val.content.Content)

Example 3 with Content

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();
}
Also used : DataCallBuilder(no.stelar7.api.r4j.basic.calling.DataCallBuilder) JsonWriter(com.google.gson.stream.JsonWriter)

Example 4 with Content

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();
    }
}
Also used : Consumer(java.util.function.Consumer) com.neovisionaries.ws.client(com.neovisionaries.ws.client) java.util(java.util) Pair(no.stelar7.api.r4j.basic.utils.Pair) java.io(java.io) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) LoggerFactory(org.slf4j.LoggerFactory) com.google.gson(com.google.gson) JsonWriter(com.google.gson.stream.JsonWriter) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) JsonWriter(com.google.gson.stream.JsonWriter)

Aggregations

JsonWriter (com.google.gson.stream.JsonWriter)2 Content (no.stelar7.api.r4j.pojo.val.content.Content)2 com.google.gson (com.google.gson)1 com.neovisionaries.ws.client (com.neovisionaries.ws.client)1 java.io (java.io)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 java.util (java.util)1 Consumer (java.util.function.Consumer)1 DataCallBuilder (no.stelar7.api.r4j.basic.calling.DataCallBuilder)1 Pair (no.stelar7.api.r4j.basic.utils.Pair)1 R4J (no.stelar7.api.r4j.impl.R4J)1 VALContentAPI (no.stelar7.api.r4j.impl.val.VALContentAPI)1 Test (org.junit.jupiter.api.Test)1 LoggerFactory (org.slf4j.LoggerFactory)1