public Domain.Session GetToken(string returnUrl = "/", string email = null, string fullname = null)
        {
            // Build request URL
            List <string> requestUrlParameters = new List <string>();

            requestUrlParameters.Add("return_url=" + HttpUtility.UrlEncode(returnUrl));
            if (email != null)
            {
                requestUrlParameters.Add("email=" + HttpUtility.UrlEncode(email));
            }
            if (fullname != null)
            {
                requestUrlParameters.Add("full_name=" + HttpUtility.UrlEncode(fullname));
            }

            // Do the request
            MessageReceivingEndpoint requestMessage = new MessageReceivingEndpoint(_provider.GetRequestUrl("/api/session/get-token", requestUrlParameters), HttpDeliveryMethods.GetRequest);

            XPathNavigator responseMessage = _provider.DoRequest(requestMessage);

            if (responseMessage == null)
            {
                return(null);
            }

            // Create result
            Domain.Session result = new Domain.Session();

            // Get the access token
            XPathNodeIterator accessTokenNode = responseMessage.Select("/response/access_token");

            if ((!accessTokenNode.MoveNext()) || (accessTokenNode.Current == null))
            {
                return(null);
            }

            result.AccessToken = accessTokenNode.Current.Value;

            // Get the local return URL
            XPathNodeIterator returnUrlNode = responseMessage.Select("/response/return_url");

            if ((!returnUrlNode.MoveNext()) || (returnUrlNode.Current == null))
            {
                return(null);
            }

            string localReturnUrl = returnUrlNode.Current.Value;

            // Build the return URL
            List <string> returnUrlParameters = new List <string>();

            returnUrlParameters.Add("session_token=" + result.AccessToken);

            result.ReturnURL = _provider.GetRequestUrl("/api/session/redeem-token", returnUrlParameters);

            // Return the object
            return(result);
        }
        /// <summary>
        /// Get a list of players defined by the default request parameters
        /// </summary>
        /// <returns></returns>
        public List <Domain.Player> GetList()
        {
            // Build request URL
            List <string> requestUrlParameters = new List <string>();

            // Do the request
            MessageReceivingEndpoint requestMessage = new MessageReceivingEndpoint(_provider.GetRequestUrl("/api/player/list", requestUrlParameters), HttpDeliveryMethods.GetRequest);

            XPathNavigator responseMessage = _provider.DoRequest(requestMessage);

            if (responseMessage == null)
            {
                return(null);
            }

            // List all the videos
            XPathNodeIterator    players = responseMessage.Select("/response/player");
            List <Domain.Player> result  = new List <Domain.Player>();

            while (players.MoveNext())
            {
                if (players.Current == null)
                {
                    return(null);
                }

                // Create the domain Tag
                Domain.Player playerModel = new Domain.Player
                {
                    Default = (players.Current.GetAttribute("default_p", "") == "1"),
                    Name    = players.Current.GetAttribute("player_name", ""),
                    Id      = players.Current.GetAttribute("player_id", "")
                };

                result.Add(playerModel);
            }

            return(result);
        }
