1 //----------------------------------------------------------------------- 2 // <copyright file="UpdateProfileColorsCommand.cs" company="Patrick 'Ricky' Smith"> 3 // This file is part of the Twitterizer library (http://www.twitterizer.net) 4 // 5 // Copyright (c) 2010, Patrick "Ricky" Smith (ricky@digitally-born.com) 6 // All rights reserved. 7 // 8 // Redistribution and use in source and binary forms, with or without modification, are 9 // permitted provided that the following conditions are met: 10 // 11 // - Redistributions of source code must retain the above copyright notice, this list 12 // of conditions and the following disclaimer. 13 // - Redistributions in binary form must reproduce the above copyright notice, this list 14 // of conditions and the following disclaimer in the documentation and/or other 15 // materials provided with the distribution. 16 // - Neither the name of the Twitterizer nor the names of its contributors may be 17 // used to endorse or promote products derived from this software without specific 18 // prior written permission. 19 // 20 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 // IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 24 // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 // NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 // POSSIBILITY OF SUCH DAMAGE. 30 // </copyright> 31 // <author>Ricky Smith</author> 32 // <summary>The update profile colors command class</summary> 33 //----------------------------------------------------------------------- 34 35 namespace Twitterizer.Commands 36 { 37 using System; 38 #if !SILVERLIGHT 39 using System.Drawing; 40 #endif 41 using Twitterizer.Core; 42 43 /// <summary> 44 /// Sets one or more hex values that control the color scheme of the authenticating user's profile page on twitter.com 45 /// </summary> 46 [AuthorizedCommand] 47 #if !SILVERLIGHT 48 [Serializable] 49 #endif 50 internal class UpdateProfileColorsCommand : TwitterCommand<TwitterUser> 51 { 52 /// <summary> 53 /// Initializes a new instance of the <see cref="UpdateProfileColorsCommand"/> class. 54 /// </summary> 55 /// <param name="tokens">The tokens.</param> 56 /// <param name="options">The options.</param> UpdateProfileColorsCommand(OAuthTokens tokens, UpdateProfileColorsOptions options)57 public UpdateProfileColorsCommand(OAuthTokens tokens, UpdateProfileColorsOptions options) : 58 base(HTTPVerb.POST, "account/update_profile_colors.json", tokens, options) 59 { 60 if (tokens == null) 61 { 62 throw new ArgumentNullException("tokens"); 63 } 64 65 if (options == null) 66 { 67 throw new ArgumentNullException("options"); 68 } 69 } 70 71 /// <summary> 72 /// Initializes the command. 73 /// </summary> Init()74 public override void Init() 75 { 76 UpdateProfileColorsOptions options = (UpdateProfileColorsOptions)this.OptionalProperties; 77 78 #if !SILVERLIGHT 79 if (options.BackgroundColor != Color.Empty) 80 { 81 this.RequestParameters.Add("profile_background_color", ColorTranslator.ToHtml(options.BackgroundColor)); 82 } 83 #else 84 if (options.BackgroundColor != null) 85 { 86 this.RequestParameters.Add("profile_background_color", options.BackgroundColor); 87 } 88 #endif 89 90 #if !SILVERLIGHT 91 if (options.TextColor != Color.Empty) 92 { 93 this.RequestParameters.Add("profile_text_color", ColorTranslator.ToHtml(options.TextColor)); 94 } 95 #else 96 if (options.TextColor != null) 97 { 98 this.RequestParameters.Add("profile_text_color", options.TextColor); 99 } 100 #endif 101 102 #if !SILVERLIGHT 103 if (options.LinkColor != Color.Empty) 104 { 105 this.RequestParameters.Add("profile_link_color", ColorTranslator.ToHtml(options.LinkColor)); 106 } 107 #else 108 if (options.LinkColor != null) 109 { 110 this.RequestParameters.Add("profile_link_color", options.LinkColor); 111 } 112 #endif 113 114 #if !SILVERLIGHT 115 if (options.SidebarFillColor != Color.Empty) 116 { 117 this.RequestParameters.Add("profile_sidebar_fill_color", ColorTranslator.ToHtml(options.SidebarFillColor)); 118 } 119 #else 120 if (options.SidebarFillColor != null) 121 { 122 this.RequestParameters.Add("profile_sidebar_fill_color", options.SidebarFillColor); 123 } 124 #endif 125 126 #if !SILVERLIGHT 127 if (options.SidebarBorderColor != Color.Empty) 128 { 129 this.RequestParameters.Add("profile_sidebar_border_color", ColorTranslator.ToHtml(options.SidebarBorderColor)); 130 } 131 #else 132 if (options.SidebarBorderColor != null) 133 { 134 this.RequestParameters.Add("profile_sidebar_border_color", options.SidebarBorderColor); 135 } 136 #endif 137 } 138 } 139 } 140