Esempio n. 1
0
 public void CheckUrl(string checkUrl, string newToken)
 {
     try
     {
         //{"email_address":"*****@*****.**","password":"******","remember":true}
         string  uniqueCampUrl = "here-is-my-url-" + StringUtil.RandomString(8);
         string  url           = "https://viralstyle.com/design.beta/check-url";
         dynamic urlObj        = new ExpandoObject();
         urlObj.url = uniqueCampUrl;
         string checkResult = web.HttpUploadFileByJson(url,
                                                       JsonConvert.SerializeObject(urlObj), token, newToken);
         Console.WriteLine(checkResult);
     }
     catch (Exception ex)
     {
         logger.ErrorFormat("Error: {0}, stacktrace: {1}", ex.Message, ex.StackTrace);
     }
 }
Esempio n. 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            IWebDriver webDriver = new ChromeDriver();

            webDriver.Navigate().GoToUrl("https://teespring.com/login");

            var divRoot    = webDriver.FindElement(By.XPath("//div[@class='authentication__standalone js-user-auth-standalone authentication--email authentication--login_open']"));
            var divAuth    = divRoot.FindElement(By.XPath("//div[@class='authentication authentication--login js-user-login']"));
            var emailInput = divAuth.FindElement(By.Name("email"));

            DivClick(webDriver, emailInput, "*****@*****.**", 1000);

            var passInput = divAuth.FindElement(By.Name("password"));

            DivClick(webDriver, passInput, "19001560", 1000);

            var loginBtn = divAuth.FindElement(By.XPath("//input[@class='button button--primary authentication__button js-email-login-submit']"));

            loginBtn.Click();
            Thread.Sleep(1500);


            var tag = webDriver.FindElement(By.XPath("//meta[@name='csrf-token']"));

            CookieContainer container = new CookieContainer();

            foreach (var cc in webDriver.Manage().Cookies.AllCookies)
            {
                container.Add(new System.Net.Cookie(cc.Name, cc.Value, cc.Path, cc.Domain));
            }

            CustomWeb web   = new CustomWeb(container);
            string    token = tag.GetAttribute("content");

            web.TOKEN = token;

            //string result = web.SendRequest("https://teespring.com/login", "GET", null, true);
            //var doc = new HtmlAgilityPack.HtmlDocument();
            //doc.LoadHtml(result);
            //var metaNode = doc.DocumentNode.SelectSingleNode("//meta[@name='csrf-token']");
            //token = metaNode.GetAttributeValue("content", string.Empty);
            ////web.TOKEN = token;

            //var htmlWeb = new HtmlAgilityPack.HtmlWeb();
            //doc = htmlWeb.Load("https://teespring.com/login");
            //metaNode = doc.DocumentNode.SelectSingleNode("//meta[@name='csrf-token']");
            //token = metaNode.GetAttributeValue("content", string.Empty);
            ////web.TOKEN = token;

            //string url = "https://teespring.com/sessions";
            NameValueCollection nvc = new NameValueCollection();
            //nvc.Add("email", "*****@*****.**");
            //nvc.Add("password", "19001560");

            //string result = web.SendRequest(url, "POST", nvc, false, "application/x-www-form-urlencoded");

            //Console.WriteLine("login: "******"csrftoken", token, "/", "teespring.com"));
            //Console.WriteLine("result: "+result);

            string responseUrl = "";
            string result      = web.SendRequest("https://teespring.com/designs", "GET", null, ref responseUrl);

            Console.WriteLine("response url: " + responseUrl);

            // signed request
            string imageName = RandomStringOnly(8) + ".png";
            string signedUrl = "https://teespring.com/designs/sign_s3?s3_object_type=image/png&s3_object_name=" + imageName;

            result = web.SendRequest(signedUrl, "GET", null);
            Console.WriteLine("signed url: " + result);
            SignedResponse signedRes = JsonConvert.DeserializeObject <SignedResponse>(result);

            Console.WriteLine(signedUrl);

            // regist 1 signal
            string sign1Url = WebUtility.UrlDecode(signedRes.signed_request);

            Console.WriteLine(sign1Url);
            nvc.Clear();
            string tempUrl = sign1Url.Split('?')[1];

            string[] temp2 = tempUrl.Split('&');
            //nvc.Add("X-Amz-Algorithm", temp2[0].Replace("X-Amz-Algorithm=", ""));
            //nvc.Add("X-Amz-Credential", temp2[1].Replace("X-Amz-Algorithm=", ""));
            //nvc.Add("X-Amz-Date", temp2[2].Replace("X-Amz-Algorithm=", ""));
            //nvc.Add("X-Amz-Expires", temp2[3].Replace("X-Amz-Algorithm=", ""));
            //nvc.Add("X-Amz-SignedHeaders", temp2[4].Replace("X-Amz-Algorithm=", ""));
            //nvc.Add("x-amz-acl", temp2[5].Replace("X-Amz-Algorithm=", ""));
            //nvc.Add("X-Amz-Signature", temp2[6].Replace("X-Amz-Algorithm=", ""));
            nvc.Add("PNG",
                    ImageToBase64(Image.FromFile(@"D:\Auto\Logo\test.png"),
                                  System.Drawing.Imaging.ImageFormat.Png));
            result = web.SendCustomRequest(sign1Url, "OPTIONS", "teespring-usercontent.s3.amazonaws.com", null, true, "PUT");
            result = web.SendCustomRequest2(sign1Url, "PUT", "teespring-usercontent.s3.amazonaws.com", @"D:\Auto\Logo\test.png", false, "", false, "image/png");
            // result = web.SendCustomRequest(sign1Url, "POST", "teespring-usercontent.s3.amazonaws.com", null);
            Console.WriteLine("sign1url result: " + result);
            string uploadUrl = responseUrl.Replace("edit", "uploads");

            // string uploadImageUrl = "https://teespring.com/designs/lu32t4/uploads";
            string randName = RandomStringOnly(8);
            //LogoModel logo = new LogoModel(@"D:\Auto\Logo\1.png", "png");
            LogoModel logo = new LogoModel(imageName, "png");

            result = web.HttpUploadFileByJson(uploadUrl, JsonConvert.SerializeObject(logo));
            Console.WriteLine(result);


            // check valid url
            string title    = "this-is-ultimate-113";
            string checkUrl = "https://teespring.com/url/availability?url=" + title;

            result = web.SendCustomRequest(checkUrl, "GET", "teespring.com", null);
            Console.WriteLine("check url result: " + result);


            // put upload design
            string uploadDesignUrl = responseUrl.Replace("/edit", "");
            string lookupId        = uploadDesignUrl.Substring(uploadDesignUrl.LastIndexOf("/") + 1);
            //UploadDesignParameters desginParams = new UploadDesignParameters(lookupId, title.Replace("-", " "),
            //    title, "I will write some description on here!", "#ipshirt", imageName,
            //    "https://teespring-usercontent.s3.amazonaws.com/"+ imageName, "test.png");

            DesignParameter designs = new DesignParameter(lookupId, title.Replace("-", " "),
                                                          title, "I will write some description on here!", "#ipshirt", imageName,
                                                          "https://teespring-usercontent.s3.amazonaws.com/" + imageName, "test.png");


            string uploadResult = web.SendCustomRequest(uploadDesignUrl, "PUT", "teespring.com",
                                                        designs.ConvertToNVC(), false, "", false, "application/x-www-form-urlencoded", "application/json");

            //dynamic uploadResult = web.SendRequestWithStringData(uploadDesignUrl, "PUT", "teespring.com",
            //   desginParams.ToString(), false, "", false, "application/json");
            Console.WriteLine("upload reuslt: " + uploadResult);
            // camp id
            dynamic dResult = JsonConvert.DeserializeObject(uploadResult);
            string  campId  = dResult.campaign_id;
            // launch campaign
            string  launchUrl    = string.Format("https://teespring.com/campaigns/{0}/launch", campId);
            dynamic launchResult = web.SendRequestWithStringData(launchUrl, "POST", "teespring.com",
                                                                 "partnership=", false, "", false, "application/x-www-form-urlencoded; charset=UTF-8");
            //Console.WriteLine(launchResult);
            var doc = new HtmlAgilityPack.HtmlDocument();

            doc.LoadHtml(launchResult);
            var metaNode = doc.DocumentNode.SelectSingleNode("//meta[@name='csrf-token']");

            token     = metaNode.GetAttributeValue("content", string.Empty);
            web.TOKEN = token;

            string url = "https://teespring.com/sessions";

            nvc.Clear();
            nvc.Add("email", "*****@*****.**");
            nvc.Add("password", "19001560");

            result = web.SendRequest(url, "POST", nvc, false, "application/x-www-form-urlencoded");


            Console.WriteLine("login2 : " + result);

            launchResult = web.SendRequestWithStringData(launchUrl, "POST", "teespring.com",
                                                         "partnership=", false, "", false, "application/x-www-form-urlencoded; charset=UTF-8");

            string readyUrl = "https://teespring.com/designs/" + lookupId + "/assets_ready";
            //for (int i = 0; i < 5; i++)
            //{
            string finalResult = web.SendRequest(readyUrl, "GET", null);

            Console.WriteLine(finalResult);
            Thread.Sleep(2000);
            //}
        }
