Ejemplo n.º 1
0
        public async Task UseBitLy(string apkikey, string url)
        {
            var bitly        = new Bitly(apkikey);
            var linkResponse = await bitly.PostShorten(url);

            URL = linkResponse.Link;
        }
Ejemplo n.º 2
0
        public IActionResult GoToUrl(string hash)
        {
            var   db    = new BitlyManager(_connectionString);
            Bitly bitly = db.GetBitlyForHash(hash);

            db.AddView(bitly.Id, bitly.Views);
            return(Redirect(bitly.Url));
        }
Ejemplo n.º 3
0
        public async Task <JsonResult> GetBitLy(string url)
        {
            string         token    = "bc6da10fdeaf9464d82cdf475cfb3b19c1a506ca";
            Bitly          provider = new Bitly(token, url);
            ShortUrlClient client   = ShortUrlClientFactory.Create(provider);

            return(Json(await client.ReceiveAsync(), JsonRequestBehavior.DenyGet));
        }
Ejemplo n.º 4
0
        public async Task <string> shortenUrl(string url)
        {
            var bitly        = new Bitly(_token);
            var linkResponse = await bitly.PostShorten(url);

            var newLink = linkResponse.Link;

            return(newLink);
        }
Ejemplo n.º 5
0
        public async Task GetBitlinksByGroup()
        {
            var bitly = new Bitly(_genericAccessToken);

            Assert.IsNotNull(bitly);
            var firstPage = await bitly.GetBitlinksByGroup();

            Assert.IsTrue(firstPage.Links.Any());
        }
Ejemplo n.º 6
0
        public void GetGroups()
        {
            var bitly = new Bitly(_genericAccessToken);

            Assert.IsNotNull(bitly);
            var groups = bitly.GetGroups().Result;

            Assert.IsTrue(groups.Any());
        }
Ejemplo n.º 7
0
        public async Task PostShorten()
        {
            var bitly = new Bitly(_genericAccessToken);

            Assert.IsNotNull(bitly);
            var linkResponse = await bitly.PostShorten("https://www.google.ca/");

            Assert.AreEqual("https://s.phansoft.ca/1WuTssO", linkResponse.Link);
            Assert.AreEqual("https://www.google.ca/", linkResponse.LongUrl);
        }
Ejemplo n.º 8
0
        public async Task GetBitlinksByGroupSize()
        {
            var bitly = new Bitly(_genericAccessToken);

            Assert.IsNotNull(bitly);
            var firstPage = await bitly.GetBitlinksByGroup(size : 1);

            Assert.IsTrue(firstPage.Links.Any());
            Assert.IsTrue(firstPage.Pagination.Total > firstPage.Pagination.Size);
            var secondPage = await bitly.GetBitlinksByGroup(size : 1, page : 2);

            Assert.AreEqual(2, secondPage.Pagination.Page);
            Assert.AreNotEqual(firstPage.Links.First().Link, secondPage.Links.First().Link);
        }
Ejemplo n.º 9
0
        public async Task GetBitlinksByGroupRecent()
        {
            var bitly = new Bitly(_genericAccessToken);

            Assert.IsNotNull(bitly);
            var now          = DateTime.Now;
            var testUrl      = "https://www.google.ca/?q=" + now.ToShortDateString() + now.ToLongTimeString();
            var linkResponse = await bitly.PostShorten(testUrl);

            //Bitly won't show links that are very new
            Thread.Sleep(new TimeSpan(0, 0, 0, 30));
            var newest = await bitly.GetBitlinksByGroup(createdAfter : now);

            Assert.IsTrue(newest.Links.Any(l => l.LongUrl == testUrl));
        }
Ejemplo n.º 10
0
        /* Создаёт сокращённую ссылку */
        private static string GetShortLink(string lpLongUrl, string lpKey)
        {
            var lpShortUrl = "";

            try
            {
                var bitly        = new Bitly(lpKey);
                var linkResponse = bitly.PostShorten(lpLongUrl);
                lpShortUrl = linkResponse.Result.Link;
            }
            catch
            {
                lpShortUrl = "error";
            }
            return(lpShortUrl);
        }
