private T GetResultFromPath <T>(JObject jObject, string[] paths) where T : class { if (paths != null && paths.Length > 0) { var path = string.Join(".", paths); var token = jObject.SelectToken(path); return(_jObjectStaticWrapper.ToObject <T>(token)); } return(_jObjectStaticWrapper.ToObject <T>(jObject)); }
public bool InvalidateCredentials(ITwitterCredentials credentials) { var url = "https://api.twitter.com/oauth2/invalidate_token"; var json = _twitterRequestHandler.ExecuteQuery(url, HttpMethod.POST, new InvalidateTokenHttpHandler(), credentials); var jobject = _jObjectStaticWrapper.GetJobjectFromJson(json); JToken unused; if (jobject.TryGetValue("access_token", out unused)) { return(true); } try { var errorsObject = jobject["errors"]; var errors = _jObjectStaticWrapper.ToObject <ITwitterExceptionInfo[]>(errorsObject); _exceptionHandler.TryLogExceptionInfos(errors, url); } catch (Exception) { // Something is definitely wrong! } return(false); }
public IEnumerable <ITwitterExceptionInfo> GetTwitterExceptionInfosFromStream(Stream stream) { if (stream == null) { return(null); } string twitterExceptionInfo = null; try { using (var reader = new StreamReader(stream)) { twitterExceptionInfo = reader.ReadToEnd(); var jObject = _jObjectStaticWrapper.GetJobjectFromJson(twitterExceptionInfo); return(_jObjectStaticWrapper.ToObject <IEnumerable <ITwitterExceptionInfo> >(jObject["errors"])); } } catch (Exception) { var twitterInfo = _twitterExceptionInfoUnityFactory.Create(); twitterInfo.Message = twitterExceptionInfo; return(new[] { twitterInfo }); } }
// Tweet private void TryRaiseQuotedTweetEvent(JObject userQuotedTweet) { var tweetDTO = _jObjectWrapper.ToObject <ITweetDTO>(userQuotedTweet["target_object"]); var tweet = _tweetFactory.GenerateTweetFromDTO(tweetDTO); TryRaiseTweetEvent(tweet); }
public List <ITweetDTO> GetTweetsFromJsonObject(JObject jObject) { if (jObject == null) { return(null); } return(_jObjectWrapper.ToObject <List <ITweetDTO> >(jObject["statuses"])); }
public ITwitterExceptionInfo[] GetTwitterExceptionInfos(string content) { try { var jObject = _jObjectStaticWrapper.GetJobjectFromJson(content); return(_jObjectStaticWrapper.ToObject <ITwitterExceptionInfo[]>(jObject["errors"])); } catch (Exception) { var twitterInfo = _twitterExceptionInfoUnityFactory.Create(); twitterInfo.Message = content; return(new[] { twitterInfo }); } }
private T GetResultFromPath <T>(JObject jObject, string[] paths) where T : class { if (paths != null && paths.Length > 0) { JToken token; if (!jObject.TryGetValue(paths[0], out token)) { return(null); } for (int i = 1; i < paths.Length; ++i) { if (!jObject.TryGetValue(paths[i], out token)) { return(null); } } return(_jObjectStaticWrapper.ToObject <T>(token)); } return(_jObjectStaticWrapper.ToObject <T>(jObject)); }
private List <ITweetDTO> GetTweetDTOsFromSearch(string httpQuery) { var jObject = _twitterAccessor.ExecuteGETQuery(httpQuery); return(_wrapper.ToObject <List <ITweetDTO> >(jObject["statuses"])); }