Ejemplo n.º 1
0
        // * Get upload token
        // Implements http://www.23developer.com/api/photo-get-upload-token
        public Domain.PhotoUploadToken GetUploadToken(string returnUrl, bool?backgroundReturn, int?userId, int?albumId, string title, string description, string tags, bool?publish, int?validMinutes, int?maxUploads)
        {
            if (String.IsNullOrEmpty(returnUrl))
            {
                return(null);
            }

            // Build request URL
            List <MultipartPostPart> data = new List <MultipartPostPart>
            {
                MultipartPostPart.CreateFormPart("return_url", returnUrl)
            };

            if (backgroundReturn != null)
            {
                data.Add(MultipartPostPart.CreateFormPart("background_return_p", backgroundReturn.Value ? "1" : "0"));
            }

            if (userId != null)
            {
                data.Add(MultipartPostPart.CreateFormPart("user_id", userId.ToString()));
            }
            if (albumId != null)
            {
                data.Add(MultipartPostPart.CreateFormPart("album_id", albumId.ToString()));
            }
            if (title != null)
            {
                data.Add(MultipartPostPart.CreateFormPart("title", title));
            }
            if (description != null)
            {
                data.Add(MultipartPostPart.CreateFormPart("description", description));
            }
            if (tags != null)
            {
                data.Add(MultipartPostPart.CreateFormPart("tags", tags));
            }

            if (publish != null)
            {
                data.Add(MultipartPostPart.CreateFormPart("publish", publish.Value ? "1" : "0"));
            }

            if (validMinutes != null)
            {
                data.Add(MultipartPostPart.CreateFormPart("valid_minutes", validMinutes.ToString()));
            }
            if (maxUploads != null)
            {
                data.Add(MultipartPostPart.CreateFormPart("max_uploads", maxUploads.ToString()));
            }

            // Do the request
            MessageReceivingEndpoint requestMessage = new MessageReceivingEndpoint(_provider.GetRequestUrl("/api/photo/get-upload-token", null), HttpDeliveryMethods.PostRequest | HttpDeliveryMethods.AuthorizationHeaderRequest);

            XPathNavigator responseMessage = _provider.DoRequest(requestMessage, data);

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

            // Get the token
            XPathNodeIterator tokenNode = responseMessage.Select("/response");

            if (!tokenNode.MoveNext())
            {
                return(null);
            }

            Domain.PhotoUploadToken uploadToken = new Domain.PhotoUploadToken
            {
                UploadToken = Helpers.GetNodeChildValue(tokenNode.Current, "upload_token"),

                Title       = Helpers.GetNodeChildValue(tokenNode.Current, "title"),
                Description = Helpers.GetNodeChildValue(tokenNode.Current, "description"),
                Tags        = Helpers.GetNodeChildValue(tokenNode.Current, "tags"),

                Publish = (Helpers.GetNodeChildValue(tokenNode.Current, "publish") == "1"),

                UserId  = Helpers.ConvertStringToInteger(Helpers.GetNodeChildValue(tokenNode.Current, "user_id")),
                AlbumId = Helpers.ConvertStringToInteger(Helpers.GetNodeChildValue(tokenNode.Current, "album_id")),

                ValidMinutes = Helpers.ConvertStringToInteger(Helpers.GetNodeChildValue(tokenNode.Current, "valid_minutes")),
                ValidUntil   = Helpers.ConvertStringToInteger(Helpers.GetNodeChildValue(tokenNode.Current, "valid_until")),

                ReturnURL = Helpers.GetNodeChildValue(tokenNode.Current, "return_url")
            };

            // If nothing pops up, we'll return null
            return(uploadToken);
        }
Ejemplo n.º 2
0
        // * Get upload token
        // Implements http://www.23developer.com/api/photo-get-upload-token
        public Domain.PhotoUploadToken GetUploadToken(string returnUrl, bool? backgroundReturn, int? userId, int? albumId, string title, string description, string tags, bool? publish, int? validMinutes, int? maxUploads)
        {
            if (String.IsNullOrEmpty(returnUrl)) return null;

            // Build request URL
            List<MultipartPostPart> data = new List<MultipartPostPart>
            {
                MultipartPostPart.CreateFormPart("return_url", returnUrl)
            };

            if (backgroundReturn != null) data.Add(MultipartPostPart.CreateFormPart("background_return_p", backgroundReturn.Value ? "1" : "0"));

            if (userId != null) data.Add(MultipartPostPart.CreateFormPart("user_id", userId.ToString()));
            if (albumId != null) data.Add(MultipartPostPart.CreateFormPart("album_id", albumId.ToString()));
            if (title != null) data.Add(MultipartPostPart.CreateFormPart("title", title));
            if (description != null) data.Add(MultipartPostPart.CreateFormPart("description", description));
            if (tags != null) data.Add(MultipartPostPart.CreateFormPart("tags", tags));

            if (publish != null) data.Add(MultipartPostPart.CreateFormPart("publish", publish.Value ? "1" : "0"));

            if (validMinutes != null) data.Add(MultipartPostPart.CreateFormPart("valid_minutes", validMinutes.ToString()));
            if (maxUploads != null) data.Add(MultipartPostPart.CreateFormPart("max_uploads", maxUploads.ToString()));

            // Do the request
            MessageReceivingEndpoint requestMessage = new MessageReceivingEndpoint(_provider.GetRequestUrl("/api/photo/get-upload-token", null), HttpDeliveryMethods.PostRequest | HttpDeliveryMethods.AuthorizationHeaderRequest);

            XPathNavigator responseMessage = _provider.DoRequest(requestMessage, data);
            if (responseMessage == null) return null;

            // Get the token
            XPathNodeIterator tokenNode = responseMessage.Select("/response");
            if (!tokenNode.MoveNext()) return null;

            Domain.PhotoUploadToken uploadToken = new Domain.PhotoUploadToken
            {
                UploadToken = Helpers.GetNodeChildValue(tokenNode.Current, "upload_token"),

                Title = Helpers.GetNodeChildValue(tokenNode.Current, "title"),
                Description = Helpers.GetNodeChildValue(tokenNode.Current, "description"),
                Tags = Helpers.GetNodeChildValue(tokenNode.Current, "tags"),

                Publish = (Helpers.GetNodeChildValue(tokenNode.Current, "publish") == "1"),

                UserId = Helpers.ConvertStringToInteger(Helpers.GetNodeChildValue(tokenNode.Current, "user_id")),
                AlbumId = Helpers.ConvertStringToInteger(Helpers.GetNodeChildValue(tokenNode.Current, "album_id")),

                ValidMinutes = Helpers.ConvertStringToInteger(Helpers.GetNodeChildValue(tokenNode.Current, "valid_minutes")),
                ValidUntil = Helpers.ConvertStringToInteger(Helpers.GetNodeChildValue(tokenNode.Current, "valid_until")),

                ReturnURL = Helpers.GetNodeChildValue(tokenNode.Current, "return_url")
            };

            // If nothing pops up, we'll return null
            return uploadToken;
        }