Example #1
0
        static void Main(string[] args)
        {
            //Just here for the purposes of alpha prototype stuff
            //UserService US = new UserService();
            //User ushi = US.GetUser(client, "ushi84", true, false);
            const string consumerKey       = "";
            const string consumerSecret    = "";
            const string accessToken       = "";
            const string accessTokenSecret = "";



            var client = new RestClient();

            client.BaseUrl       = AppKeys.GetBaseUri();
            client.Authenticator = OAuth1Authenticator.ForProtectedResource(consumerKey, consumerSecret, accessToken, accessTokenSecret);
            ShopService    SS         = new ShopService();
            ListingService LS         = new ListingService();
            UserService    US         = new UserService();
            var            Company    = InternalClientService.GetInternalClientByID("646");
            bool           consoleApp = false;

            if (consoleApp)
            {
                //RestRequest request = new RestRequest("/oauth/scopes", Method.GET);
                //IRestResponse response = client.Execute(request);
                //JObject oq = JObject.Parse(response.Content);
                //Console.WriteLine(oq.ToString());
                var command = Console.ReadLine();
                var user    = US.GetUser(client, "threadedtees", true, false);


                if (command.ToLower() == "getlistings")
                {
                    RestRequest request = new RestRequest();
                    request.Resource = string.Format("/taxonomy/seller/get");
                    IRestResponse response = client.Execute(request);
                    JObject       o        = JObject.Parse(response.Content);
                    Console.WriteLine(o.ToString());

                    LS.ImportListing(client);

                    Authorization.GetAccessToken();

                    var listings = SS.GetShopListings(client, Company.EtsyShopIDs.First());
                    //listring id
                    //title
                    //variation name
                    //variation value

                    ExportHelpers.ExportListingIdAndVariations(user.shops.FirstOrDefault().listings, @"C:\Internal\Etsy\ListingIdAndVariation.txt", true);
                }
                if (command.ToLower() == "createlistings")
                {
                    ListingHelper.CreateEtsyListingFromCustomMapping(client, Company, @"C:\Internal\Etsy\CalculatedFailure_FirstTest_Amazon_Feed.txt");
                }
                #region Listing Tool Code

                #endregion

                if (command.ToLower() == "download")
                {
                    string path = @"C:\Internal\Etsy.txt";

                    var receipts = SS.GetOpenShopReceipts(client, Company.EtsyShopIDs.FirstOrDefault());
                    Console.WriteLine("Exporting...");
                    ExportHelpers.ExtractionExport(receipts, path, CountryService.GetCountryMapping(client), true);
                    Console.Write("Export Complete");
                }

                if (command.ToLower() == "upload")
                {
                    ImportHelpers.ShippingSummaries();
                    Console.Write("Upload Complete");
                    Console.ReadLine();
                }
            }
            else
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new DownloadUploadForm());
            }


            #region Listing Creation Stuff

            #endregion
        }
