コード例 #1
0
        private static PermanentToken GetAuthToken(EtsyListItArgs args)
        {
            var permanentToken = new PermanentToken();

            // If API Key or Shared Secret not found either place, throw error.
            if (args.APIKey.IsNullOrEmpty() || args.SharedSecret.IsNullOrEmpty())
            {
                throw new EtsyListItException(
                          "Must specify API Key and Shared Secret to authenticate.  Please input command line arg -a [value] for API Key and -ss [value] for SharedSecret to continue.");
            }

            permanentToken.APIKey       = args.APIKey;
            permanentToken.SharedSecret = args.SharedSecret;
            permanentToken.TokenID      = _settingsUtility.GetEncryptedAppSetting("PermanentAuthToken");
            permanentToken.TokenSecret  = _settingsUtility.GetEncryptedAppSetting("PermanentSecret");
            // If permanent auth token is not found, get it.
            if (permanentToken.TokenID.IsNullOrEmpty() || permanentToken.TokenSecret.IsNullOrEmpty())
            {
                var permissions = new[] { "listings_r", "listings_w" };
                var validator   = string.Empty;
                IEtsyAuthenticationWrapper authenticationWrapper =
                    _container.GetInstance <IEtsyAuthenticationWrapper>();
                var tempCredentials =
                    authenticationWrapper.GetTemporaryCredentials(args.APIKey, args.SharedSecret, permissions);
                Process.Start(tempCredentials.LoginURL);
                while (validator.IsNullOrEmpty())
                {
                    Console.Write("Enter your Etsy validator from the web browser to continue: ");
                    validator = Console.ReadLine();
                }

                permanentToken =
                    authenticationWrapper.GetPermanentTokenCredentials(args.APIKey, args.SharedSecret, tempCredentials, validator);
            }

            _settingsUtility.SetAppSettingWithEncryption("PermanentAuthToken", permanentToken.TokenID);
            _settingsUtility.SetAppSettingWithEncryption("PermanentSecret", permanentToken.TokenSecret);

            return(permanentToken);
        }
コード例 #2
0
        private static Listing PopulateGraphicListing(List <string> watermarkFiles, List <string> digitalFilePaths,
                                                      EtsyListItArgs listItArgs, string customTitle, string price, string tags)
        {
            if (customTitle.IsNullOrEmpty())
            {
                throw new EtsyListItException(
                          "User must provide custom title for listing.  Use command line arg -ct to specify.");
            }
            var listing = new Listing
            {
                Title       = $"{customTitle} {listItArgs.ListingDefaultTitle}",
                Description =
                    $"{customTitle} {listItArgs.ListingDefaultTitle}\r\n{listItArgs.ListingDefaultDescription}",
                Quantity = listItArgs.ListingQuantity,
                Price    = decimal.TryParse(price, out decimal priceValue)
                    ? priceValue
                    : throw new InvalidDataException("Price must be a decimal value."),
                                 IsSupply           = true,
                                 CategoryID         = "69150433",
                                 WhenMade           = "2010_2017",
                                 WhoMade            = "i_did",
                                 State              = "draft",
                                 IsCustomizable     = true,
                                 IsDigital          = true,
                                 ShippingTemplateID = "30116314577",
                                 Tags = tags.Split(',')
            };

            listing.Images = new ListingImage[5];

            var count = 0;

            foreach (var watermarkPath in watermarkFiles)
            {
                listing.Images[count] = new ListingImage
                {
                    ImagePath = File.Exists(watermarkPath)
                        ? watermarkPath
                        : throw new InvalidDataException("Watermark path is invalid."),
                                      Overwrite     = true,
                                      IsWatermarked = true,
                                      Rank          = count
                };
                count++;
            }

            listing.DigitalFiles = new DigitalFile[5];
            count = 0;
            foreach (var digitalFilePath in digitalFilePaths)
            {
                listing.DigitalFiles[count] = new DigitalFile
                {
                    Path = File.Exists(digitalFilePath)
                        ? digitalFilePath
                        : throw new InvalidDataException("Digital file path is invalid."),
                                 Name = Path.GetFileName(digitalFilePath),
                                 Rank = count
                };

                count++;
            }


            return(listing);
        }
