public async Task<List<TwitterFeedItemDto>> GetHomeFeed() { var url = new Uri(String.Format ("{0}{1}", BASE_URL, Routes.TWITTER_HOME_FEED)); var parameters = new Dictionary<string, string> () { { "count", "20" }, { "include_rts", "1" }, { "exclude_replies", "0" }, { "include_entities", "1" }, { "trim_user", "0" }, { "contributor_details", "1" } }; try { _logger.StartTrackTime(TimedEvent.GET_TWITTER_FEED.ToString()); var response = await _twitterHelper.ExecuteRequest (GET, url, parameters); var results = JsonConvert.DeserializeObject<List<TwitterFeedItemDto>> (response, _settings); return results; } catch (Exception e) { var exception = new ApiException("Failed to get tweets", e); _logger.Log(exception, LogType.ERROR); throw exception; } finally { _logger.StopTrackTime(TimedEvent.GET_TWITTER_FEED.ToString()); } }
public async Task<FacebookResponseDto> GetHomeFeed () { var url = new Uri (String.Format ("{0}{1}", BASE_URL, Routes.FACEBOOK_HOME_FEED)); var parameters = new Dictionary<string, string> () { { "limit", "20" }, { "fields", "full_picture,created_time,id,updated_time,message,link,shares,from,likes,comments,actions,story,name,description,type,source"} }; try { _logger.StartTrackTime(TimedEvent.GET_FACEBOOK_FEED.ToString()); var response = await _facebookHelper.ExecuteRequest(GET, url, parameters); var results = JsonConvert.DeserializeObject<FacebookResponseDto>(response); return results; } catch (Exception e) { var exception = new ApiException ("Failed to get facebook posts", e); _logger.Log (exception, LogType.ERROR); throw exception; } finally { _logger.StopTrackTime(TimedEvent.GET_FACEBOOK_FEED.ToString()); } }
public async Task<FacebookToFromDto> GetUser () { var url = new Uri (String.Format ("{0}{1}", BASE_URL, Routes.FACEBOOK_USER)); try { _logger.StartTrackTime(TimedEvent.GET_FACEBOOK_USER.ToString()); var response = await _facebookHelper.ExecuteRequest(GET, url); var result = JsonConvert.DeserializeObject<FacebookToFromDto>(response); return result; } catch (Exception e) { var exception = new ApiException ("Failed to get facebook user", e); _logger.Log (exception, LogType.ERROR); throw exception; } finally { _logger.StopTrackTime(TimedEvent.GET_FACEBOOK_USER.ToString()); } }
public async Task Like(string postId) { var url = new Uri (String.Format ("{0}/{1}{2}", BASE_URL, postId, Routes.FACEBOOK_LIKE)); try { _logger.StartTrackTime(TimedEvent.FACEBOOK_LIKE.ToString()); await _facebookHelper.ExecuteRequest(POST, url, null); } catch (Exception e) { var exception = new ApiException("Failed to like facebook post", e); _logger.Log(exception, LogType.ERROR); throw exception; } finally { _logger.StopTrackTime(TimedEvent.FACEBOOK_LIKE.ToString()); } }
public async Task Post (string userId, string message) { // TODO: May need to change this endpoints if images or links need to be included var url = new Uri(String.Format("{0}/{1}{2}", BASE_URL, userId, Routes.FACEBOOK_POST)); var parameters = new Dictionary<string, string> () { // { "link", link }, // { "picture", picture }, { "message", message } }; try { // TODO: Determine if we care about if this fails // Do we store locally and try to resync later? // Do we just alert the user that twitter failed? _logger.StartTrackTime(TimedEvent.FACEBOOK_POST.ToString()); await _facebookHelper.ExecuteRequest(POST, url, parameters); } catch (Exception e) { var exception = new ApiException("Failed to post a tweet", e); _logger.Log(exception, LogType.ERROR); throw exception; } finally { _logger.StopTrackTime(TimedEvent.FACEBOOK_POST.ToString()); } }
public async Task DeleteComment (string commentId) { var url = new Uri(String.Format("{0}/{1}{2}", BASE_URL, Routes.FACEBOOK_DELETE_COMMENT, commentId)); try { _logger.StartTrackTime(TimedEvent.DELETE_FACEBOOK_COMMENT.ToString()); await _facebookHelper.ExecuteRequest(DELETE, url); } catch (Exception e) { var exception = new ApiException("Failed to delete a comment on facebook post", e); _logger.Log(exception, LogType.ERROR); throw exception; } finally { _logger.StopTrackTime(TimedEvent.DELETE_FACEBOOK_COMMENT.ToString()); } }
public async Task Comment (string postId, string message) { var url = new Uri(String.Format("{0}/{1}{2}", BASE_URL, postId, Routes.FACEBOOK_COMMENT)); var parameters = new Dictionary<string, string> () { { "message", message } }; try { // TODO: return id so we can track the post locally _logger.StartTrackTime(TimedEvent.FACEBOOK_COMMENT.ToString()); await _facebookHelper.ExecuteRequest(POST, url, parameters); } catch (Exception e) { var exception = new ApiException("Failed to comment on facebook post", e); _logger.Log(exception, LogType.ERROR); throw exception; } finally { _logger.StopTrackTime(TimedEvent.FACEBOOK_COMMENT.ToString()); } }
public async Task Like(string tweetId) { var url = new Uri (String.Format ("{0}{1}", BASE_URL, Routes.TWITTER_LIKE)); var parameters = new Dictionary<string, string> () { { "id", tweetId } }; try { _logger.StartTrackTime(TimedEvent.TWITTER_LIKE.ToString()); await _twitterHelper.ExecuteRequest(POST, url, parameters); } catch (Exception e) { var exception = new ApiException("Failed to like tweet", e); _logger.Log(exception, LogType.ERROR); throw exception; } finally { _logger.StopTrackTime(TimedEvent.TWITTER_LIKE.ToString()); } }
public async Task<TwitterUserDto> GetUser (string screenName) { var url = new Uri (String.Format ("{0}{1}", BASE_URL, Routes.TWITTER_USER)); var parameters = new Dictionary<string, string> () { { "screen_name", screenName } }; try { _logger.StartTrackTime(TimedEvent.GET_TWITTER_USER.ToString()); var response = await _twitterHelper.ExecuteRequest(GET, url, parameters); var results = JsonConvert.DeserializeObject<TwitterUserDto>(response, _settings); return results; } catch (Exception e) { var exception = new ApiException("Failed to user", e); _logger.Log(exception, LogType.ERROR); throw exception; } finally { _logger.StopTrackTime(TimedEvent.GET_TWITTER_USER.ToString()); } }
public async Task DeleteTweet (string tweetId) { var url = new Uri(String.Format("{0}/{1}/{2}.json", BASE_URL, Routes.TWITTER_DELETE_POST, tweetId)); try { _logger.StartTrackTime(TimedEvent.DELETE_TWITTER_POST.ToString()); await _twitterHelper.ExecuteRequest(POST, url); } catch (Exception e) { var exception = new ApiException("Failed to delete a comment on twitter post", e); _logger.Log(exception, LogType.ERROR); throw exception; } finally { _logger.StopTrackTime(TimedEvent.DELETE_TWITTER_POST.ToString()); } }
public async Task Comment (string tweetId, string message) { var url = new Uri(String.Format("{0}{1}", BASE_URL, Routes.TWITTER_POST)); var parameters = new Dictionary<string, string> () { { "in_reply_to_status_id", tweetId }, { "status", message } }; try { // TODO: return the id so we can track this _logger.StartTrackTime(TimedEvent.TWITTER_COMMENT.ToString()); await _twitterHelper.ExecuteRequest(POST, url, parameters); } catch (Exception e) { var exception = new ApiException("Failed to comment on twitter post", e); _logger.Log(exception, LogType.ERROR); throw exception; } finally { _logger.StopTrackTime(TimedEvent.TWITTER_COMMENT.ToString()); } }