Esempio n. 1
0
        public string RunCommand()
        {
            IBitlyService bitlyService = new BitlyService("vhytyk", "R_5d31d4dc7a364cf6af291c7533655e55");

            string result = null;

            if (!string.IsNullOrEmpty(_searchPhrase))
            {
                var wikiService = new ConfluenceSoapServiceService();
                if (null == wikiToken)
                {
                    wikiToken = wikiService.login("vhytyk", "");
                }

                var resultList = new List <string>();
                var searchList = wikiService.search(wikiToken, _searchPhrase, 20)
                                 .Where(r => r.type == "page")
                                 .Take(3)
                                 .ToList();

                searchList.ForEach(s =>
                {
                    resultList.Add(string.Format("{1} ({0})",
                                                 bitlyService.Shorten(s.url.Replace("wiki/", "wiki.justanswer.local/")), s.title));
                });



                result = string.Join("\r", resultList);
            }

            return(result);
        }
Esempio n. 2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            BitlyService s = new BitlyService("bitlyapidemo", "R_0da49e0a9118ff35f52f629d2d71bf07");
            string       shortened;
            StatusCode   status = s.Shorten("http://cnn.com", out shortened);

            IBitlyResponse[] shortUrls = s.Shorten(new string[] { "http://cnn.com", "http://google.com" }, out status);
        }
Esempio n. 3
0
        public void CreateRandomUrl()
        {
            BitlyService service = new BitlyService();
            Regex        regex   = new Regex(@"^[A-Za-z]{8}$");
            Boolean      match   = regex.IsMatch(service.GetRandomUrlEndpoint());

            Assert.True(match);
        }
Esempio n. 4
0
        public string BitylFromApi(string url)
        {
            IBitlyService s = new BitlyService(userName, password);

            if (s.Shorten(url, out shortUrl) == StatusCode.OK)
            {
                Console.WriteLine(shortUrl);
                Console.ReadKey();
            }

            return(shortUrl);
        }
Esempio n. 5
0
        public void InvalidUrl()
        {
            BitlyService service           = new BitlyService();
            Regex        lowerLengthRegex  = new Regex(@"^[A-Za-z]{8:}$");
            Regex        higherLengthRegex = new Regex(@"^[A-Za-z]{0:7}$");

            Boolean lowerMatch  = lowerLengthRegex.IsMatch(service.GetRandomUrlEndpoint());
            Boolean higherMatch = higherLengthRegex.IsMatch(service.GetRandomUrlEndpoint());

            Assert.False(lowerMatch);
            Assert.False(higherMatch);
        }
Esempio n. 6
0
 public static String Shorten(String url)
 {
     try
     {
         var bitlyService = new BitlyService("xxx", "xxx");
         bitlyService.AuthenticateWith("xxx");
         var response = bitlyService.ShortenUrl(new ShortenUrlOptions {
             Longurl = url
         });
         return(response.Data.Url);
     }
     catch (Exception exception)
     {
         Error(exception);
     }
     return(url);
 }
Esempio n. 7
0
        private static string GetBitlyUrl(ISettings settingsRepository, string url, string urlFormat)
        {
            var bitlyUsername = ApplicationConfiguration.BitlyUserName;
            var bitlyApiKey   = ApplicationConfiguration.BitlyApiKey;

            if (string.IsNullOrEmpty(bitlyUsername) || string.IsNullOrEmpty(bitlyApiKey))
            {
                return(null);
            }

            try
            {
                var    bitlyService = new BitlyService(bitlyUsername, bitlyApiKey);
                string shortUrl;
                bitlyService.Shorten(string.Format(urlFormat, settingsRepository.BlogAkismetUrl, url), out shortUrl);
                return(shortUrl);
            }
            catch
            {
                return(null);
            }
        }
Esempio n. 8
0
 public BitlyProvider(string user, string apiKey)
 {
     _client = new BitlyService(user, apiKey);
 }
Esempio n. 9
0
 public BitlyClient()
 {
     _bitlyService = new BitlyService(_account, _apiKey);
 }
Esempio n. 10
0
        public static void SendTweet(string tweet, string appendUrl, SessionProperties sessionProperties)
        {
            if (TwitterService == null)
            {
                InitiateTwitterAuthentication(sessionProperties);
            }


            if (TwitterService == null)
            {
                WebControlManager.SendAndLogErrorMessage(new Exception("TwitterService not initialized"), Parameters.Instance.MailSender, Parameters.Instance.SupportMail);
                //clear authentication, guess we need to authenticate again?
                Parameters.Instance.TwitterAccessToken       = null;
                Parameters.Instance.TwitterAccessTokenSecret = null;
                return;
            }

            try
            {
                //format the string, replace
                if (tweet.Contains("&"))
                {
                    tweet = HttpUtility.HtmlDecode(tweet);
                }

                string shortUrl = String.Empty;
                //parse url to shorturl
                if (!String.IsNullOrEmpty(appendUrl))
                {
                    IBitlyService s = new BitlyService("o_3cpfcndji4", "R_8e203358cb5ca0f68d809419b056b192");

                    string shortened = s.Shorten(appendUrl);
                    if (shortened != null)
                    {
                        shortUrl = " " + shortened;
                    }
                }
                var maxLength = 140 - shortUrl.Length;
                if (tweet.Length > maxLength)
                {
                    tweet = tweet.Substring(0, maxLength);
                }

                tweet += shortUrl;

                TwitterService.SendTweet(new SendTweetOptions()
                {
                    Status = tweet
                });

                // Likely this is an error; we don't have to go fishing for it
                TwitterError    error    = TwitterService.Response.Error;
                TwitterResponse response = TwitterService.Response;
                if (error != null || response.StatusCode != HttpStatusCode.OK)
                {
                    // You now know you have a real error from Twitter, and can handle it
                    string message;
                    if (error != null)
                    {
                        message = String.Format("Twitter error: {0} ({1})", error.Message, error.Code);
                    }
                    else
                    {
                        message = String.Format("Twitter response status not ok: {0} ({1})\n{2}",
                                                response.StatusDescription, response.StatusCode, response.Response);
                    }
                    WebControlManager.SendAndLogErrorMessage(new Exception(message), Parameters.Instance.MailSender, Parameters.Instance.SupportMail);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }
Esempio n. 11
0
 public BitlyTests()
 {
     _bitlyService = new BitlyService("21392ff1718d0277e0b2b43ea4bc491902755911");
 }