Beispiel #1
0
 public static Uri Shortener(UrlShortenerServices service, string url)
 {
     HttpWebRequest req = CreateRequest (service, url);
     using (HttpWebResponse res = (HttpWebResponse)req.GetResponse ())
     using (Stream strm = res.GetResponseStream ())
     using (StreamReader reader = new StreamReader (strm, Encoding.ASCII)) {
          return ParseResponse (service, reader.ReadToEnd ().Trim ());
     }
 }
Beispiel #2
0
        public static Uri Shortener(UrlShortenerServices service, string url)
        {
            HttpWebRequest req = CreateRequest(service, url);

            using (HttpWebResponse res = (HttpWebResponse)req.GetResponse())
                using (Stream strm = res.GetResponseStream())
                    using (StreamReader reader = new StreamReader(strm, Encoding.ASCII)) {
                        return(ParseResponse(service, reader.ReadToEnd().Trim()));
                    }
        }
Beispiel #3
0
 static Uri ParseResponse(UrlShortenerServices service, string responseBody)
 {
     switch (service) {
         case UrlShortenerServices.tinyURL:
         case UrlShortenerServices.toly:
             return new Uri (responseBody);
         default:
             throw new ArgumentException ();
     }
 }
Beispiel #4
0
        static Uri ParseResponse(UrlShortenerServices service, string responseBody)
        {
            switch (service)
            {
            case UrlShortenerServices.tinyURL:
            case UrlShortenerServices.toly:
                return(new Uri(responseBody));

            default:
                throw new ArgumentException();
            }
        }
Beispiel #5
0
 static HttpWebRequest CreateRequest(UrlShortenerServices service, string url)
 {
     string requestUrl = null;
     switch (service) {
         case UrlShortenerServices.tinyURL:
             requestUrl = "http://tinyurl.com/api-create.php?url=" + OAuthBase.UrlEncode (url);
             break;
         case UrlShortenerServices.toly:
             requestUrl = "http://to.ly/api.php?longurl=" + OAuthBase.UrlEncode (url);
             break;
         default:
             throw new ArgumentException ();
     }
     return (HttpWebRequest)WebRequest.Create (requestUrl);
 }
Beispiel #6
0
        static HttpWebRequest CreateRequest(UrlShortenerServices service, string url)
        {
            string requestUrl = null;

            switch (service)
            {
            case UrlShortenerServices.tinyURL:
                requestUrl = "http://tinyurl.com/api-create.php?url=" + OAuthBase.UrlEncode(url);
                break;

            case UrlShortenerServices.toly:
                requestUrl = "http://to.ly/api.php?longurl=" + OAuthBase.UrlEncode(url);
                break;

            default:
                throw new ArgumentException();
            }
            return((HttpWebRequest)WebRequest.Create(requestUrl));
        }
Beispiel #7
0
 public static Uri Shortener(UrlShortenerServices service, Uri url)
 {
     return(Shortener(service, url.ToString()));
 }
Beispiel #8
0
 public static Uri Shortener(UrlShortenerServices service, Uri url)
 {
     return Shortener (service, url.ToString ());
 }