Пример #1
0
        public Album GetAlbumInfo(long albumID, string albumKey)
        {
            logger.Info("Getting Album info");

            try
            {
                string result   = SmugMugRequest.ExecuteSmugMugHttpRequest("smugmug.albums.getInfo", apiKey, appSecret, this.accessToken, true, "AlbumID", albumID.ToString(), "AlbumKey", albumKey);
                var    response = JsonConvert.DeserializeObject <AlbumResponse>(result);

                if (response.stat == "ok")
                {
                    logger.InfoFormat("Retrieved Album: ", response.Album.Title);
                    return(response.Album);
                }
                else
                {
                    logger.Error("Could not retrieve Album Info");
                    logger.Error(response.code);
                    logger.Error(response.message);
                    logger.Error(response.method);
                    throw new SmugMugException(response.code, response.message, response.method);
                }
            }
            catch (Exception ex)
            {
                logger.Error("Could not retrieve Album Info", ex);
                throw new SmugMugException("Could not retrieve Album Info", ex);
            }
        }
Пример #2
0
        public bool DeleteImage(long imageID)
        {
            try
            {
                logger.InfoFormat("Deleting Image with image id: {0}", imageID);

                string result   = SmugMugRequest.ExecuteSmugMugHttpRequest("smugmug.images.delete", apiKey, appSecret, this.accessToken, true, "ImageID", imageID.ToString());
                var    response = JsonConvert.DeserializeObject <SmugMugResponse>(result);

                if (response.stat == "ok")
                {
                    logger.InfoFormat("Deleted image id:{0}", imageID);
                    return(true);
                }
                else
                {
                    logger.Error("An error occured trying to delete an Image");
                    throw new SmugMugException(response.code, response.message, response.method);
                }
            }
            catch (Exception ex)
            {
                throw new SmugMugException("An error occured trying to delete an Image: " + imageID, ex);
            }
        }
Пример #3
0
        /// <summary>
        /// Gets all the SubCategories for a given <see cref="Category"/>.
        /// </summary>
        /// <returns>An <see cref="Array"/> of <see cref="SubCategory"/>.
        /// If there are no SubCategories then it returns null.</returns>
        /// <remarks>SubCategories are cached for the existing Session.
        /// Throws an <see cref="SmugMugException"/>
        /// if an error occurs trying to retrieve the SubCategories.</remarks>
        public SubCategory[] GetSubCategories(long categoryID)
        {
            logger.Info("Getting SubCategories for category id: " + categoryID.ToString());

            try
            {
                string result   = SmugMugRequest.ExecuteSmugMugHttpRequest("smugmug.subcategories.get", this.apiKey, this.appSecret, this.accessToken, true, "CategoryID", categoryID.ToString());
                var    response = JsonConvert.DeserializeObject <SubCategoryResponse>(result);

                if (response.stat == "ok")
                {
                    logger.InfoFormat("Retrieved {0}, SubCategories", response.SubCategories.Length);
                    return(response.SubCategories);
                }
                else
                {
                    logger.Info("No SubCategories for category id: " + categoryID);
                    return(new SubCategory[0]);
                }
            }
            catch (Exception ex)
            {
                logger.Error("Could not retrieve SubCategories", ex);
                throw new SmugMugException("Could not retrieve SubCategories", ex);
            }
        }
Пример #4
0
        public bool ShareGroupsAddAlbum(int shareGroupID, long albumID)
        {
            logger.Info("Adding ShareGroups");

            try
            {
                string result   = SmugMugRequest.ExecuteSmugMugHttpRequest("smugmug.sharegroups.albums.add", apiKey, appSecret, this.accessToken, true, "AlbumID", albumID.ToString(), "ShareGroupID", shareGroupID.ToString());
                var    response = JsonConvert.DeserializeObject <SmugMugResponse>(result);

                if (response.stat == "ok")
                {
                    logger.InfoFormat("Added albumID:{0} to ShareGroup:{1}", albumID, shareGroupID);
                    return(true);
                }
                else
                {
                    logger.Error("Could not add Album to ShareGroup");
                    throw new SmugMugException(response.code, response.message, response.method);
                }
            }
            catch (Exception ex)
            {
                logger.Error("Could not add Album to ShareGroup", ex);
                throw new SmugMugException("Could not add Album to ShareGroup", ex);
            }
        }
