Get() public static method

public static Get ( Enum Enumerator ) : string
Enumerator System.Enum
return string
Ejemplo n.º 1
0
        // * Create user
        // Implements http://www.23developer.com/api/user-create
        /// <summary>Create a user specified by an e-mail address, username, password, full name, timezone and site admin rigts specification</summary>
        public int?Create(string email, string username = null, string password = null, string fullName = null, Timezone timezone = Timezone.CET, bool siteAdmin = false)
        {
            // Verify required parameters
            if (String.IsNullOrEmpty(email))
            {
                return(null);
            }

            // Build request URL
            List <string> requestUrlParameters = new List <string>();

            requestUrlParameters.Add("email=" + HttpUtility.UrlEncode(email));
            if (!String.IsNullOrEmpty(username))
            {
                requestUrlParameters.Add("username="******"password="******"full_name=" + HttpUtility.UrlEncode(fullName));
            }
            requestUrlParameters.Add("timezone=" + HttpUtility.UrlEncode(RequestValues.Get(timezone)));
            if (siteAdmin)
            {
                requestUrlParameters.Add("site_admin=1");
            }

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

            XPathNavigator responseMessage = _provider.DoRequest(requestMessage);

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

            // Get the User id
            XPathNodeIterator users = responseMessage.Select("/response/user_id");

            if ((users.MoveNext()) && (users.Current != null))
            {
                return(Helpers.ConvertStringToInteger(users.Current.Value));
            }

            // If nothing pops up, we'll return null
            return(null);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        /// <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);
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
        /// <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);
        }
Ejemplo n.º 6
0
        public bool?Update(int userId, string email = null, string username = null, string password = null, string fullName = null, Timezone?timezone = null, bool siteAdmin = false)
        {
            // Verify required parameters
            if (userId <= 0)
            {
                return(null);
            }

            // Build request URL
            List <string> requestUrlParameters = new List <string>();

            requestUrlParameters.Add("user_id=" + userId.ToString());
            if (!String.IsNullOrEmpty(username))
            {
                requestUrlParameters.Add("username="******"password="******"full_name=" + HttpUtility.UrlEncode(fullName));
            }
            if (timezone != null)
            {
                requestUrlParameters.Add("timezone=" + HttpUtility.UrlEncode(RequestValues.Get(timezone)));
            }
            if (siteAdmin)
            {
                requestUrlParameters.Add("site_admin=1");
            }

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

            XPathNavigator responseMessage = _provider.DoRequest(requestMessage);

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

            // Get the User id
            XPathNodeIterator response = responseMessage.Select("/response");

            if ((response.MoveNext()) && (response.Current != null))
            {
                string status = response.Current.GetAttribute("status", "");
                if (status.Equals("ok", StringComparison.InvariantCultureIgnoreCase))
                {
                    return(true);
                }
                else
                {
                    string key     = response.Current.GetAttribute("code", "");
                    string message = response.Current.GetAttribute("message", "");
                    switch (key)
                    {
                    case "permission_denied":
                        throw new PermissionDenied(message);

                    case "no_such_user":
                    case "invalid_username":
                        throw new MalformedRequest(message);

                    default:
                        throw new FailedRequest(message);
                    }
                }
            }

            // If nothing pops up, we'll return null
            return(null);
        }
Ejemplo n.º 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);
        }