use of de.foryasee.httprequest.RequestResponse in project Rubicon by Rubicon-Bot.
the class WebpanelManager method sendRequest.
public void sendRequest(HttpRequestBuilder request) {
try {
request.addParameter("token", requestToken);
RequestResponse response = request.sendRequest();
if (response.getResponseCode() != 200) {
Logger.debug(response.getResponseMessage());
throw new Exception("Error while sending request to " + response.getEndpointUrl());
}
} catch (Exception e) {
e.printStackTrace();
}
}
use of de.foryasee.httprequest.RequestResponse 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.RequestResponse in project Rubicon by Rubicon-Bot.
the class MojangUtil method fetchName.
private String fetchName(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("name").toString();
}
use of de.foryasee.httprequest.RequestResponse 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.RequestResponse 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