Пример #5
0
        /// <summary>
        /// Gets all the Categories for the user.
        /// </summary>
        /// <returns>An <see cref="Array"/> of <see cref="Category"/>.</returns>
        /// <remarks>Categories are cached for the existing Session.
        /// Throws an <see cref="SmugMugException"/>
        /// if an error occurs trying to retrieve the Categories.</remarks>
        public Category[] GetCategories()
        {
            logger.Info("Getting Categories");

            if (this.categories == null)
            {
                try
                {
                    string result = SmugMugRequest.ExecuteSmugMugHttpRequest("smugmug.categories.get", this.apiKey, this.appSecret, this.accessToken, true);

                    var response = JsonConvert.DeserializeObject <CategoryResponse>(result);

                    if (response.stat == "ok")
                    {
                        logger.InfoFormat("Retrieved {0}, Categories", response.Categories.Length);
                        this.categories = response.Categories;
                    }
                    else
                    {
                        logger.Error("Could not retrieve Categories");
                        logger.Error(response.code);
                        logger.Error(response.message);
                        logger.Error(response.method);
                        throw new SmugMugException(response.code, response.message, response.method);
                    }
                }
                catch (Exception ex)
                {
                    logger.Error("Could not retrieve Categories", ex);
                    throw new SmugMugException("Could not retrieve Categories", ex);
                }
            }

            return(this.categories);
        }
Пример #6
0
        public ShareGroup[] GetShareGroups()
        {
            logger.Info("Getting ShareGroups");

            if (this.sharegroups == null)
            {
                try
                {
                    string result   = SmugMugRequest.ExecuteSmugMugHttpRequest("smugmug.sharegroups.get", apiKey, appSecret, this.accessToken, true);
                    var    response = JsonConvert.DeserializeObject <ShareGroupResponse>(result);

                    if (response.stat == "ok")
                    {
                        this.sharegroups = response.ShareGroups;
                        logger.InfoFormat("Retrieved {0}, ShareGroups", this.sharegroups.Length);
                    }
                    else
                    {
                        logger.Error("Could not retrieve ShareGroups");
                        logger.Error(response.code);
                        logger.Error(response.message);
                        logger.Error(response.method);

                        return(new ShareGroup[0]);
                    }
                }
                catch (Exception ex)
                {
                    logger.Error("Could not retrieve ShareGroups", ex);
                    return(new ShareGroup[0]);
                }
            }

            return(this.sharegroups);
        }
Пример #7
0
        public Watermark[] GetWatermarks()
        {
            logger.Info("Getting Watermarks");

            if (this.watermarks == null)
            {
                try
                {
                    string result   = SmugMugRequest.ExecuteSmugMugHttpRequest("smugmug.watermarks.get", apiKey, appSecret, this.accessToken, true);
                    var    response = JsonConvert.DeserializeObject <WatermarkResponse>(result);

                    if (response.stat == "ok")
                    {
                        this.watermarks = response.Watermarks;
                        logger.InfoFormat("Retrieved {0}, Watermarks", this.watermarks.Length);
                    }
                    else
                    {
                        logger.Error("Could not retrieve Watermarks");
                        logger.Error(response.code);
                        logger.Error(response.message);
                        logger.Error(response.method);

                        return(new Watermark[0]);
                    }
                }
                catch (Exception ex)
                {
                    logger.Error("Could not retrieve Watermarks", ex);
                    throw new SmugMugException("Could not retrieve Watermarks", ex);
                }
            }

            return(this.watermarks);
        }
