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 ()); } }
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())); } }
static Uri ParseResponse(UrlShortenerServices service, string responseBody) { switch (service) { case UrlShortenerServices.tinyURL: case UrlShortenerServices.toly: return new Uri (responseBody); default: throw new ArgumentException (); } }
static Uri ParseResponse(UrlShortenerServices service, string responseBody) { switch (service) { case UrlShortenerServices.tinyURL: case UrlShortenerServices.toly: return(new Uri(responseBody)); default: throw new ArgumentException(); } }
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); }
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)); }
public static Uri Shortener(UrlShortenerServices service, Uri url) { return(Shortener(service, url.ToString())); }
public static Uri Shortener(UrlShortenerServices service, Uri url) { return Shortener (service, url.ToString ()); }