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); }
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); }
public void CreateRandomUrl() { BitlyService service = new BitlyService(); Regex regex = new Regex(@"^[A-Za-z]{8}$"); Boolean match = regex.IsMatch(service.GetRandomUrlEndpoint()); Assert.True(match); }
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); }
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); }
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); }
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); } }
public BitlyProvider(string user, string apiKey) { _client = new BitlyService(user, apiKey); }
public BitlyClient() { _bitlyService = new BitlyService(_account, _apiKey); }
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); } }
public BitlyTests() { _bitlyService = new BitlyService("21392ff1718d0277e0b2b43ea4bc491902755911"); }