Пример #8
0
        /// <summary>
        /// Check if the token is still valid.
        /// </summary>
        private Auth CheckAccessToken(ref Token accessToken)
        {
            var loginResult = SmugMugRequest.ExecuteSmugMugHttpRequest("smugmug.auth.checkAccessToken", apiKey, appSecret, accessToken, true);
            var response    = JsonConvert.DeserializeObject <GetTokenResponse>(loginResult);

            if (response.stat == "ok")
            {
                return(response.Auth);
            }

            return(null);
        }
Пример #9
0
        /// <summary>
        /// Gets all the Albums for the user.
        /// </summary>
        /// <returns>An <see cref="Array"/> of <see cref="Album"/>.
        /// <remarks>Albums are cached for the existing Session.
        /// Throws an <see cref="SmugMugException"/>
        /// if an error occurs trying to retrieve the Albums.</remarks>
        public Album[] GetAlbums(bool forceRefresh)
        {
            logger.Info("Getting Albums");

            if (this.albums == null | forceRefresh)
            {
                try
                {
                    string result   = SmugMugRequest.ExecuteSmugMugHttpRequest("smugmug.albums.get", this.apiKey, this.appSecret, this.accessToken, true);
                    var    response = JsonConvert.DeserializeObject <AlbumResponse>(result);

                    if (response.stat == "ok")
                    {
                        logger.InfoFormat("Retrieved {0}, Albums", response.Albums.Length);
                        this.albums = response.Albums;

                        // need to decode any HTML entities in the Album titles
                        for (int i = 0; i < this.albums.Length; i++)
                        {
                            this.albums[i].Title = HttpUtility.HtmlDecode(this.albums[i].Title);
                        }
                    }
                    else
                    {
                        logger.Error("Could not retrieve Albums");
                        logger.Error(response.code);
                        logger.Error(response.message);
                        logger.Error(response.method);
                        throw new SmugMugException(response.code, response.message, response.method);
                    }

                    return(this.albums);
                }
                catch (Exception ex)
                {
                    logger.Error("Could not retrieve Albums", ex);
                    throw new SmugMugException("Could not retrieve Albums", ex);
                }
            }
            else
            {
                return(this.albums);
            }
        }
Пример #10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="albumID"></param>
        /// <param name="heavy"></param>
        /// <returns></returns>
        public Image[] GetImages(long albumID, string albumKey, string extras)
        {
            try
            {
                logger.InfoFormat("Getting imageIDs with album id: {0}, album key: {1}, heavy: {2}", albumID, albumKey, extras);

                string result;

                if (String.IsNullOrEmpty(extras))
                {
                    result = SmugMugRequest.ExecuteSmugMugHttpRequest("smugmug.images.get", apiKey, appSecret, this.accessToken, true, "AlbumID", albumID.ToString(), "AlbumKey", albumKey.ToString());
                }
                else
                {
                    result = SmugMugRequest.ExecuteSmugMugHttpRequest("smugmug.images.get", apiKey, appSecret, this.accessToken, true, "AlbumID", albumID.ToString(), "AlbumKey", albumKey.ToString(), "Extras", extras);
                }

                var response = JsonConvert.DeserializeObject <ImageResponse>(result);

                if (response.stat == "ok")
                {
                    logger.InfoFormat("Retreived {0}, images", response.Album.Images.Length);
                }
                else
                {
                    logger.Error("Could not retrieve Images");
                    logger.Error(response.code);
                    logger.Error(response.message);
                    logger.Error(response.method);

                    return(new Image[0]);
                }

                return(response.Album.Images);
            }
            catch (Exception ex)
            {
                logger.Error("Could not retrieve Images", ex);
                throw new SmugMugException("Could not get images", ex);
            }
        }