Ejemplo n.º 11
0
        public IActionResult ShortenUrl(string url)
        {
            var    db   = new BitlyManager(_connectionString);
            string hash = ShortId.Generate(7);

            while (db.CheckIfContainedHash(hash))
            {
                hash = ShortId.Generate(7);
            }
            Bitly bitly = new Bitly();

            bitly.Url  = url;
            bitly.Hash = hash;
            if (User.Identity.IsAuthenticated)
            {
                User user = db.GetByEmail(User.Identity.Name);
                bitly.UserId = user.Id;
            }
            db.AddBitly(bitly);
            string h = "https://localhost:44372/" + hash;

            return(Json(h));
        }
Ejemplo n.º 12
0
        public ActionResult <GenericResponseModel> ConfirmSubmit([FromBody] OfferDto pOffer)
        {
            var loUserId          = HelperMethods.GetApiUserIdFromToken(HttpContext.User.Identity);
            var loGenericResponse = new GenericResponseModel
            {
                Code   = -1,
                Status = "Fail"
            };

            var loResult = GetData.GetOfferById(pOffer.row_guid.ToString());

            if (loResult == null)
            {
                loGenericResponse.Message = "Kayıtlı teklif bulunamadı!";
                return(loGenericResponse);
            }

            var loCustomer = GetData.GetCustomerById(loResult.owner_uuid.ToString());

            if (loCustomer == null)
            {
                loGenericResponse.Message = "Kayıtlı teklif bulunamadı!";
                return(loGenericResponse);
            }

            loResult.offer_state_type_system_type_id = (int)OfferStateTypes.WaitingOffer;
            loResult.row_update_date = DateTime.Now;
            loResult.row_update_user = loUserId;

            //Crud<Offer>.Update(loResult, out _);

            var loPassword       = "";
            var loMessageContent = "";
            var loUserNameType   = loCustomer.user_type_system_type_id == 1 ? "kimlik numaranız" : "vergi numaranız";

            if (string.IsNullOrEmpty(loCustomer.password))
            {
                loPassword       = HelperMethods.RandomOtp();
                loMessageContent =
                    string.Format(
                        "Sayın müşterimiz teklif vermek istediğiniz gayrimenkule ait başvurunuz onaylanmıştır. Teklif vermek için {0} adresini ziyaret edebilirsiniz. Sisteme giriş için kullanıcı adınız: {3}, şifreniz: {1}'dir. Mesaj tarihi: {2}", Common.CustomerUrl, loPassword, DateTime.Now, loUserNameType);

                loCustomer.password        = HelperMethods.Md5OfString(loPassword);
                loCustomer.row_update_date = loResult.row_update_date;
                loCustomer.row_update_user = loUserId;
                Crud <Customer> .Update(loCustomer, out _);
            }
            else
            {
                var loUrl = Bitly.Shorten(Common.CustomerUrl);
                loMessageContent =
                    string.Format(
                        "Sayın müşterimiz teklif vermek istediğiniz gayrimenkule ait başvurunuz onaylanmıştır. Teklif vermek için {0} adresini ziyaret edebilirsiniz. Sisteme giriş için kullanıcı adınız olarak {2} ve daha önce oluşturduğunuz şifreyi kullanabilirsiniz. Mesaj tarihi: {1}", loUrl, DateTime.Now, loUserNameType);
            }

            Crud <Offer> .Update(loResult, out _);

            RestCalls.SendSms(loMessageContent, loCustomer.phone);

            loGenericResponse.Code   = 200;
            loGenericResponse.Status = "OK";
            loGenericResponse.Data   = loResult;

            return(loGenericResponse);
        }
Ejemplo n.º 13
0
 public UrlShortener(Bitly bitly, ILogger <UrlShortener> logger)
 {
     _bitly  = bitly;
     _logger = logger;
 }
