Search in sources :

Example 1 with UrlRequest

use of chatty.util.UrlRequest in project chatty by chatty.

the class NewsDialog method requestNews.

/**
 * Requests the announcements from the server.
 */
private void requestNews(final boolean openIfUnread) {
    news.setText("Loading..");
    latestNewsTimestamp = 0;
    lastRequested = System.currentTimeMillis();
    refreshButton.setEnabled(false);
    UrlRequest request = new UrlRequest(Chatty.DEBUG ? NEWS_URL_TEST : NEWS_URL);
    request.async((result, responseCode) -> {
        SwingUtilities.invokeLater(() -> {
            if (responseCode == 200) {
                int unread = setNews(result);
                if (openIfUnread && unread > 0) {
                    showDialog();
                }
            } else {
                news.setText("Error loading news. (" + responseCode + ")");
            }
            refreshButton.setEnabled(true);
        });
    });
}
Also used : UrlRequest(chatty.util.UrlRequest)

Example 2 with UrlRequest

use of chatty.util.UrlRequest in project chatty by chatty.

the class FrankerFaceZ method requestBotNames.

/**
 * Request and parse FFZ bot names.
 */
public void requestBotNames() {
    UrlRequest request = new UrlRequest("https://api.frankerfacez.com/v1/badge/bot");
    request.setLabel("FFZ Bots");
    request.async((result, responseCode) -> {
        if (result != null && responseCode == 200) {
            Set<String> botNames = FrankerFaceZParsing.getBotNames(result);
            LOGGER.info("[FFZ Bots] Found " + botNames.size() + " names");
            listener.botNamesReceived(botNames);
        }
    });
}
Also used : UrlRequest(chatty.util.UrlRequest)

Example 3 with UrlRequest

use of chatty.util.UrlRequest in project chatty by chatty.

the class WebsocketManager method fetchEmoteSet.

/**
 * Get the emotes from a specific emoteset, useable in the given room.
 *
 * @param room The channel the emotes should be useable in
 * @param emoteset The FFZ emoteset to fetch
 * @return A set of emotes or an empty set if an error occured
 */
private Set<Emoticon> fetchEmoteSet(String room, int emoteset) {
    UrlRequest r = new UrlRequest("https://api.frankerfacez.com/v1/set/" + emoteset);
    FullResult result = r.sync();
    if (result.getResult() != null) {
        Set<Emoticon> emotes = FrankerFaceZParsing.parseSetEmotes(result.getResult(), Emoticon.SubType.EVENT, room);
        return emotes;
    }
    return new HashSet<>();
}
Also used : Emoticon(chatty.util.api.Emoticon) UrlRequest(chatty.util.UrlRequest) FullResult(chatty.util.UrlRequest.FullResult) HashSet(java.util.HashSet)

Example 4 with UrlRequest

use of chatty.util.UrlRequest in project chatty by chatty.

the class UpdateMessage method loadChangelog.

/**
 * Loads the changelog if not already successfully loaded.
 */
private void loadChangelog() {
    if (changelogLoaded) {
        return;
    }
    changelog.setText("Loading..");
    UrlRequest request = new UrlRequest(CHANGELOG_URL);
    request.async((result, responseCode) -> {
        if (responseCode == 200) {
            changelog.setText(result);
            changelogLoaded = true;
        } else {
            changelog.setText("Error loading changelog.");
        }
    });
}
Also used : UrlRequest(chatty.util.UrlRequest)

Example 5 with UrlRequest

use of chatty.util.UrlRequest in project chatty by chatty.

the class FrankerFaceZ method request.

/**
 * Issue a request of the given type and stream.
 *
 * <p>
 * The URL which is used for the request is build from the paramters. Only
 * requests each URL once, unless {@code forcedUpdate} is true. Always
 * prevents the same URL from being requested twice at the same time.</p>
 *
 * <p>This is not safe to be called unsynchronized, because of the way
 * check the URL for being already requested/pending is done.</p>
 *
 * @param type The type of request
 * @param stream The stream, can be {@code null} if not needed for this type
 * @param forcedUpdate Whether to request even if already requested before
 */
private void request(final Type type, final String stream, boolean forcedUpdate) {
    final String url = getUrl(type, stream);
    if (requestPending.contains(url) || (alreadyRequested.contains(url) && !forcedUpdate)) {
        return;
    }
    alreadyRequested.add(url);
    requestPending.add(url);
    // Create request and run it in a seperate thread
    UrlRequest request = new UrlRequest();
    request.setLabel("FFZ");
    request.setUrl(url);
    request.async((result, responseCode) -> {
        requestPending.remove(url);
        parseResult(type, stream, result);
    });
}
Also used : UrlRequest(chatty.util.UrlRequest)

Aggregations

UrlRequest (chatty.util.UrlRequest)5 FullResult (chatty.util.UrlRequest.FullResult)1 Emoticon (chatty.util.api.Emoticon)1 HashSet (java.util.HashSet)1