Пример #11
0
        /// <summary>
        /// Get the access Token from SmugMug
        /// </summary>
        public Token GetAccessToken(Token requestToken)
        {
            logger.InfoFormat("calling smugmug.auth.getAccessToken with requestToken: {0}", requestToken.id);

            var loginResult = SmugMugRequest.ExecuteSmugMugHttpRequest("smugmug.auth.getAccessToken", apiKey, appSecret, requestToken, true);
            var response    = JsonConvert.DeserializeObject <GetTokenResponse>(loginResult);

            if (response.stat == "ok")
            {
                logger.InfoFormat("retrieved auth token", response.message);
                return(response.Auth.Token);
            }
            else
            {
                logger.Error("failed to retrieve AccessToken with error: ");
                logger.ErrorFormat("stat: {0}", response.stat);
                logger.ErrorFormat("code: {0}", response.code);
                logger.ErrorFormat("message: {0}", response.message);
            }

            return(null);
        }
Пример #12
0
        /// <summary>
        /// Get the request Token from SmugMug
        /// </summary>
        public Token GetRequestToken()
        {
            logger.InfoFormat("calling smugmug.auth.getRequestToken");
            var loginResult = SmugMugRequest.ExecuteSmugMugHttpRequest("smugmug.auth.getRequestToken", apiKey, appSecret, null, true);
            var response    = JsonConvert.DeserializeObject <GetTokenResponse>(loginResult);

            if (response.stat == "ok")
            {
                logger.InfoFormat("retrieved token: {0}", response.Auth.Token.id);
                return(response.Auth.Token);
            }
            else if (response.code == 30)
            {
                logger.Error("failed to retrieve Request Token with error: ");
                logger.ErrorFormat("stat: {0}", response.stat);
                logger.ErrorFormat("code: {0}", response.code);
                logger.ErrorFormat("message: {0}", response.message);

                throw new SmugMugException("It appears your system clock is not set. Please check your System time and Time Zone and try again");
            }

            return(null);
        }
Пример #13
0
        public bool SetAlbumHighlight(long albumID, long highlightID)
        {
            try
            {
                logger.InfoFormat("Changing Album highlight for album id: {0}, highlight id: {1}", albumID, highlightID);

                string result   = SmugMugRequest.ExecuteSmugMugHttpRequest("smugmug.albums.changeSettings", apiKey, appSecret, this.accessToken, true, "AlbumID", albumID.ToString(), "HighlightID", highlightID.ToString(), "Extras", "Highlight");
                var    response = JsonConvert.DeserializeObject <AlbumResponse>(result);

                if (response.stat == "ok")
                {
                    logger.InfoFormat("Changed Album highlight for album id:{0} to:{1}", albumID, highlightID);
                    if (response.Album.Highlight.id == highlightID)
                    {
                        return(true);
                    }
                    else
                    {
                        logger.Error("Could not change Album highlight");
                        logger.Error(response.code);
                        logger.Error(response.message);
                        logger.Error(response.method);
                        return(false);
                    }
                }
                else
                {
                    logger.Error("Could not change Album highlight");
                    throw new SmugMugException(response.code, response.message, response.method);
                }
            }
            catch (Exception ex)
            {
                logger.Error("An error occured trying to set an album settings: " + albumID, ex);
                throw new SmugMugException("An error occured trying to set an album settings: " + albumID, ex);
            }
        }
