public ControlStreamFollow(JsonData csJson) { var follow = csJson.GetValue<JsonData>("follow"); User = new ControlStreamUser(follow.GetValue<JsonData>("user")); Friends = (from JsonData friend in follow.GetValue<JsonData>("friends") select (ulong)friend) .ToList(); Cursors = new Cursors(follow); }
public ControlStreamFollow(JsonData csJson) { var follow = csJson.GetValue <JsonData>("follow"); User = new ControlStreamUser(follow.GetValue <JsonData>("user")); Friends = (from JsonData friend in follow.GetValue <JsonData>("friends") select(ulong) friend) .ToList(); Cursors = new Cursors(follow); }
public IDList(JsonData idJson) { if (idJson == null) return; CursorMovement = new Cursors(idJson); var ids = idJson.GetValue<JsonData>("ids"); IDs = (from JsonData id in ids select (ulong)id) .ToList(); }
public User(JsonData user) { if (user == null) { return; } var userID = user.GetValue <ulong>("id").ToString(CultureInfo.InvariantCulture); Identifier = new UserIdentifier { ID = userID, UserID = userID, ScreenName = user.GetValue <string>("screen_name") }; Name = user.GetValue <string>("name"); Location = user.GetValue <string>("location"); Description = user.GetValue <string>("description"); ProfileImageUrl = user.GetValue <string>("profile_image_url"); ProfileImageUrlHttps = user.GetValue <string>("profile_image_url_https"); Url = user.GetValue <string>("url"); Protected = user.GetValue <bool>("protected"); ProfileUseBackgroundImage = user.GetValue <bool>("profile_use_background_image"); IsTranslator = user.GetValue <bool>("is_translator"); FollowersCount = user.GetValue <int>("followers_count"); DefaultProfile = user.GetValue <bool>("default_profile"); ProfileBackgroundColor = user.GetValue <string>("profile_background_color"); LangResponse = user.GetValue <string>("lang"); ProfileTextColor = user.GetValue <string>("profile_text_color"); ProfileLinkColor = user.GetValue <string>("profile_link_color"); ProfileSidebarFillColor = user.GetValue <string>("profile_sidebar_fill_color"); ProfileSidebarBorderColor = user.GetValue <string>("profile_sidebar_border_color"); FriendsCount = user.GetValue <int>("friends_count"); DefaultProfileImage = user.GetValue <bool>("default_profile_image"); CreatedAt = user.GetValue <string>("created_at").GetDate(DateTime.MinValue); FavoritesCount = user.GetValue <int>("favourites_count"); UtcOffset = user.GetValue <int>("utc_offset"); TimeZone = user.GetValue <string>("time_zone"); ProfileBackgroundImageUrl = user.GetValue <string>("profile_background_image_url"); ProfileBackgroundImageUrlHttps = user.GetValue <string>("profile_background_image_url_https"); ProfileBackgroundTile = user.GetValue <bool>("profile_background_tile"); ProfileBannerUrl = user.GetValue <string>("profile_banner_url"); StatusesCount = user.GetValue <int>("statuses_count"); Notifications = user.GetValue <bool>("notifications"); GeoEnabled = user.GetValue <bool>("geo_enabled"); Verified = user.GetValue <bool>("verified"); ContributorsEnabled = user.GetValue <bool>("contributors_enabled"); Following = user.GetValue <bool>("following"); ShowAllInlineMedia = user.GetValue <bool>("show_all_inline_media"); ListedCount = user.GetValue <int>("listed_count"); FollowRequestSent = user.GetValue <bool>("follow_request_sent"); Status = new Status(user.GetValue <JsonData>("status")); CursorMovement = new Cursors(user); }
/// <summary> /// Translate XML to IDList /// </summary> /// <param name="idList">XML with IDs and cursor info</param> /// <returns>New IDList instance</returns> public static IDList CreateIDList(XElement idList) { return(new IDList { CursorMovement = Cursors.CreateCursors(idList), IDs = (from id in idList.Element("ids").Elements("id") select id.Value) .ToList() }); }
public User(JsonElement user) { if (user.IsNull()) { return; } BannerSizes = new List <BannerSize>(); Categories = new List <Category>(); UserIDResponse = user.GetUlong("id").ToString(CultureInfo.InvariantCulture); ScreenNameResponse = user.GetString("screen_name"); Name = user.GetString("name"); Location = user.GetString("location"); Description = user.GetString("description"); ProfileImageUrl = user.GetString("profile_image_url"); ProfileImageUrlHttps = user.GetString("profile_image_url_https"); Url = user.GetString("url"); user.TryGetProperty("entities", out JsonElement entitiesValue); Entities = new UserEntities(entitiesValue); Protected = user.GetBool("protected"); ProfileUseBackgroundImage = user.GetBool("profile_use_background_image"); IsTranslator = user.GetBool("is_translator"); FollowersCount = user.GetInt("followers_count"); DefaultProfile = user.GetBool("default_profile"); ProfileBackgroundColor = user.GetString("profile_background_color"); LangResponse = user.GetString("lang"); ProfileTextColor = user.GetString("profile_text_color"); ProfileLinkColor = user.GetString("profile_link_color"); ProfileSidebarFillColor = user.GetString("profile_sidebar_fill_color"); ProfileSidebarBorderColor = user.GetString("profile_sidebar_border_color"); FriendsCount = user.GetInt("friends_count"); DefaultProfileImage = user.GetBool("default_profile_image"); CreatedAt = (user.GetString("created_at") ?? string.Empty).GetDate(DateTime.MinValue); FavoritesCount = user.GetInt("favourites_count"); UtcOffset = user.GetInt("utc_offset"); TimeZone = user.GetString("time_zone"); ProfileBackgroundImageUrl = user.GetString("profile_background_image_url"); ProfileBackgroundImageUrlHttps = user.GetString("profile_background_image_url_https"); ProfileBackgroundTile = user.GetBool("profile_background_tile"); ProfileBannerUrl = user.GetString("profile_banner_url"); StatusesCount = user.GetInt("statuses_count"); Notifications = user.GetBool("notifications"); GeoEnabled = user.GetBool("geo_enabled"); Verified = user.GetBool("verified"); ContributorsEnabled = user.GetBool("contributors_enabled"); Following = user.GetBool("following"); ShowAllInlineMedia = user.GetBool("show_all_inline_media"); ListedCount = user.GetInt("listed_count"); FollowRequestSent = user.GetBool("follow_request_sent"); user.TryGetProperty("status", out JsonElement statusElement); Status = new Status(statusElement); CursorMovement = new Cursors(user); Email = user.GetString("email"); }
public User(JsonData user) { if (user == null) return; var userID = user.GetValue<int>("id").ToString(CultureInfo.InvariantCulture); Identifier = new UserIdentifier { ID = userID, UserID = userID, ScreenName = user.GetValue<string>("screen_name") }; Name = user.GetValue<string>("name"); Location = user.GetValue<string>("location"); Description = user.GetValue<string>("description"); ProfileImageUrl = user.GetValue<string>("profile_image_url"); ProfileImageUrlHttps = user.GetValue<string>("profile_image_url_https"); Url = user.GetValue<string>("url"); Protected = user.GetValue<bool>("protected"); ProfileUseBackgroundImage = user.GetValue<bool>("profile_use_background_image"); IsTranslator = user.GetValue<bool>("is_translator"); FollowersCount = user.GetValue<int>("followers_count"); DefaultProfile = user.GetValue<bool>("default_profile"); ProfileBackgroundColor = user.GetValue<string>("profile_background_color"); LangResponse = user.GetValue<string>("lang"); ProfileTextColor = user.GetValue<string>("profile_text_color"); ProfileLinkColor = user.GetValue<string>("profile_link_color"); ProfileSidebarFillColor = user.GetValue<string>("profile_sidebar_fill_color"); ProfileSidebarBorderColor = user.GetValue<string>("profile_sidebar_border_color"); FriendsCount = user.GetValue<int>("friends_count"); DefaultProfileImage = user.GetValue<bool>("default_profile_image"); CreatedAt = user.GetValue<string>("created_at").GetDate(DateTime.MinValue); FavoritesCount = user.GetValue<int>("favourites_count"); UtcOffset = user.GetValue<int>("utc_offset"); TimeZone = user.GetValue<string>("time_zone"); ProfileBackgroundImageUrl = user.GetValue<string>("profile_background_image_url"); ProfileBackgroundImageUrlHttps = user.GetValue<string>("profile_background_image_url_https"); ProfileBackgroundTile = user.GetValue<bool>("profile_background_tile"); ProfileBannerUrl = user.GetValue<string>("profile_banner_url"); StatusesCount = user.GetValue<int>("statuses_count"); Notifications = user.GetValue<bool>("notifications"); GeoEnabled = user.GetValue<bool>("geo_enabled"); Verified = user.GetValue<bool>("verified"); ContributorsEnabled = user.GetValue<bool>("contributors_enabled"); Following = user.GetValue<bool>("following"); ShowAllInlineMedia = user.GetValue<bool>("show_all_inline_media"); ListedCount = user.GetValue<int>("listed_count"); FollowRequestSent = user.GetValue<bool>("follow_request_sent"); Status = new Status(user.GetValue<JsonData>("status")); CursorMovement = new Cursors(user); }
public IDList(JsonData idJson) { if (idJson == null) { return; } CursorMovement = new Cursors(idJson); var ids = idJson.GetValue <JsonData>("ids"); IDs = (from JsonData id in ids select(ulong) id) .ToList(); }
public static List CreateList(XElement list, XElement cursorNode) { return(new List { ListID = list.Element("id").Value, Name = list.Element("name").Value, FullName = list.Element("full_name").Value, Slug = list.Element("slug").Value, Description = list.Element("description").Value, SubscriberCount = int.Parse(list.Element("subscriber_count").Value), MemberCount = int.Parse(list.Element("member_count").Value), Uri = list.Element("uri").Value, Mode = list.Element("mode").Value, Users = new List <User> { User.CreateUser(list.Element("user")) }, CursorMovement = Cursors.CreateCursors(cursorNode) }); }
/// <summary> /// Transforms Twitter response into List. /// </summary> /// <param name="responseJson">Json Twitter response</param> /// <returns>List of List</returns> public virtual List <T> ProcessResults(string responseJson) { if (string.IsNullOrWhiteSpace(responseJson)) { return(new List <T>()); } JsonData listJson = JsonMapper.ToObject(responseJson); List <List> lists; switch (Type) { case ListType.List: case ListType.Memberships: case ListType.Subscriptions: case ListType.Ownerships: lists = HandleMultipleListsResponse(listJson); break; case ListType.Show: lists = HandleSingleListResponse(listJson); break; case ListType.Statuses: lists = HandleStatusesResponse(listJson); break; case ListType.Members: case ListType.Subscribers: lists = HandleMultipleUsersResponse(listJson); break; case ListType.IsMember: case ListType.IsSubscriber: lists = HandleSingleUserResponse(listJson); break; default: lists = new List <List>(); break; } var cursors = new Cursors(listJson); foreach (var list in lists) { list.Type = Type; list.Cursor = Cursor; list.UserID = UserID; list.ListID = ListID; list.Slug = Slug; list.OwnerID = OwnerID; list.OwnerScreenName = OwnerScreenName; list.MaxID = MaxID; list.Count = Count; list.Page = Page; list.ScreenName = ScreenName; list.SinceID = SinceID; list.TrimUser = TrimUser; list.IncludeEntities = IncludeEntities; list.IncludeRetweets = IncludeRetweets; list.FilterToOwnedLists = FilterToOwnedLists; list.CursorMovement = cursors; list.SkipStatus = SkipStatus; list.Reverse = Reverse; } return(lists.AsEnumerable().OfType <T>().ToList()); }
/// <summary> /// creates a new user based on an XML user fragment /// </summary> /// <param name="user">XML user fragment</param> /// <returns>new User instance</returns> public static User CreateUser(XElement user) { if (user == null) { return(null); } var tempUserProtected = false; var tempFollowersCount = 0ul; var tempFriendsCount = 0ul; var tempFavoritesCount = 0ul; var tempStatusesCount = 0ul; var tempFollowingUsers = false; var tempShowInlineMedia = false; var tempListedCount = 0; var tempFollowRequestSent = false; var canParseProtected = user.Element("protected") == null ? false : bool.TryParse(user.Element("protected").Value, out tempUserProtected); var followersCount = user.Element("followers_count") == null ? false : ulong.TryParse(user.Element("followers_count").Value, out tempFollowersCount); var friendsCount = user.Element("friends_count") == null ? false : ulong.TryParse(user.Element("friends_count").Value, out tempFriendsCount); var userDate = user.Element("created_at").Value; var userCreatedAtDate = String.IsNullOrEmpty(userDate) ? DateTime.MinValue : DateTime.ParseExact( userDate, "ddd MMM dd HH:mm:ss %zzzz yyyy", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal); var favoritesCount = user.Element("favourites_count") == null ? false : ulong.TryParse(user.Element("favourites_count").Value, out tempFavoritesCount); var statusesCount = user.Element("statuses_count") == null ? false : ulong.TryParse(user.Element("statuses_count").Value, out tempStatusesCount); var notifications = user.Element("notifications") == null || string.IsNullOrEmpty(user.Element("notifications").Value) ? false : bool.Parse(user.Element("notifications").Value); var geoEnabled = user.Element("geo_enabled") == null || string.IsNullOrEmpty(user.Element("geo_enabled").Value) ? false : bool.Parse(user.Element("geo_enabled").Value); var verified = user.Element("verified") == null || string.IsNullOrEmpty(user.Element("verified").Value) ? false : bool.Parse(user.Element("verified").Value); var contributorsEnabled = user.Element("contributors_enabled") == null || string.IsNullOrEmpty(user.Element("contributors_enabled").Value) ? false : bool.Parse(user.Element("contributors_enabled").Value); var isFollowing = user.Element("following") == null || string.IsNullOrEmpty(user.Element("following").Value) ? false : bool.TryParse(user.Element("following").Value, out tempFollowingUsers); var showInlineMedia = user.Element("show_all_inline_media") == null ? false : bool.TryParse(user.Element("show_all_inline_media").Value, out tempShowInlineMedia); var listedCount = user.Element("listed_count") == null ? false : int.TryParse(user.Element("listed_count").Value, out tempListedCount); var followRequestSent = user.Element("follow_request_sent") == null ? false : bool.TryParse(user.Element("follow_request_sent").Value, out tempFollowRequestSent); var status = user.Element("status"); var newUser = new User { Identifier = new UserIdentifier { ID = user.Element("id") == null ? "0" : user.Element("id").Value, UserID = user.Element("id") == null ? "0" : user.Element("id").Value, ScreenName = user.Element("screen_name") == null ? "" : user.Element("screen_name").Value }, Name = user.Element("name") == null ? "" : user.Element("name").Value, Location = user.Element("location") == null ? "" : user.Element("location").Value, Description = user.Element("description") == null ? "" : user.Element("description").Value, ProfileImageUrl = user.Element("profile_image_url") == null ? "" : user.Element("profile_image_url").Value, URL = user.Element("url") == null ? "" : user.Element("url").Value, Protected = tempUserProtected, FollowersCount = tempFollowersCount, ProfileBackgroundColor = user.Element("profile_background_color") == null ? string.Empty : user.Element("profile_background_color").Value, ProfileTextColor = user.Element("profile_text_color") == null ? string.Empty : user.Element("profile_text_color").Value, ProfileLinkColor = user.Element("profile_link_color") == null ? string.Empty : user.Element("profile_link_color").Value, ProfileSidebarFillColor = user.Element("profile_sidebar_fill_color") == null ? string.Empty : user.Element("profile_sidebar_fill_color").Value, ProfileSidebarBorderColor = user.Element("profile_sidebar_border_color") == null ? string.Empty : user.Element("profile_sidebar_border_color").Value, FriendsCount = tempFriendsCount, CreatedAt = userCreatedAtDate, FavoritesCount = tempFavoritesCount, UtcOffset = user.Element("utc_offset") == null ? string.Empty : user.Element("utc_offset").Value, TimeZone = user.Element("time_zone") == null ? string.Empty : user.Element("time_zone").Value, ProfileBackgroundImageUrl = user.Element("profile_background_image_url") == null ? string.Empty : user.Element("profile_background_image_url").Value, ProfileBackgroundTile = user.Element("profile_background_tile") == null ? string.Empty : user.Element("profile_background_tile").Value, StatusesCount = tempStatusesCount, Notifications = notifications, GeoEnabled = geoEnabled, Verified = verified, ContributorsEnabled = contributorsEnabled, Following = tempFollowingUsers, ShowAllInlineMedia = tempShowInlineMedia, ListedCount = tempListedCount, FollowRequestSent = tempFollowRequestSent, Status = Status.CreateStatus(status), CursorMovement = Cursors.CreateCursors(GrandParentOrNull(user)) }; return(newUser); }
/// <summary> /// transforms XML into IList of List /// </summary> /// <param name="responseXml">xml with Twitter response</param> /// <returns>IList of List</returns> public virtual List <T> ProcessResults(string responseXml) { XElement twitterResponse = XElement.Parse(responseXml); List <List> lists = new List <List>(); if (twitterResponse.Name == "lists_list" || twitterResponse.Name == "lists") { IEnumerable <XElement> listElements = twitterResponse.Name == "lists_list" ? twitterResponse.Element("lists").Elements("list") : twitterResponse.Elements("list"); lists = (from list in listElements select List.CreateList(list, twitterResponse)) .ToList(); } else if (twitterResponse.Name == "list") { lists.Add( List.CreateList(twitterResponse, twitterResponse) ); } else if (twitterResponse.Name == "users_list") { lists.Add( new List { Users = (from user in twitterResponse.Element("users").Elements("user") select User.CreateUser(user)) .ToList(), CursorMovement = Cursors.CreateCursors(twitterResponse) }); } else if (twitterResponse.Name == "user") { lists.Add( new List { Users = new List <User> { User.CreateUser(twitterResponse) } }); } else if (twitterResponse.Name == "statuses") { lists.Add( new List { Statuses = (from status in twitterResponse.Elements("status") select Status.CreateStatus(status)) .ToList(), CursorMovement = Cursors.CreateCursors(twitterResponse) }); } lists.ForEach(list => { list.Type = Type; list.Cursor = Cursor; list.ID = ID; if (String.IsNullOrEmpty(list.ListID) && !String.IsNullOrEmpty(ListID)) { list.ListID = ListID; } list.PerPage = PerPage; list.Page = Page; list.ScreenName = ScreenName; list.SinceID = SinceID; }); return(lists.AsEnumerable().OfType <T>().ToList()); }