Example #3
0
        /// <summary>
        /// Returns a list of photos by specific parameters
        /// </summary>
        public List <Domain.Photo> GetList(PhotoListParameters requestParameters)
        {
            // Build request URL
            List <string> requestUrlParameters = new List <string>();

            if (requestParameters.AlbumId != null)
            {
                requestUrlParameters.Add("album_id=" + requestParameters.AlbumId);
            }
            if (requestParameters.PhotoId != null)
            {
                requestUrlParameters.Add("photo_id=" + requestParameters.PhotoId);
            }
            if (requestParameters.UserId != null)
            {
                requestUrlParameters.Add("user_id=" + requestParameters.UserId);
            }
            if (requestParameters.PlayerId != null)
            {
                requestUrlParameters.Add("player_id=" + requestParameters.PlayerId);
            }

            if (requestParameters.Token != null)
            {
                requestUrlParameters.Add("token=" + HttpUtility.UrlEncode(requestParameters.Token));
            }
            if (requestParameters.Search != null)
            {
                requestUrlParameters.Add("search=" + HttpUtility.UrlEncode(requestParameters.Search));
            }

            if (requestParameters.Year != null)
            {
                requestUrlParameters.Add("year=" + requestParameters.Year);
            }
            if (requestParameters.Month != null)
            {
                requestUrlParameters.Add("month=" + requestParameters.Month);
            }
            if (requestParameters.Day != null)
            {
                requestUrlParameters.Add("day=" + requestParameters.Day);
            }

            if (requestParameters.Video != null)
            {
                requestUrlParameters.Add("video_p=" + (requestParameters.Video.Value ? "1" : "0"));
            }
            if (requestParameters.Audio != null)
            {
                requestUrlParameters.Add("audio_p=" + (requestParameters.Audio.Value ? "1" : "0"));
            }
            if (requestParameters.VideoEncoded != null)
            {
                requestUrlParameters.Add("video_encoded_p=" + (requestParameters.VideoEncoded.Value ? "1" : "0"));
            }

            requestUrlParameters.Add("prioritize_promoted_p=" + (requestParameters.PrioritizePromoted ? "1": "0"));

            requestUrlParameters.Add("include_unpublished_p=" + (requestParameters.IncludeUnpublished ? "1" : "0"));

            if (requestParameters.Tags.Count > 0)
            {
                string tagString = "";

                foreach (string tag in requestParameters.Tags)
                {
                    tagString += (String.IsNullOrEmpty(tagString) ? "" : " ") + (((tag.Contains(" ")) && (tag[0] != '"')) ? "\"" + tag + "\"" : tag);
                }

                requestUrlParameters.Add("tags=" + HttpUtility.UrlEncode(tagString));
            }
            if (requestParameters.TagMode != PhotoTagMode.And)
            {
                requestUrlParameters.Add("tag_mode=" + RequestValues.Get(requestParameters.TagMode));
            }

            if (requestParameters.OrderBy != PhotoListSort.Published)
            {
                requestUrlParameters.Add("orderby=" + RequestValues.Get(requestParameters.OrderBy));
            }
            if (requestParameters.Order != GenericSort.Descending)
            {
                requestUrlParameters.Add("order=" + RequestValues.Get(requestParameters.Order));
            }

            if (requestParameters.PageOffset != null)
            {
                requestUrlParameters.Add("p=" + requestParameters.PageOffset);
            }
            if (requestParameters.Size != null)
            {
                requestUrlParameters.Add("size=" + requestParameters.Size);
            }

            // Do the request
            MessageReceivingEndpoint requestMessage = new MessageReceivingEndpoint(_provider.GetRequestUrl("/api/photo/list", requestUrlParameters), HttpDeliveryMethods.GetRequest);

            XPathNavigator responseMessage = _provider.DoRequest(requestMessage);

            if (responseMessage == null)
            {
                return(null);
            }

            // List all the videos
            XPathNodeIterator   photos = responseMessage.Select("/response/photo");
            List <Domain.Photo> result = new List <Domain.Photo>();

            while (photos.MoveNext())
            {
                // Create the domain Photo
                Domain.Photo photoModel = new Domain.Photo
                {
                    PhotoId = Helpers.ConvertStringToInteger(photos.Current.GetAttribute("photo_id", "")),

                    Title = photos.Current.GetAttribute("title", ""),
                    Token = photos.Current.GetAttribute("token", ""),
                    One   = photos.Current.GetAttribute("one", ""),

                    AlbumId    = Helpers.ConvertStringToInteger(photos.Current.GetAttribute("album_id", "")),
                    AlbumTitle = photos.Current.GetAttribute("album_title", ""),

                    Published = (photos.Current.GetAttribute("published_p", "") == "1"),
                    Promoted  = (photos.Current.GetAttribute("promoted_p", "") == "1"),

                    CreationDateANSI = photos.Current.GetAttribute("creation_date_ansi", ""),
                    CreationDateDate = photos.Current.GetAttribute("creation_date__date", ""),
                    CreationDateTime = photos.Current.GetAttribute("creation_date__time", ""),

                    OriginalDateANSI = photos.Current.GetAttribute("original_date_ansi", ""),
                    OriginalDateDate = photos.Current.GetAttribute("original_date__date", ""),
                    OriginalDateTime = photos.Current.GetAttribute("original_date__time", ""),

                    ViewCount        = Helpers.ConvertStringToInteger(photos.Current.GetAttribute("view_count", "")),
                    NumberOfComments = Helpers.ConvertStringToInteger(photos.Current.GetAttribute("number_of_comments", "")),
                    NumberOfAlbums   = Helpers.ConvertStringToInteger(photos.Current.GetAttribute("number_of_albums", "")),
                    NumberOfTags     = Helpers.ConvertStringToInteger(photos.Current.GetAttribute("number_of_tags", "")),
                    NumberOfRatings  = Helpers.ConvertStringToInteger(photos.Current.GetAttribute("number_of_ratings", "")),

                    PhotoRating = Helpers.ConvertStringToDouble(photos.Current.GetAttribute("photo_rating", "")),

                    IsVideo      = (photos.Current.GetAttribute("video_p", "") == "1"),
                    IsAudio      = (photos.Current.GetAttribute("audio_p", "") == "1"),
                    VideoEncoded = (photos.Current.GetAttribute("video_encoded_p", "") == "1"),
                    TextOnly     = (photos.Current.GetAttribute("text_only_p", "") == "1"),

                    VideoLength = Helpers.ConvertStringToDouble(photos.Current.GetAttribute("video_length", "")),

                    UserId      = Helpers.ConvertStringToInteger(photos.Current.GetAttribute("user_id", "")),
                    Username    = photos.Current.GetAttribute("username", ""),
                    DisplayName = photos.Current.GetAttribute("display_name", ""),
                    UserURL     = photos.Current.GetAttribute("user_url", ""),

                    Original = new Domain.PhotoBlock(
                        photos.Current.GetAttribute("original_width", ""),
                        photos.Current.GetAttribute("original_height", ""),
                        photos.Current.GetAttribute("original_size", ""),
                        photos.Current.GetAttribute("original_download", "")
                        ),

                    Quad16 = new Domain.PhotoBlock(
                        "16",
                        "16",
                        "0",
                        photos.Current.GetAttribute("quad16_download", "")
                        ),
                    Quad50 = new Domain.PhotoBlock(
                        photos.Current.GetAttribute("quad50_width", ""),
                        photos.Current.GetAttribute("quad50_height", ""),
                        photos.Current.GetAttribute("quad50_size", ""),
                        photos.Current.GetAttribute("quad50_download", "")
                        ),
                    Quad75 = new Domain.PhotoBlock(
                        photos.Current.GetAttribute("quad75_width", ""),
                        photos.Current.GetAttribute("quad75_height", ""),
                        photos.Current.GetAttribute("quad75_size", ""),
                        photos.Current.GetAttribute("quad75_download", "")
                        ),
                    Quad100 = new Domain.PhotoBlock(
                        photos.Current.GetAttribute("quad100_width", ""),
                        photos.Current.GetAttribute("quad100_height", ""),
                        photos.Current.GetAttribute("quad100_size", ""),
                        photos.Current.GetAttribute("quad100_download", "")
                        ),

                    Small = new Domain.PhotoBlock(
                        photos.Current.GetAttribute("small_width", ""),
                        photos.Current.GetAttribute("small_height", ""),
                        photos.Current.GetAttribute("small_size", ""),
                        photos.Current.GetAttribute("small_download", "")
                        ),
                    Medium = new Domain.PhotoBlock(
                        photos.Current.GetAttribute("medium_width", ""),
                        photos.Current.GetAttribute("medium_height", ""),
                        photos.Current.GetAttribute("medium_size", ""),
                        photos.Current.GetAttribute("medium_download", "")
                        ),
                    Portrait = new Domain.PhotoBlock(
                        photos.Current.GetAttribute("portrait_width", ""),
                        photos.Current.GetAttribute("portrait_height", ""),
                        photos.Current.GetAttribute("portrait_size", ""),
                        photos.Current.GetAttribute("portrait_download", "")
                        ),
                    Standard = new Domain.PhotoBlock(
                        photos.Current.GetAttribute("standard_width", ""),
                        photos.Current.GetAttribute("standard_height", ""),
                        photos.Current.GetAttribute("standard_size", ""),
                        photos.Current.GetAttribute("standard_download", "")
                        ),
                    Large = new Domain.PhotoBlock(
                        photos.Current.GetAttribute("large_width", ""),
                        photos.Current.GetAttribute("large_height", ""),
                        photos.Current.GetAttribute("large_size", ""),
                        photos.Current.GetAttribute("large_download", "")
                        ),

                    VideoSmall = new Domain.PhotoBlock(
                        photos.Current.GetAttribute("video_small_width", ""),
                        photos.Current.GetAttribute("video_small_height", ""),
                        photos.Current.GetAttribute("video_small_size", ""),
                        photos.Current.GetAttribute("video_small_download", "")
                        ),
                    VideoMedium = new Domain.PhotoBlock(
                        photos.Current.GetAttribute("video_medium_width", ""),
                        photos.Current.GetAttribute("video_medium_height", ""),
                        photos.Current.GetAttribute("video_medium_size", ""),
                        photos.Current.GetAttribute("video_medium_download", "")
                        ),
                    VideoHD = new Domain.PhotoBlock(
                        photos.Current.GetAttribute("video_hd_width", ""),
                        photos.Current.GetAttribute("video_hd_height", ""),
                        photos.Current.GetAttribute("video_hd_size", ""),
                        photos.Current.GetAttribute("video_hd_download", "")
                        ),
                    Video1080p = new Domain.PhotoBlock(
                        photos.Current.GetAttribute("video_1080p_width", ""),
                        photos.Current.GetAttribute("video_1080p_height", ""),
                        photos.Current.GetAttribute("video_1080p_size", ""),
                        photos.Current.GetAttribute("video_1080p_download", "")
                        ),
                    VideoMobileH263AMR = new Domain.PhotoBlock(
                        photos.Current.GetAttribute("video_mobile_h263_amr_width", ""),
                        photos.Current.GetAttribute("video_mobile_h263_amr_height", ""),
                        photos.Current.GetAttribute("video_mobile_h263_amr_size", ""),
                        photos.Current.GetAttribute("video_mobile_h263_amr_download", "")
                        ),
                    VideoMobileH263AAC = new Domain.PhotoBlock(
                        photos.Current.GetAttribute("video_mobile_h263_aac_width", ""),
                        photos.Current.GetAttribute("video_mobile_h263_aac_height", ""),
                        photos.Current.GetAttribute("video_mobile_h263_aac_size", ""),
                        photos.Current.GetAttribute("video_mobile_h263_aac_download", "")
                        ),
                    VideoMobileMPEGE4AMR = new Domain.PhotoBlock(
                        photos.Current.GetAttribute("video_mobile_mpeg4_amr_width", ""),
                        photos.Current.GetAttribute("video_mobile_mpeg4_amr_height", ""),
                        photos.Current.GetAttribute("video_mobile_mpeg4_amr_size", ""),
                        photos.Current.GetAttribute("video_mobile_mpeg4_amr_download", "")
                        ),

                    Audio = new Domain.PhotoBlock(
                        photos.Current.GetAttribute("audio_width", ""),
                        photos.Current.GetAttribute("audio_height", ""),
                        photos.Current.GetAttribute("audio_size", ""),
                        photos.Current.GetAttribute("audio_download", "")
                        ),

                    Content     = Helpers.GetNodeChildValue(photos.Current, "content"),
                    ContentText = Helpers.GetNodeChildValue(photos.Current, "content_text"),

                    BeforeDownloadType = Helpers.GetNodeChildValue(photos.Current, "before_download_type"),
                    BeforeDownloadURL  = Helpers.GetNodeChildValue(photos.Current, "before_download_url"),
                    AfterDownloadType  = Helpers.GetNodeChildValue(photos.Current, "after_download_type"),
                    AfterDownloadURL   = Helpers.GetNodeChildValue(photos.Current, "after_download_url"),

                    AfterText   = Helpers.GetNodeChildValue(photos.Current, "after_text"),
                    AbsoluteUrl = photos.Current.GetAttribute("absolute_url", ""),

                    Tags      = new List <string>(Helpers.GetNodeChildValue(photos.Current, "tags").Split(',')),
                    Variables = new Dictionary <string, string>()
                };

                // Read out custom variables.
                XPathNavigator variableNavigator = photos.Current.Clone();
                if (variableNavigator.MoveToFirstAttribute())
                {
                    if (!_defaultAttributes.Contains(variableNavigator.Name))
                    {
                        photoModel.Variables.Add(variableNavigator.Name,
                                                 variableNavigator.Value);
                    }

                    while (variableNavigator.MoveToNextAttribute())
                    {
                        if (!_defaultAttributes.Contains(variableNavigator.Name))
                        {
                            photoModel.Variables.Add(variableNavigator.Name,
                                                     variableNavigator.Value);
                        }
                    }
                }

                result.Add(photoModel);
            }

            return(result);
        }
        /// <summary>
        /// Returns a list of comments by specific parameters
        /// </summary>
        public List <Domain.Comment> GetList(CommentListParameters requestParameters)
        {
            // Build request URL
            List <string> requestUrlParameters = new List <string>();

            if (requestParameters.ObjectId != null)
            {
                requestUrlParameters.Add("object_id=" + requestParameters.ObjectId);
            }
            if (requestParameters.ObjectType != CommentObjectType.Empty)
            {
                requestUrlParameters.Add("order=" + RequestValues.Get(requestParameters.ObjectType));
            }

            if (requestParameters.CommentId != null)
            {
                requestUrlParameters.Add("comment_id=" + requestParameters.CommentId);
            }
            if (requestParameters.CommentUserId != null)
            {
                requestUrlParameters.Add("comment_user_id=" + requestParameters.CommentUserId);
            }

            if (requestParameters.Search != null)
            {
                requestUrlParameters.Add("search=" + HttpUtility.UrlEncode(requestParameters.Search));
            }

            if (requestParameters.Order != GenericSort.Descending)
            {
                requestUrlParameters.Add("order=" + RequestValues.Get(requestParameters.Order));
            }

            if (requestParameters.PageOffset != null)
            {
                requestUrlParameters.Add("p=" + requestParameters.PageOffset);
            }
            if (requestParameters.Size != null)
            {
                requestUrlParameters.Add("size=" + requestParameters.Size);
            }

            // Do the request
            MessageReceivingEndpoint requestMessage = new MessageReceivingEndpoint(_provider.GetRequestUrl("/api/comment/list", requestUrlParameters), HttpDeliveryMethods.GetRequest);

            XPathNavigator responseMessage = _provider.DoRequest(requestMessage);

            if (responseMessage == null)
            {
                return(null);
            }

            // List all the videos
            XPathNodeIterator     comments = responseMessage.Select("/response/comment");
            List <Domain.Comment> result   = new List <Domain.Comment>();

            while (comments.MoveNext())
            {
                if (comments.Current == null)
                {
                    return(null);
                }

                // Create the domain album
                Domain.Comment commentModel = new Domain.Comment();

                commentModel.CommentId = Helpers.ConvertStringToInteger(comments.Current.GetAttribute("comment_id", ""));

                commentModel.ObjectId = Helpers.ConvertStringToInteger(comments.Current.GetAttribute("object_id", ""));
                switch (comments.Current.GetAttribute("object_type", ""))
                {
                case "album":
                    commentModel.ObjectType = CommentObjectType.Album;
                    break;

                case "photo":
                    commentModel.ObjectType = CommentObjectType.Photo;
                    break;

                default:
                    commentModel.ObjectType = CommentObjectType.Empty;
                    break;
                }

                commentModel.PrettyDate = comments.Current.GetAttribute("pretty_date", "");
                commentModel.PrettyTime = comments.Current.GetAttribute("pretty_time", "");

                commentModel.ShortDate        = comments.Current.GetAttribute("short_date", "");
                commentModel.CreationDateANSI = comments.Current.GetAttribute("creation_date_ansi", "");

                commentModel.UserId        = (!String.IsNullOrEmpty(comments.Current.GetAttribute("user_id", "")) ? (int?)Helpers.ConvertStringToInteger(comments.Current.GetAttribute("user_id", "")) : null);
                commentModel.Name          = comments.Current.GetAttribute("name", "");
                commentModel.Email         = comments.Current.GetAttribute("email", "");
                commentModel.TruncatedName = comments.Current.GetAttribute("truncated_name", "");

                commentModel.Content     = Helpers.GetNodeChildValue(comments.Current, "content");
                commentModel.ContentText = Helpers.GetNodeChildValue(comments.Current, "content_text");

                result.Add(commentModel);
            }

            return(result);
        }
