示例#1
0
        public ulong ClicksOnShortURL(string shortURL)
        {
            ShortenedURL shortenedURL = GetShortenedURL(shortURL);

            if (shortenedURL == null) // shortened URL does not exist.
            {
                return(0);
            }

            return(shortenedURL.Clicks);
        }
示例#2
0
        public string Expand(string shortURL)
        {
            ShortenedURL shortenedURL = GetShortenedURL(shortURL);

            if (shortenedURL == null) // shortened URL does not exist.
            {
                return(string.Empty);
            }

            shortenedURL.Expanded();

            return(shortenedURL.URL);
        }
示例#3
0
        public string Shorten(string url)
        {
            ShortenedURL shortenedURL = shortenedURLRepo.GetByURL(url);

            if (shortenedURL == null) // shorten this URL for the first time
            {
                shortenedURL = new ShortenedURL(url, hasher.NextHash(lastHash));
                shortenedURLRepo.Save(shortenedURL);
                lastHash = shortenedURL.Hash;
            }

            return(FormatHashAsURL(shortenedURL.Hash));
        }