/// <summary>
        /// Processes the response from the feed service.
        /// </summary>
        /// <param name="response">response from the feed service.</param>
        internal override void ProcessResponse(object responseObject)
        {
            string response = responseObject.ToString();

            byte[]            byteArray = Encoding.UTF8.GetBytes(response);
            TwitterJsonStatus status    = null;

            using (MemoryStream stream = new MemoryStream(byteArray))
            {
                status = _json.ReadObject(stream) as TwitterJsonStatus;
            }

            StatusFeedItem feedItem = new StatusFeedItem
            {
                Author    = status.user.screen_name,
                AvatarUri = new Uri(status.user.profile_image_url),
                Date      = DateTimeOffset.ParseExact(status.created_at, "ddd MMM dd HH:mm:ss zzz yyyy", CultureInfo.InvariantCulture).DateTime,
                ServiceId = status.id,
                Uri       = new Uri(string.Format(CultureInfo.InvariantCulture, "http://twitter.com/#!/{0}/status/{1}", status.user.screen_name, status.id)),
                Status    = status.text
            };

            RaiseGotNewFeedItem(feedItem);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Processes the response to convert owner's posts into feed items.
        /// </summary>
        /// <param name="response">response from the feed service.</param>
        internal void ProcessResponseWithOwner(dynamic response)
        {
            #region Process Owner's Image Items

            if (response.data[_ownerPhotoDataIndex]["fql_result_set"].Count > 0)                            // ownerphotodata
            {
                foreach (dynamic photo in response.data[_ownerPhotoDataIndex]["fql_result_set"])            // ownerphotodata
                {
                    foreach (dynamic author in response.data[_ownerPhotoAuthorDataIndex]["fql_result_set"]) // ownerphotoauthordata
                    {
                        DateTime created = ConvertFromUnixTimestamp(double.Parse(photo["created"].ToString()));

                        if (created < MinDate)
                        {
                            continue;
                        }

                        // add a feed if matching author is found for the post
                        if (photo.owner == author.page_id)
                        {
                            ImageFeedItem feedItem = new ImageFeedItem
                            {
                                Author       = (string)author["name"],
                                AvatarUri    = new Uri((string)author["pic_small"]),
                                Date         = created,
                                ServiceId    = (string)photo["pid"],
                                Uri          = new Uri(string.Format(CultureInfo.InvariantCulture, (string)photo["link"])),
                                SourceType   = SourceType.Facebook,
                                Caption      = (string)photo["caption"],
                                ThumbnailUri = new Uri(string.Format(CultureInfo.InvariantCulture, (string)photo["src_big"])),
                            };

                            RaiseGotNewFeedItem(feedItem);
                        }

                        break;
                    }
                }
            }

            #endregion

            #region Process Owner's Status Items

            if (response.data[_ownerStatusStreamIndex]["fql_result_set"].Count > 0)
            {
                foreach (dynamic post in response.data[_ownerStatusStreamIndex]["fql_result_set"])           // ownerstatusstream
                {
                    foreach (dynamic author in response.data[_ownerStatusAuthorDataIndex]["fql_result_set"]) // ownerstatusauthordata
                    {
                        if (post.actor_id == author.page_id)
                        {
                            // create status feed item if matching author data is found for this post
                            DateTime created = ConvertFromUnixTimestamp(double.Parse(post["created_time"].ToString()));

                            if (created < MinDate)
                            {
                                continue;
                            }

                            StatusFeedItem feedItem = new StatusFeedItem
                            {
                                Author     = (string)author["name"],
                                AvatarUri  = new Uri((string)author["pic_small"]),
                                Date       = created,
                                ServiceId  = (string)post["post_id"],
                                Uri        = new Uri(string.Format(CultureInfo.InvariantCulture, (string)post["permalink"])),
                                Status     = (string)post["message"],
                                SourceType = SourceType.Facebook,
                            };

                            RaiseGotNewFeedItem(feedItem);

                            break;
                        }
                    }
                }
            }

            #endregion
        }