/// <summary>
        /// transforms XML into IQueryable of User
        /// </summary>
        /// <param name="responseXml">xml with Twitter response</param>
        /// <returns>IQueryable of User</returns>
        public List <T> ProcessResults(string responseXml)
        {
            XElement twitterResponse = XElement.Parse(responseXml);
            var      graph           = new SocialGraph
            {
                Type           = Type,
                ID             = ID,
                UserID         = UserID,
                ScreenName     = ScreenName,
                Page           = Page,
                Cursor         = Cursor,
                CursorMovement = new Cursors
                {
                    Next =
                        twitterResponse.Element("next_cursor") == null ?
                        string.Empty :
                        twitterResponse.Element("next_cursor").Value,
                    Previous =
                        twitterResponse.Element("previous_cursor") == null ?
                        string.Empty :
                        twitterResponse.Element("previous_cursor").Value
                }
            };

            IEnumerable <string> idList = null;

            // TODO: analyze to determine if this (CursorMovement and IDs) can be refactored to use IDList list as done in friendship/incoming and friendship/outgoing.
            //  Would be a breaking change, but yet pull API into consistent usage in this area.
            //  Because of the if statement this might not be straight forward, but then again, if statement might be OBE since initial API creation and all that is needed is to parse IDs rather than a single ID. - Joe 4/16/2010

            // we get back ids if using cursors but id if not using cursors
            if (twitterResponse.Element("ids") == null)
            {
                idList =
                    from id in twitterResponse.Elements("id").ToList()
                    select id.Value;
            }
            else
            {
                idList =
                    from id in twitterResponse.Element("ids").Elements("id").ToList()
                    select id.Value;
            }

            graph.IDs = idList.ToList();

            return(new List <SocialGraph> {
                graph
            }.OfType <T>().ToList());
        }
Esempio n. 2
0
        /// <summary>
        /// Transforms Twitter response into List of SocialGraph
        /// </summary>
        /// <param name="responseJson">Twitter response</param>
        /// <returns>List of SocialGraph</returns>
        public List <T> ProcessResults(string responseJson)
        {
            if (string.IsNullOrEmpty(responseJson))
            {
                return(new List <T>());
            }

            JsonData graphJson = JsonMapper.ToObject(responseJson);

            var graph = new SocialGraph
            {
                Type           = Type,
                UserID         = UserID,
                ScreenName     = ScreenName,
                Cursor         = Cursor,
                Count          = Count,
                CursorMovement = new Cursors(graphJson)
            };

            switch (Type)
            {
            case SocialGraphType.Friends:
            case SocialGraphType.Followers:
                graph.IDs =
                    (from JsonData id in graphJson.GetValue <JsonData>("ids")
                     select id.ToString())
                    .ToList();
                break;

            default:
                break;
            }

            return(new List <SocialGraph> {
                graph
            }.OfType <T>().ToList());
        }
        public void SocialGraph_Can_Serialize()
        {
            var graph = new SocialGraph();
            var stringBuilder = new StringBuilder();

            var writer = XmlWriter.Create(stringBuilder);
            var xmlSerializer = new XmlSerializer(typeof(SocialGraph));
            xmlSerializer.Serialize(writer, graph);
        }
Esempio n. 4
0
 private static string CreateIdsText(SocialGraph source)
 {
     return string.Format(
         "{0}\n\nNextCursor:{1}\nPreviousCursor:{2}",
         string.Join("\n", source.IDs),
         source.CursorMovement.Next,
         source.CursorMovement.Previous
     );
 }