TryFromStatusValueDictionary ( Dictionary <String, Object> statusValueDictionary, Boolean expandStatusUrls, out TwitterStatus twitterStatus ) { Debug.Assert(statusValueDictionary != null); twitterStatus = null; // Get the status information. String statusID, statusText; if ( !TwitterJsonUtil.TryGetJsonValueFromDictionary( statusValueDictionary, "id_str", out statusID) || !TwitterJsonUtil.TryGetJsonValueFromDictionary( statusValueDictionary, "text", out statusText) ) { return(false); } String statusDateUtc; if (TwitterJsonUtil.TryGetJsonValueFromDictionary( statusValueDictionary, "created_at", out statusDateUtc)) { statusDateUtc = TwitterDateParser.ParseTwitterDate(statusDateUtc); } String latitude, longitude; TwitterGraphMLUtil.GetLatitudeAndLongitudeFromStatusValueDictionary( statusValueDictionary, out latitude, out longitude); String statusUrls, statusHashtags; TwitterGraphMLUtil.GetUrlsAndHashtagsFromStatusValueDictionary( statusValueDictionary, expandStatusUrls, out statusUrls, out statusHashtags); String inReplyToStatusID; TwitterJsonUtil.TryGetJsonValueFromDictionary( statusValueDictionary, "in_reply_to_status_id_str", out inReplyToStatusID); // Note that null date, coordinates, URLs hashtags, and in-reply-to-ID // are acceptable here. twitterStatus = new TwitterStatus( statusID, statusText, statusDateUtc, latitude, longitude, statusUrls, statusHashtags, inReplyToStatusID); return(true); }
AppendValueFromValueDictionary ( Dictionary <String, Object> valueDictionary, String name, GraphMLXmlDocument graphMLXmlDocument, XmlNode edgeOrVertexXmlNode, String graphMLAttributeID ) { Debug.Assert(valueDictionary != null); Debug.Assert(!String.IsNullOrEmpty(name)); Debug.Assert(graphMLXmlDocument != null); Debug.Assert(edgeOrVertexXmlNode != null); Debug.Assert(!String.IsNullOrEmpty(graphMLAttributeID)); String value; if (TwitterJsonUtil.TryGetJsonValueFromDictionary( valueDictionary, name, out value)) { graphMLXmlDocument.AppendGraphMLAttributeValue( edgeOrVertexXmlNode, graphMLAttributeID, value); return(true); } return(false); }
AppendUserStatisticsFromValueDictionary ( Dictionary <String, Object> userValueDictionary, GraphMLXmlDocument graphMLXmlDocument, TwitterUser twitterUser ) { Debug.Assert(userValueDictionary != null); Debug.Assert(graphMLXmlDocument != null); Debug.Assert(twitterUser != null); XmlNode vertexXmlNode = twitterUser.VertexXmlNode; AppendValueFromValueDictionary(userValueDictionary, "friends_count", graphMLXmlDocument, vertexXmlNode, VertexFollowedID); AppendValueFromValueDictionary(userValueDictionary, "followers_count", graphMLXmlDocument, vertexXmlNode, VertexFollowersID); AppendValueFromValueDictionary(userValueDictionary, "statuses_count", graphMLXmlDocument, vertexXmlNode, VertexStatusesID); AppendValueFromValueDictionary(userValueDictionary, "favourites_count", graphMLXmlDocument, vertexXmlNode, VertexFavoritesID); AppendValueFromValueDictionary(userValueDictionary, "description", graphMLXmlDocument, vertexXmlNode, VertexDescriptionID); AppendValueFromValueDictionary(userValueDictionary, "location", graphMLXmlDocument, vertexXmlNode, VertexLocationID); AppendValueFromValueDictionary(userValueDictionary, "url", graphMLXmlDocument, vertexXmlNode, VertexUrlID); AppendValueFromValueDictionary(userValueDictionary, "time_zone", graphMLXmlDocument, vertexXmlNode, VertexTimeZoneID); AppendValueFromValueDictionary(userValueDictionary, "utc_offset", graphMLXmlDocument, vertexXmlNode, VertexUtcOffsetID); String joinedDateUtc; if (TwitterJsonUtil.TryGetJsonValueFromDictionary(userValueDictionary, "created_at", out joinedDateUtc)) { graphMLXmlDocument.AppendGraphMLAttributeValue( vertexXmlNode, VertexJoinedDateUtcID, TwitterDateParser.ParseTwitterDate(joinedDateUtc)); } }
TryGetUserIDFromDictionary ( Dictionary <String, Object> oUserValueDictionary, out String sUserID ) { Debug.Assert(oUserValueDictionary != null); AssertValid(); return(TwitterJsonUtil.TryGetJsonValueFromDictionary( oUserValueDictionary, "id_str", out sUserID)); }
TryAppendVertexXmlNode ( Dictionary <String, Object> userValueDictionary, Boolean userTweetedSearchTerm, GraphMLXmlDocument graphMLXmlDocument, Dictionary <String, TwitterUser> userIDDictionary, out TwitterUser twitterUser ) { Debug.Assert(userValueDictionary != null); Debug.Assert(graphMLXmlDocument != null); Debug.Assert(userIDDictionary != null); twitterUser = null; String screenName, userID; if ( !TwitterJsonUtil.TryGetJsonValueFromDictionary(userValueDictionary, "screen_name", out screenName) || !TwitterJsonUtil.TryGetJsonValueFromDictionary(userValueDictionary, "id_str", out userID) ) { return(false); } screenName = screenName.ToLower(); Boolean isFirstTweetForAuthor = TwitterGraphMLUtil.TryAppendVertexXmlNode( screenName, userID, graphMLXmlDocument, userIDDictionary, out twitterUser); if (isFirstTweetForAuthor) { TwitterGraphMLUtil.AppendCommonUserInformationFromValueDictionary( userValueDictionary, graphMLXmlDocument, twitterUser); TwitterGraphMLUtil.AppendUserStatisticsFromValueDictionary( userValueDictionary, graphMLXmlDocument, twitterUser); AppendTweetedSearchTermGraphMLAttributeValue( graphMLXmlDocument, twitterUser, userTweetedSearchTerm); } return(true); }
GetLatitudeAndLongitudeFromStatusValueDictionary ( Dictionary <String, Object> statusValueDictionary, out String latitude, out String longitude ) { Debug.Assert(statusValueDictionary != null); Object geoAsObject; if ( statusValueDictionary.TryGetValue("geo", out geoAsObject) && geoAsObject is Dictionary <String, Object> ) { Dictionary <String, Object> geoValueDictionary = (Dictionary <String, Object>)geoAsObject; Object coordinatesAsObject; if ( geoValueDictionary.TryGetValue("coordinates", out coordinatesAsObject) && coordinatesAsObject is Object[] ) { Object [] coordinates = ( Object[] )coordinatesAsObject; if (coordinates.Length == 2) { TwitterJsonUtil.TryConvertJsonValueToString( coordinates[0], out latitude); TwitterJsonUtil.TryConvertJsonValueToString( coordinates[1], out longitude); return; } } } latitude = longitude = null; }
TryGetScreenNameFromDictionary ( Dictionary <String, Object> oUserValueDictionary, out String sScreenName ) { Debug.Assert(oUserValueDictionary != null); AssertValid(); if (TwitterJsonUtil.TryGetJsonValueFromDictionary( oUserValueDictionary, "screen_name", out sScreenName)) { sScreenName = sScreenName.ToLower(); return(true); } return(false); }
EnumerateFriendOrFollowerIDs ( String sScreenName, Boolean bEnumerateFriendIDs, Int32 iMaximumPeoplePerRequest, RequestStatistics oRequestStatistics ) { Debug.Assert(!String.IsNullOrEmpty(sScreenName)); Debug.Assert(iMaximumPeoplePerRequest > 0); Debug.Assert(oRequestStatistics != null); AssertValid(); String sUrl = String.Format( "{0}{1}.json?screen_name={2}" , TwitterApiUrls.Rest, bEnumerateFriendIDs ? "friends/ids" : "followers/ids", TwitterUtil.EncodeUrlParameter(sScreenName) ); // The JSON looped through here has an "ids" name whose value is an // array of integer IDs. foreach (Object oUserIDAsObject in EnumerateJsonValues( sUrl, "ids", iMaximumPeoplePerRequest, true, oRequestStatistics)) { String sUserID; if (TwitterJsonUtil.TryConvertJsonValueToString( oUserIDAsObject, out sUserID)) { yield return(sUserID); } } }