Esempio n. 3
0
        public string UplodNewMockup(string jsonData)
        {
            string uploadUrl = "https://manager.sunfrogshirts.com/Designer/php/upload-handler.cfm";

            return(web.HttpUploadFileByJson(uploadUrl, jsonData));
        }
Esempio n. 4
0
        private void button1_Click(object sender, EventArgs e)
        {
            CustomWeb           web = new CustomWeb();
            NameValueCollection nvc = new NameValueCollection();

            string url = "https://viralstyle.com/design.beta/product-categories?api_campaign=false";

            string result = web.SendRequest(url, "GET", "viralstyle.com", null, true);

            //Console.WriteLine(result);
            url = "https://viralstyle.com/api/v2/token";

            nvc.Clear();
            //grant_type=client_credentials&client_id=frontend&client_secret=frontend&scope=public
            nvc.Add("grant_type", "client_credentials");
            nvc.Add("client_id", "frontend");
            nvc.Add("client_secret", "frontend");
            nvc.Add("scope", "public");
            result = web.SendRequest(url, "POST", "viralstyle.com", nvc, false, "application/x-www-form-urlencoded");
            dynamic jsonResult = JsonConvert.DeserializeObject(result);
            string  token      = jsonResult.access_token;

            Console.WriteLine(token);

            //nvc.Add("email", "*****@*****.**");
            // nvc.Add("password", "19001560");
            string loginUrl = " https://viralstyle.com/api/v2/auth/login";

            LoginModel loginModel = new LoginModel("*****@*****.**", "19001560", false);
            string     loginJson  = JsonConvert.SerializeObject(loginModel);

            result = web.SendRequestJsonType(loginUrl, "POST", "application/json", loginJson, token, true);
            // Console.WriteLine(result);

            url = "https://viralstyle.com/api/v2/token";
            nvc.Clear();
            //grant_type=client_credentials&client_id=frontend&client_secret=frontend&scope=public
            nvc.Add("grant_type", "client_credentials");
            nvc.Add("client_id", "frontend");
            nvc.Add("client_secret", "frontend");
            nvc.Add("scope", "public");
            result     = web.SendRequest(url, "POST", "viralstyle.com", nvc, false, "application/x-www-form-urlencoded");
            jsonResult = JsonConvert.DeserializeObject(result);
            token      = jsonResult.access_token;
            Console.WriteLine(token);

            string uploadUrl = "https://viralstyle.com/design.beta/upload-asset";

            nvc.Clear();
            //nvc.Add("is_api_order", "0");
            nvc.Add("product_id", "1");
            nvc.Add("is_embroidery", "0");
            nvc.Add("is_phone_case", "0");
            nvc.Add("sublimation", "0");
            nvc.Add("campaign_identifier", "NEW");
            nvc.Add("identifier", "NEW");
            nvc.Add("sublimation", "0");
            nvc.Add("width", "218");
            nvc.Add("extension", "png");
            result = web.HttpUploadFile(uploadUrl, @"C:\Users\RAVI\Desktop\Logo\BROWN.png",
                                        "image_file", "image/png", nvc);
            dynamic uploadResult = JsonConvert.DeserializeObject(result);
            string  campId       = uploadResult.data.campaign_identifier;
            string  imageId      = Path.GetFileNameWithoutExtension(uploadResult.data.original_file.ToString());
            string  id           = uploadResult.data.identifier;

            string orgUrl     = uploadResult.data.original_file;
            string resizeUrl  = uploadResult.data.trimmed_image;
            string trimmedUrl = uploadResult.data.resized_image;

            Console.WriteLine(result);


            string title       = "this is my title";
            string description = "this is another description";
            // string token = "tkMyMmQDXpeeLkFaLv5wb3lPx0KdEsNV269PnepU";
            string uniqueCampUrl = "here-is-my-url-" + StringUtil.RandomString(8);
            string jsonData      = File.ReadAllText(Directory.GetCurrentDirectory() + "\\data3.json");

            nvc.Clear();
            result = web.SendRequest("https://viralstyle.com/design.beta", "GET", nvc);
            var doc = new HtmlAgilityPack.HtmlDocument();

            doc.LoadHtml(result);

            string newToken = doc.DocumentNode.SelectSingleNode("//input[@id='_token']")
                              .GetAttributeValue("value", string.Empty);

            System.Drawing.Image img = System.Drawing.Image.FromFile(@"C:\Users\RAVI\Desktop\Logo\test.png");
            //var resizeImg = Resize(@"C:\Users\RAVI\Desktop\Logo\BROWN.png", 0.5);
            string base64String;

            using (var ms = new MemoryStream())
            {
                img.Save(ms, img.RawFormat);
                base64String = "data:image/png;base64," + Convert.ToBase64String(ms.ToArray());
            }
            //img.Dispose();
            img.Dispose();
            jsonData = jsonData.Replace("{CAMP_ID}", campId)
                       .Replace("{IMAGE_ID}", id)
                       .Replace("{RESIZE_IMAGE_URL}", resizeUrl)
                       .Replace("{TRIMMED_IMAGE_URL}", trimmedUrl)
                       .Replace("{ORG_IMAGE_URL}", orgUrl)
                       .Replace("{TITLE}", title)
                       .Replace("{DESCRIPTION}", description)
                       .Replace("{CAMP_URL}", uniqueCampUrl)
                       .Replace("{TOKEN}", newToken)
                       .Replace("{IMAGE_64}", base64String);


            // check url
            dynamic urlObj = new ExpandoObject();

            urlObj.url = uniqueCampUrl;
            string checkResult = web.HttpUploadFileByJson("https://viralstyle.com/design.beta/check-url",
                                                          JsonConvert.SerializeObject(urlObj), token, newToken);
            //Console.WriteLine(result);
            string campUrl = "https://viralstyle.com/api/v2/designer/store";

            result = web.HttpUploadFileByJson(campUrl, jsonData, token, newToken);
            Console.WriteLine(result);
        }