use of de.foryasee.httprequest.HttpRequestBuilder in project Rubicon by Rubicon-Bot.
the class Bitly method shorten.
/**
* Shortens a URL with bit.ly.
*
* @param longURL the URL to shorten.
* @return the shortened URL.
* @throws IllegalArgumentException if the long URI was invalid.
* @throws HTTPException if the bit.ly API returns a response code unlike 200 'OK'.
* @throws RuntimeException if the http request threw an unknown error.
*/
public static String shorten(String longURL) {
HttpRequestBuilder request = new HttpRequestBuilder(API_URL, RequestType.GET);
request.addParameter("access_token", Info.BITLY_TOKEN);
request.addParameter("longUrl", longURL);
request.addParameter("format", "json");
RequestResponse result;
try {
result = request.sendRequest();
} catch (Exception e) {
// catch 'anonymous' exceptions
throw new RuntimeException("An unknown exception occurred while fetching a bit.ly http request", e);
}
JSONObject response = new JSONObject(result.getResponseMessage());
// check if uri was valid
if (response.getString("status_txt").equals("INVALID_URI"))
throw new IllegalArgumentException("'" + longURL + "' is not a valid URL.");
else // ensure 'OK' status response
if (response.getInt("status_code") == 400)
throw new HTTPException(response.getInt("status_code"));
// return shortened url
return response.getJSONObject("data").getString("url");
}
use of de.foryasee.httprequest.HttpRequestBuilder in project Rubicon by Rubicon-Bot.
the class MemberCountUpdateRequestImpl method build.
@Override
public HttpRequestBuilder build() {
HttpRequestBuilder request = new HttpRequestBuilder(WebpanelData.BASE_URL, RequestType.GET);
request.addParameter("type", WebpanelData.MEMBER_COUNT_UPDATE.getKey());
request.addParameter("guildid", guild.getId());
request.addParameter("guildname", guild.getName());
request.addParameter("count", String.valueOf(guild.getMembers().size()));
return request;
}
use of de.foryasee.httprequest.HttpRequestBuilder in project Rubicon by Rubicon-Bot.
the class MojangUtil method fetchNameHistory.
private String fetchNameHistory(String uuid) {
HttpRequestBuilder request = new HttpRequestBuilder("https://api.mojang.com/user/profiles/" + uuid + "/names", RequestType.GET);
RequestResponse response = null;
try {
response = request.sendRequest();
} catch (Exception e) {
e.printStackTrace();
}
if (response.getResponseCode() != 200)
return null;
return response.getResponseMessage();
}
use of de.foryasee.httprequest.HttpRequestBuilder in project Rubicon by Rubicon-Bot.
the class MojangUtil method fetchUUID.
public String fetchUUID(String playername) {
HttpRequestBuilder request = new HttpRequestBuilder("https://api.mojang.com/users/profiles/minecraft/" + playername, RequestType.GET);
RequestResponse response = null;
try {
response = request.sendRequest();
} catch (Exception e) {
e.printStackTrace();
}
if (response.getResponseCode() != 200)
return null;
JSONObject json = null;
try {
json = (JSONObject) parser.parse(response.getResponseMessage());
} catch (ParseException e) {
e.printStackTrace();
}
return json.get("id").toString();
}
use of de.foryasee.httprequest.HttpRequestBuilder in project Rubicon by Rubicon-Bot.
the class MojangUtil method fetchStatus.
public JSONArray fetchStatus() {
HttpRequestBuilder request = new HttpRequestBuilder("https://status.mojang.com/check", RequestType.GET);
RequestResponse response = null;
try {
response = request.sendRequest();
} catch (Exception e) {
e.printStackTrace();
}
JSONArray res = null;
try {
res = ((JSONArray) parser.parse(response.getResponseMessage()));
} catch (ParseException e) {
Logger.error(e);
}
return res;
}
Aggregations