コード例 #3
0
        public EtsyListItArgs ParseCommandLineArguments(string[] args)
        {
            _commandLineArgs = new EtsyListItArgs();
            var p = new OptionSet()
            {
                {
                    "wd|Working Directory=", "Sets or changes the directory of the base file",
                    v => _commandLineArgs.WorkingDirectory = v
                },
                {
                    "od|Output Directory=",
                    "Sets or changes the directory of the output files",
                    v => _commandLineArgs.OutputDirectory = v
                },
                {
                    "a|APIKey=",
                    "Sets or changes the API key for the application",
                    v => _commandLineArgs.APIKey = v
                },
                {
                    "ss|Shared Secret=",
                    "Sets or changes the shared secret for the application",
                    v => _commandLineArgs.SharedSecret = v
                },
                {
                    "dt|Default Title=",
                    "Sets or changes the default title for the listing.",
                    v => _commandLineArgs.ListingDefaultTitle = v
                },
                {
                    "dd|Default Description=",
                    "Sets or changes the default description for the listing.",
                    v => _commandLineArgs.ListingDefaultDescription = v
                },
                {
                    "lq|Listing Quantity=",
                    "Sets or changes the quantity for the listing.",
                    v => _commandLineArgs.ListingQuantity = v
                },
                {
                    "wm|Watermark File=" +
                    "",
                    "Sets the watermark to place on the graphic.",
                    v => _commandLineArgs.WatermarkFile = v
                },
                {
                    "update|Update Listing=" +
                    "",
                    "Tells the application whether you want to add a listing for the graphic to Etsy.",
                    v => _commandLineArgs.UpdateListingID = v
                },
                {
                    "add|Add To Etsy=" +
                    "",
                    "Tells the application whether you want to add a listing for the graphic to Etsy.",
                    v => _commandLineArgs.AddToEtsy = v
                },
                {
                    "publish|Publish Listing=" +
                    "",
                    "Tells the application whether you want to publish the listing.",
                    v => _commandLineArgs.PublishListing = v
                }
            };

            try
            {
                p.Parse(args);

                _commandLineArgs.WorkingDirectory = GetValueAndStore("WorkingDirectory", _commandLineArgs.WorkingDirectory, "-wd");
                _commandLineArgs.OutputDirectory  =
                    GetValueAndStore("Output Directory", _commandLineArgs.OutputDirectory, "-od");
                _commandLineArgs.APIKey              = GetValueAndStore("APIKey", _commandLineArgs.APIKey, "-a");
                _commandLineArgs.SharedSecret        = GetValueAndStore("SharedSecret", _commandLineArgs.SharedSecret, "-ss");
                _commandLineArgs.ListingDefaultTitle =
                    GetValueAndStore("ListingDefaultTitle", _commandLineArgs.ListingDefaultTitle, "-dt");
                _commandLineArgs.ListingDefaultDescription =
                    GetValueAndStore("ListingDefaultDescription", _commandLineArgs.ListingDefaultDescription, "-dd");
                _commandLineArgs.ListingQuantity = GetValueAndStore("ListingQuantity",
                                                                    _commandLineArgs.ListingQuantity, "-lq");
                _commandLineArgs.WatermarkFile = GetValueAndStore("WatermarkFile",
                                                                  _commandLineArgs.WatermarkFile, "-wm");
                _commandLineArgs.PublishListing = GetValueAndStore("PublishListing",
                                                                   _commandLineArgs.WatermarkFile, "-publish");
                _commandLineArgs.AddToEtsy = GetValueAndStore("AddToEtsy", _commandLineArgs.AddToEtsy, "-add");
            }
            catch (OptionException e)
            {
                throw new EtsyListItException("Unable to parse commandLine args.  OptionsException: {0}".QuickFormat(e.Message));
            }
            return(_commandLineArgs);
        }