Пример #14
0
        public Album CreateAlbum(Album album)
        {
            if (album.Title == null || album.Title.Length == 0)
            {
                logger.Error("Error creating Album, no Title");
                throw new ArgumentException("Name must not be empty or null");
            }
            try
            {
                logger.InfoFormat("Creating Album Title: {0}", album.Title);

                Dictionary <string, string> albumValues = new Dictionary <string, string>();

                albumValues.Add("Title", album.Title);
                if (album.CategoryID != 0)
                {
                    albumValues.Add("CategoryID", album.CategoryID.ToString());
                }
                if (album.SubCategoryID != 0)
                {
                    albumValues.Add("SubCategoryID", album.SubCategoryID.ToString());
                }
                if (album.CommunityID != 0)
                {
                    albumValues.Add("CommunityID", album.CommunityID.ToString());
                }
                if (album.Description != null && album.Description.Length != 0)
                {
                    albumValues.Add("Description", album.Description);
                }
                if (album.Keywords != null && album.Keywords.Length != 0)
                {
                    albumValues.Add("Keywords", album.Keywords);
                }
                if (album.Password != null && album.Password.Length != 0)
                {
                    albumValues.Add("Password", album.Password);
                }
                if (album.PasswordHint != null && album.PasswordHint.Length != 0)
                {
                    albumValues.Add("PasswordHint", album.PasswordHint);
                }
                if (album.SortMethod != null)
                {
                    albumValues.Add("SortMethod", album.SortMethod);
                }
                albumValues.Add("Position", album.Position.ToString());
                albumValues.Add("SortDirection", album.SortDirection.ToString());
                albumValues.Add("Public", album.Public.ToString());
                albumValues.Add("Filenames", album.Filenames.ToString());
                albumValues.Add("Comments", album.Comments.ToString());
                albumValues.Add("External", album.External.ToString());
                albumValues.Add("EXIF", album.EXIF.ToString());
                albumValues.Add("Share", album.Share.ToString());
                albumValues.Add("Printable", album.Printable.ToString());

                albumValues.Add("Geography", album.Geography.ToString());
                albumValues.Add("WorldSearchable", album.WorldSearchable.ToString());
                albumValues.Add("SmugSearchable", album.SmugSearchable.ToString());
                albumValues.Add("HideOwner", album.HideOwner.ToString());
                albumValues.Add("FriendEdit", album.FriendEdit.ToString());
                albumValues.Add("FamilyEdit", album.FamilyEdit.ToString());
                albumValues.Add("CanRank", album.CanRank.ToString());
                albumValues.Add("SquareThumbs", album.SquareThumbs.ToString());

                albumValues.Add("Larges", album.Larges.ToString());
                albumValues.Add("XLarges", album.XLarges.ToString());
                albumValues.Add("X2Larges", album.X2Larges.ToString());
                albumValues.Add("X3Larges", album.X3Larges.ToString());
                albumValues.Add("Originals", album.Originals.ToString());

                if (this.account.User.AccountType != AccountTypeEnum.Standard)
                {
                    albumValues.Add("Header", album.Header.ToString());
                }

                if (this.account.User.AccountType == AccountTypeEnum.Pro)
                {
                    albumValues.Add("TemplateID", album.TemplateID.ToString());
                    albumValues.Add("Clean", album.Clean.ToString());
                    albumValues.Add("Protected", album.Protected.ToString());
                    albumValues.Add("Watermarking", album.Watermarking.ToString());

                    if (album.WatermarkID != 0)
                    {
                        albumValues.Add("WatermarkID", album.WatermarkID.ToString());
                    }
                }

                albumValues.Add("Extras", "Title");

                List <string> albumArgs = new List <string>();
                foreach (var item in albumValues)
                {
                    albumArgs.Add(item.Key);
                    albumArgs.Add(item.Value);
                }

                string result   = SmugMugRequest.ExecuteSmugMugHttpRequest("smugmug.albums.create", apiKey, appSecret, this.accessToken, true, albumArgs.ToArray());
                var    response = JsonConvert.DeserializeObject <AlbumResponse>(result);

                if (response.stat == "ok")
                {
                    logger.InfoFormat("Created Album with album id: {0}, album name: {1}, album key: {2}", response.Album.id, response.Album.Title, response.Album.Key);

                    // reload the albums
                    this.albums = GetAlbums(true);
                    return(response.Album);
                }
                else
                {
                    logger.Error("Could not retrieve Albums");
                    logger.Error(response.code);
                    logger.Error(response.message);
                    logger.Error(response.method);
                    throw new SmugMugException(response.code, response.message, response.method);
                }
            }
            catch (Exception ex)
            {
                logger.Error("An error occured trying to create a new Album: " + album.Title, ex);
                throw new SmugMugException("An error occured trying to create a new Album: " + album.Title, ex);
            }
        }