Ejemplo n.º 14
0
        public SocialPageData Execute(string pageUri)
        {
            SessionAwareCoreServiceClient client = null;
            SocialPageData socialPageData        = new SocialPageData();

            try
            {
                client = Client.GetCoreService();

                string liveTargetUri = Configuration.GetConfigString("livetargeturi");
                string liveUrl       = Configuration.GetConfigString("liveurl");

                PageData            pageData = (PageData)client.Read(pageUri, new ReadOptions());
                PublishLocationInfo pubInfo  = (PublishLocationInfo)pageData.LocationInfo;

                socialPageData.Title       = pageData.Title;
                socialPageData.Uri         = pageUri;
                socialPageData.Url         = liveUrl + pubInfo.PublishLocationUrl;
                socialPageData.IsPublished = client.IsPublished(pageUri, liveTargetUri, true);
                socialPageData.UseShortUrl = bool.Parse(Configuration.GetConfigString("shorturl"));

                string shortUrl = string.Empty;

                if (socialPageData.UseShortUrl)
                {
                    ApplicationData appData = client.ReadApplicationData(pageUri, SHORT_URL_APP_ID);

                    if (appData != null)
                    {
                        Byte[] data = appData.Data;
                        shortUrl = Encoding.Unicode.GetString(data);
                    }

                    if (shortUrl.Equals(string.Empty))
                    {
                        Bitly  service = new Bitly(socialPageData.Url);
                        string shorter = service.ShortenUrl(service.UrlToShorten, service.BitlyLogin, service.BitlyAPIKey);
                        shortUrl = Bitly.ParseXmlResponse(shorter, false);

                        Byte[] byteData = Encoding.Unicode.GetBytes(shortUrl);
                        appData = new ApplicationData
                        {
                            ApplicationId = SHORT_URL_APP_ID,
                            Data          = byteData,
                            TypeId        = shortUrl.GetType().ToString()
                        };

                        client.SaveApplicationData(pageUri, new[] { appData });
                    }
                }

                socialPageData.ShortUrl = shortUrl;
            }
            catch (Exception ex)
            {
                socialPageData.HasError  = true;
                socialPageData.ErrorInfo = ex;
            }
            finally
            {
                if (client != null)
                {
                    if (client.State == CommunicationState.Faulted)
                    {
                        client.Abort();
                    }
                    else
                    {
                        client.Close();
                    }
                }
            }

            return(socialPageData);
        }
Ejemplo n.º 15
0
 public void TestTryBitConverter()
 {
     var restt = Bitly.TryBitConverter();
 }
Ejemplo n.º 16
0
        // GET api/values
        public string Get()
        {
            
            Uri uri = Request.RequestUri;
            Bitly bityly = new Bitly();
            UrlLog.UrlLogdbContext dblog = new UrlLog.UrlLogdbContext();
            string paramMethod = HttpUtility.ParseQueryString(uri.Query).Get("method");
            if (paramMethod==null)
            {
                return "error: no param method";
            }


            string querryvalue =  uri.Query;

            if (!querryvalue.Contains("&url="))
            {
                return "error: no param url";
            }

            if (querryvalue.Contains("&method="+paramMethod))
            {
                querryvalue = querryvalue.Replace("&method=" + paramMethod, "").Replace("url=","");
            }
            else
            {
                querryvalue = querryvalue.Replace("?method=" + paramMethod+"&url=", "");
            }

            string urifromget = querryvalue;//HttpUtility.ParseQueryString(uri.Query).Get("url");

           

            
            
            if (paramMethod == "short")
            {
                
                string returnUri = bityly.Shorten(HttpUtility.HtmlDecode(urifromget));
                if (returnUri == "Wrong URL")
                {
                    dblog.ItemDbSet.Add(new UrlLog.LogUrl()
                    {
                        Datetimeofrequest = DateTime.UtcNow, NewUrl = returnUri, OldUrl = urifromget,
                        Result = returnUri
                    });
                    dblog.SaveChanges();
                    return returnUri;
                }
                else
                {
                    dblog.ItemDbSet.Add(new UrlLog.LogUrl()
                    {
                        Datetimeofrequest = DateTime.UtcNow,
                        NewUrl = returnUri,
                        OldUrl = urifromget,
                        Result = "Success"
                    });
                    dblog.SaveChanges();
                    return returnUri;
                }
            }
            else if (paramMethod == "expand")
            {
                string returnuri = bityly.Expand(urifromget);
                if (returnuri == "can't expand")
                {
                    dblog.ItemDbSet.Add(new UrlLog.LogUrl()
                    {
                        Datetimeofrequest = DateTime.UtcNow,
                        NewUrl = returnuri,
                        OldUrl = urifromget,
                        Result = returnuri
                    });
                    dblog.SaveChanges();
                    return returnuri;
                }
                else
                {
                    dblog.ItemDbSet.Add(new UrlLog.LogUrl()
                    {
                        Datetimeofrequest = DateTime.UtcNow,
                        NewUrl = returnuri,
                        OldUrl = urifromget,
                        Result = "Success"
                    });
                    dblog.SaveChanges();
                    return returnuri;
                }

            }
            else
            {
                return "unsupported method";
            }


            // return new string[] { "value1", "value2" };
        }