/** * Sends a DELETE request with a body. * * @param url * the url where to send the DELETE request. * @param entity * the entity to DELETE. * @return the delete response. */ public static BotMillNetworkResponse delete(String url, StringEntity entity) { HttpDeleteWithBody delete = new HttpDeleteWithBody(url); delete.setEntity(entity); return send(delete); }
/** * Sends a DELETE request. * * @param url * the url where to send the DELETE request. * @return the delete response. */ public static BotMillNetworkResponse delete(String url) { HttpDelete delete = new HttpDelete(url); return send(delete); }
/** * Performs a POST and propagates it to the registered monitors. * * @param url * the URL where to post. * @param input * the object to send. * @return the response. */ private static BotMillNetworkResponse postInternal(String url, StringEntity input) { BotMillNetworkResponse response = NetworkUtils.post(url, input); propagateResponse(response); return response; }
HttpResponse httpResponse = null; String responseContent = null; BotMillNetworkResponse response = new BotMillNetworkResponse(); responseContent = getResponseContent(httpResponse); logger.error("HTTP connection failed with error code {}.", statusCode); response.setError(true); response.setResponse(responseContent); return response;
/** * GETs the daily unique active thread counts. * * @return the daily unique active thread counts. */ public static DailyUniqueActiveThreadCounts getDailyUniqueActiveThreadCounts() { String pageToken = FbBotMillContext.getInstance().getPageToken(); BotMillNetworkResponse response = NetworkUtils .get(FbBotMillNetworkConstants.FACEBOOK_BASE_URL + FbBotMillNetworkConstants.FACEBOOK_MESSAGING_INSIGHT_ACTIVE_THREADS_URL + pageToken); return FbBotMillJsonUtils.fromJson(response.getResponse(), DailyUniqueActiveThreadCounts.class); }
String output = response.getResponse(); if (response.isError()) {
/** * DELETEs a JSON string as a Facebook's Messenger Profile. * * @param input * the JSON data to send. */ public static void deleteMessengerProfile(StringEntity input) { String pageToken = FbBotMillContext.getInstance().getPageToken(); // If the page token is invalid, returns. if (!validatePageToken(pageToken)) { return; } String url = FbBotMillNetworkConstants.FACEBOOK_BASE_URL + FbBotMillNetworkConstants.FACEBOOK_MESSENGER_PROFILE + pageToken; BotMillNetworkResponse response = NetworkUtils.delete(url, input); propagateResponse(response); }
/** * POSTs an attachment as a JSON string to Facebook. * * @param input * the JSON data to send. * @return the uploaded attachment ID. */ public static UploadAttachmentResponse postUploadAttachment( StringEntity input) { String pageToken = FbBotMillContext.getInstance().getPageToken(); // If the page token is invalid, returns. if (!validatePageToken(pageToken)) { return null; } String url = FbBotMillNetworkConstants.FACEBOOK_BASE_URL + FbBotMillNetworkConstants.FACEBOOK_UPLOAD_API_URL + pageToken; BotMillNetworkResponse response = postInternal(url, input); // Parses the response as a UploadAttachmentResponse and returns it. return FbBotMillJsonUtils.fromJson(response.getResponse(), UploadAttachmentResponse.class); }
/** * GETs the daily unique conversation counts. * * @return the daily unique conversation counts. */ public static DailyUniqueConversationCounts getDailyUniqueConversationCounts() { String pageToken = FbBotMillContext.getInstance().getPageToken(); BotMillNetworkResponse response = NetworkUtils .get(FbBotMillNetworkConstants.FACEBOOK_BASE_URL + FbBotMillNetworkConstants.FACEBOOK_MESSAGING_INSIGHT_CONVERSATION_URL + pageToken); return FbBotMillJsonUtils.fromJson(response.getResponse(), DailyUniqueConversationCounts.class); }
/** * Utility to send a GET request. * * @param url * the url we need to send the get request to. * @return the get response. */ public static BotMillNetworkResponse get(String url) { HttpGet get = new HttpGet(url); return send(get); }
/** * DELETEs a JSON string as a Facebook's Thread Setting. * * @param input * the JSON data to send. */ public static void deleteThreadSetting(StringEntity input) { String pageToken = FbBotMillContext.getInstance().getPageToken(); // If the page token is invalid, returns. if (!validatePageToken(pageToken)) { return; } String url = FbBotMillNetworkConstants.FACEBOOK_BASE_URL + FbBotMillNetworkConstants.FACEBOOK_THREAD_SETTINGS_URL + pageToken; BotMillNetworkResponse response = NetworkUtils.delete(url, input); propagateResponse(response); }
/** * POSTs a messenger code as a JSON string to Facebook. * * @param input * the JSON data to send. * @return the requested messenger code. */ public static MessengerCode postMessengerCode(StringEntity input) { String pageToken = FbBotMillContext.getInstance().getPageToken(); // If the page token is invalid, returns. if (!validatePageToken(pageToken)) { return null; } String url = FbBotMillNetworkConstants.FACEBOOK_BASE_URL + FbBotMillNetworkConstants.FACEBOOK_MESSENGER_CODE_API_URL + pageToken; BotMillNetworkResponse response = postInternal(url, input); // Parses the response as a MessengerCode and returns it. return FbBotMillJsonUtils.fromJson(response.getResponse(), MessengerCode.class); }
/** * Method used to retrieve a {@link FacebookUserProfile} from an ID using * the GET method. * * @param userId * the ID of the user to retrieve. * @return the user profile info. */ public static FacebookUserProfile getUserProfile(String userId) { String pageToken = FbBotMillContext.getInstance().getPageToken(); BotMillNetworkResponse response = NetworkUtils .get(FbBotMillNetworkConstants.FACEBOOK_BASE_URL + userId + FbBotMillNetworkConstants.USER_PROFILE_FIELDS + pageToken); FacebookUserProfile user = FbBotMillJsonUtils.fromJson( response.getResponse(), FacebookUserProfile.class); return user; }
/** * Utility to send a POST request. * * @param url * the url we need to send the post request to. * @param entity * the entity that containts the object we need to pass as part * of the post request. * @return the post response. */ public static BotMillNetworkResponse post(String url, StringEntity entity) { HttpPost post = new HttpPost(url); //post.setHeader("Content-Type", "application/x-www-form-urlencoded"); post.setHeader("Content-Type","application/json"); post.setEntity(entity); return send(post); }