Example #2
0
        public static List <ExtractionModel> CreateExtractionFromReceipt(InternalClient GClient, bool allReceipts)
        {
            //Creation New Rest Client
            var client = new RestClient();

            client.BaseUrl       = AppKeys.GetBaseUri();
            client.Authenticator = OAuth1Authenticator.ForProtectedResource(AppKeys.GetApiKey(), AppKeys.GetSharedSecretKey(), GClient.AccessToken, GClient.AccessSecretKey);

            //The shop servce is where we pull receipts because functionally
            //The call is related to the shop object and te shop id
            ShopService    shopservice = new ShopService();
            List <Receipt> receipts;

            //This is just in case for some reason we want every transaction from a shop
            if (allReceipts)
            {
                receipts = shopservice.GetShopReceipts(client, GClient.EtsyShopIDs.FirstOrDefault());
            }
            else
            {
                receipts = shopservice.GetOpenShopReceipts(client, GClient.EtsyShopIDs.FirstOrDefault());
            }

            //Get the country list from etsy in advance so it doesn't
            //Have to be called per receipt request
            var countries = CountryService.GetCountryMapping(client);

            List <ExtractionModel> extractions = new List <ExtractionModel>();

            //make sure we actually pulled back client data
            if (GClient != null)
            {
                //iteract through receipts
                foreach (Receipt r in receipts)
                {
                    //iterrate through transactions of receipts
                    foreach (var t in r.transactions)
                    {
                        string country = countries[int.Parse(r.country_id)];

                        ExtractionModel em = new ExtractionModel();
                        em.company_id             = GClient.clientID;
                        em.Order_ID               = r.receipt_id;
                        em.date_purchased         = FormattingHelpers.FromEpochUnixTime(t.creation_tsz).ToString("g");
                        em.customer_email_address = r.buyer_email;
                        var FirstnameLastname = FormattingHelpers.FirstNameLastNameFormatter(r.name);
                        em.first_name = FirstnameLastname.Item1;
                        em.last_name  = FirstnameLastname.Item2;

                        em.delivery_address_1 = r.first_line;
                        em.delivery_address_2 = r.second_line;
                        em.delivery_city      = r.city;
                        em.delivery_state     = r.state;
                        em.delivery_zipCode   = r.zip;
                        em.country            = country;

                        //This is for the variation that is assuming
                        //it follows the format "Color - Design"
                        string[] color_design = t.variations.Where(x => x.formatted_name == "Color").FirstOrDefault().formatted_value.Split('-');

                        //If there is not a "-" then it automatically
                        //is the wrong format
                        if (color_design.Length > 1)
                        {
                            //This is making sure that the Design actually is associated
                            //with the client
                            //TODO: Eventually check that the design is actually available in the color
                            //that is provided.
                            if (GClient.ClientDesigns.Where(x => x.design_number.Trim() == color_design[1].Trim()).Any())
                            {
                                em.color         = color_design[0].Trim();
                                em.design_number = FormattingHelpers.DesignNumberFormatCheck(color_design[1].Trim());
                            }
                            else
                            {
                                em.color         = color_design[0].Trim();
                                em.design_number = string.Format("{0} Is Not a Correct Design Id", color_design[1]);
                            }
                        }
                        else
                        {
                            em.color         = color_design[0].Trim();
                            em.design_number = "Color_Design Incorrect Format";
                        }
                        em.design_description = "TBD";
                        em.print_location     = "TBD";


                        //This is for the variation that is assuming
                        //it follows the format "Style - Size"
                        string[] size_style = t.variations.Where(x => x.formatted_name == "Size").FirstOrDefault().formatted_value.Split('-');

                        if (size_style.Length > 1)
                        {
                            string etsystyle = size_style[1].Trim();
                            em.size = size_style[0].Trim();

                            //Check to see if the style from the variation
                            //has a mapping otherwise we can't know what
                            //prodct style its suposed to be
                            var style = GClient.ClientStyles.Where(x => x.etsy_style_descripion == etsystyle).FirstOrDefault();
                            if (style != null)
                            {
                                em.style_number      = style.style_number;
                                em.style_description = style.style_description;
                            }
                            else
                            {
                                em.style_number      = "ESTY STYLE '" + etsystyle + "' NOT FOUND";
                                em.style_description = "ESTY STYLE '" + etsystyle + "' NOT FOUND";
                            }
                        }
                        else
                        {
                            em.style_number      = size_style[0].Trim();
                            em.style_description = "Size_Style Incorrect Format";
                        }

                        em.product_quantity = t.quantity;
                        em.gift_message     = r.message_from_buyer;
                        em.Insured_Order    = "No";
                        em.shipping_method  = CountryService.GetCountryShippingMethodByCountry(country).Shipping_Method;
                        em.order_status     = "2";

                        extractions.Add(em);
                    }
                }
            }
            return(extractions);
        }