Example #5
0
        /// <summary>
        /// Get a list of tags defined by the request parameters
        /// </summary>
        /// <param name="requestParameters"></param>
        /// <returns></returns>
        public List <Domain.Tag> GetList(TagListParameters requestParameters)
        {
            // Build request URL
            List <string> requestUrlParameters = new List <string>();

            if (requestParameters.Search != null)
            {
                requestUrlParameters.Add("search=" + HttpUtility.UrlEncode(requestParameters.Search));
            }

            requestUrlParameters.Add("reformat_tags_p=" + (requestParameters.ReformatTags ? 1 : 0));
            requestUrlParameters.Add("exclude_machine_tags_p=" + (requestParameters.ExcludeMachineTags ? 1 : 0));

            if (requestParameters.OrderBy != TagListSort.Tag)
            {
                requestUrlParameters.Add("orderby=" + RequestValues.Get(requestParameters.OrderBy));
            }
            if (requestParameters.Order != GenericSort.Descending)
            {
                requestUrlParameters.Add("order=" + RequestValues.Get(requestParameters.Order));
            }

            if (requestParameters.PageOffset != null)
            {
                requestUrlParameters.Add("p=" + requestParameters.PageOffset);
            }
            if (requestParameters.Size != null)
            {
                requestUrlParameters.Add("size=" + requestParameters.Size);
            }

            // Do the request
            MessageReceivingEndpoint requestMessage = new MessageReceivingEndpoint(_provider.GetRequestUrl("/api/tag/list", requestUrlParameters), HttpDeliveryMethods.GetRequest);

            XPathNavigator responseMessage = _provider.DoRequest(requestMessage);

            if (responseMessage == null)
            {
                return(null);
            }

            // List all the videos
            XPathNodeIterator tags   = responseMessage.Select("/response/tag");
            List <Domain.Tag> result = new List <Domain.Tag>();

            while (tags.MoveNext())
            {
                if (tags.Current == null)
                {
                    return(null);
                }

                // Create the domain Tag
                Domain.Tag tagModel = new Domain.Tag
                {
                    Name  = tags.Current.GetAttribute("tag", ""),
                    URL   = tags.Current.GetAttribute("url", ""),
                    Count = Helpers.ConvertStringToInteger(tags.Current.GetAttribute("count", ""))
                };

                result.Add(tagModel);
            }

            return(result);
        }
        /// <summary>
        /// Returns a list of users by specific parameters
        /// </summary>
        public List <Domain.User> GetList(UserListParameters requestParameters)
        {
            // Build request URL
            List <string> requestUrlParameters = new List <string>();

            if (requestParameters.UserId != null)
            {
                requestUrlParameters.Add("user_id=" + requestParameters.UserId);
            }

            if (requestParameters.Search != null)
            {
                requestUrlParameters.Add("search=" + HttpUtility.UrlEncode(requestParameters.Search));
            }

            if (requestParameters.OrderBy != UserListSort.DisplayName)
            {
                requestUrlParameters.Add("orderby=" + RequestValues.Get(requestParameters.OrderBy));
            }
            if (requestParameters.Order != GenericSort.Descending)
            {
                requestUrlParameters.Add("order=" + RequestValues.Get(requestParameters.Order));
            }

            if (requestParameters.PageOffset != null)
            {
                requestUrlParameters.Add("p=" + requestParameters.PageOffset);
            }
            if (requestParameters.Size != null)
            {
                requestUrlParameters.Add("size=" + requestParameters.Size);
            }

            // Do the request
            MessageReceivingEndpoint requestMessage = new MessageReceivingEndpoint(_provider.GetRequestUrl("/api/user/list", requestUrlParameters), HttpDeliveryMethods.GetRequest);

            XPathNavigator responseMessage = _provider.DoRequest(requestMessage);

            if (responseMessage == null)
            {
                return(null);
            }

            // List all the videos
            XPathNodeIterator  users  = responseMessage.Select("/response/user");
            List <Domain.User> result = new List <Domain.User>();

            while (users.MoveNext())
            {
                if (users.Current == null)
                {
                    return(null);
                }

                // Create the domain User
                Domain.User userModel = new Domain.User
                {
                    UserId        = Helpers.ConvertStringToInteger(users.Current.GetAttribute("user_id", "")),
                    Username      = users.Current.GetAttribute("username", ""),
                    DisplayName   = users.Current.GetAttribute("display_name", ""),
                    URL           = users.Current.GetAttribute("url", ""),
                    FullName      = users.Current.GetAttribute("full_name", ""),
                    Email         = users.Current.GetAttribute("email", ""),
                    SiteAdmin     = (users.Current.GetAttribute("site_admin", "") != "f"),
                    AboutAbstract = Helpers.GetNodeChildValue(users.Current, "about_abstract")
                };

                result.Add(userModel);
            }

            return(result);
        }
