use of me.duncte123.botcommons.web.WebParserUtils in project SkyBot by DuncteBot.
the class AirUtils method shortenUrl.
@Nonnull
public static PendingRequest<String> shortenUrl(String url, String googleKey, ObjectMapper mapper, String prefix) {
final ObjectNode json = mapper.createObjectNode();
json.set("dynamicLinkInfo", mapper.createObjectNode().put("domainUriPrefix", prefix).put("link", url));
json.set("suffix", mapper.createObjectNode().put("option", // SHORT or UNGUESSABLE
"SHORT"));
try {
return WebUtils.ins.postRequest("https://firebasedynamiclinks.googleapis.com/v1/shortLinks?key=" + googleKey, JSONRequestBody.fromJackson(json)).setRateLimiter(RateLimiter.directLimiter()).build((r) -> {
final ObjectNode response = toJSONObject(r, mapper);
if (response == null) {
return "Google did a fucky wucky and send invalid json";
}
return response.get("shortLink").asText();
}, WebParserUtils::handleError);
} catch (JsonProcessingException e) {
e.printStackTrace();
// Return a fake pending request to make sure that things don't break
return new FakePendingRequest<>("JSON PARSING FAILED: " + e.getMessage());
}
}
use of me.duncte123.botcommons.web.WebParserUtils in project SkyBot by duncte123.
the class AirUtils method shortenUrl.
@Nonnull
public static PendingRequest<String> shortenUrl(String url, String googleKey, ObjectMapper mapper, String prefix) {
final ObjectNode json = mapper.createObjectNode();
json.set("dynamicLinkInfo", mapper.createObjectNode().put("domainUriPrefix", prefix).put("link", url));
json.set("suffix", mapper.createObjectNode().put("option", // SHORT or UNGUESSABLE
"SHORT"));
try {
return WebUtils.ins.postRequest("https://firebasedynamiclinks.googleapis.com/v1/shortLinks?key=" + googleKey, JSONRequestBody.fromJackson(json)).build((r) -> {
final ObjectNode response = toJSONObject(r, mapper);
if (response == null) {
return "Google did a fucky wucky and send invalid json";
}
return response.get("shortLink").asText();
}, WebParserUtils::handleError);
} catch (JsonProcessingException e) {
e.printStackTrace();
// Return a fake pending request to make sure that things don't break
return new FakePendingRequest<>("JSON PARSING FAILED: " + e.getMessage());
}
}
Aggregations