Example #7
0
        /// <summary>
        /// Returns a list of albums by specific parameters
        /// </summary>
        public List <Domain.Album> GetList(AlbumListParameters requestParameters)
        {
            // Build request URL
            List <string> requestUrlParameters = new List <string>();

            if (requestParameters.AlbumId != null)
            {
                requestUrlParameters.Add("album_id=" + requestParameters.AlbumId);
            }
            if (requestParameters.UserId != null)
            {
                requestUrlParameters.Add("user_id=" + requestParameters.UserId);
            }
            if (requestParameters.PhotoId != null)
            {
                requestUrlParameters.Add("photo_id=" + requestParameters.PhotoId);
            }

            if (requestParameters.Search != null)
            {
                requestUrlParameters.Add("search=" + HttpUtility.UrlEncode(requestParameters.Search));
            }

            if (requestParameters.IncludeHidden)
            {
                requestUrlParameters.Add("include_hidden_p=1");
            }

            if (requestParameters.OrderBy != AlbumListSort.CreationDate)
            {
                requestUrlParameters.Add("orderby=" + RequestValues.Get(requestParameters.OrderBy));
            }
            if (requestParameters.Order != GenericSort.Descending)
            {
                requestUrlParameters.Add("order=" + RequestValues.Get(requestParameters.Order));
            }

            if (requestParameters.PageOffset != null)
            {
                requestUrlParameters.Add("p=" + requestParameters.PageOffset);
            }
            if (requestParameters.Size != null)
            {
                requestUrlParameters.Add("size=" + requestParameters.Size);
            }

            // Do the request
            MessageReceivingEndpoint requestMessage = new MessageReceivingEndpoint(_provider.GetRequestUrl("/api/album/list", requestUrlParameters), HttpDeliveryMethods.GetRequest);

            XPathNavigator responseMessage = _provider.DoRequest(requestMessage);

            if (responseMessage == null)
            {
                return(null);
            }

            // List all the videos
            XPathNodeIterator   albums = responseMessage.Select("/response/album");
            List <Domain.Album> result = new List <Domain.Album>();

            while (albums.MoveNext())
            {
                if (albums.Current == null)
                {
                    return(null);
                }

                // Create the domain album
                Domain.Album albumModel = new Domain.Album
                {
                    AlbumId = Helpers.ConvertStringToInteger(albums.Current.GetAttribute("album_id", "")),

                    Title = albums.Current.GetAttribute("title", ""),

                    PrettyDate = albums.Current.GetAttribute("pretty_date", ""),
                    PrettyTime = albums.Current.GetAttribute("pretty_time", ""),

                    One = albums.Current.GetAttribute("one", ""),
                    CreationDateANSI = albums.Current.GetAttribute("creation_date_ansi", ""),

                    UserId      = Helpers.ConvertStringToInteger(albums.Current.GetAttribute("user_id", "")),
                    UserUrl     = albums.Current.GetAttribute("user_url", ""),
                    Username    = albums.Current.GetAttribute("username", ""),
                    DisplayName = albums.Current.GetAttribute("display_name", ""),

                    Token = albums.Current.GetAttribute("token", ""),
                    Hide  = (albums.Current.GetAttribute("hide_p", "") == "1"),

                    Content     = Helpers.GetNodeChildValue(albums.Current, "content"),
                    ContentText = Helpers.GetNodeChildValue(albums.Current, "content_text")
                };

                result.Add(albumModel);
            }

            return(result);
        }
        /// <summary>
        /// Method for getting a Site object containing information about the site
        /// </summary>
        /// <returns></returns>
        public Domain.Site Get()
        {
            // Build request URL
            List <string> requestUrlParameters = new List <string>();

            // Do the request
            MessageReceivingEndpoint requestMessage = new MessageReceivingEndpoint(_provider.GetRequestUrl("/api/site/get", requestUrlParameters), HttpDeliveryMethods.GetRequest);

            XPathNavigator responseMessage = _provider.DoRequest(requestMessage);

            if (responseMessage == null)
            {
                return(null);
            }

            // Get the site id
            XPathNavigator siteIdToken = responseMessage.SelectSingleNode("/response/site_id");

            if (siteIdToken == null)
            {
                return(null);
            }

            // Get the site name
            XPathNavigator siteNameToken = responseMessage.SelectSingleNode("/response/site_name");

            if (siteNameToken == null)
            {
                return(null);
            }

            // Get the product key
            XPathNavigator productKeyToken = responseMessage.SelectSingleNode("/response/product_key");

            if (productKeyToken == null)
            {
                return(null);
            }

            // Get the allow signup variable
            XPathNavigator allowSignupToken = responseMessage.SelectSingleNode("/response/allow_signup_p");

            if (allowSignupToken == null)
            {
                return(null);
            }

            // Get the site key
            XPathNavigator siteKeyToken = responseMessage.SelectSingleNode("/response/site_key");

            if (siteKeyToken == null)
            {
                return(null);
            }

            // Get the license id
            XPathNavigator licenseIdToken = responseMessage.SelectSingleNode("/response/license_id");

            if (licenseIdToken == null)
            {
                return(null);
            }

            // Get the domain
            XPathNavigator domainToken = responseMessage.SelectSingleNode("/response/domain");

            if (domainToken == null)
            {
                return(null);
            }

            // Create result
            try
            {
                Domain.Site result = new Domain.Site
                {
                    SiteId      = Helpers.ConvertStringToInteger(siteIdToken.Value),
                    SiteName    = siteNameToken.Value,
                    SiteKey     = siteKeyToken.Value,
                    ProductKey  = productKeyToken.Value,
                    AllowSignup = (allowSignupToken.Value != "f"),
                    LicenseId   = Helpers.ConvertStringToInteger(licenseIdToken.Value),
                    Domain      = domainToken.Value
                };

                return(result);
            }
            catch
            {
                return(null);
            }
        }