public override UploadResult ShortenURL(string url)
        {
            UploadResult result = new UploadResult {
                URL = url
            };

            string json = JsonConvert.SerializeObject(new
            {
                url = url
            });

            string response = SendRequest(HttpMethod.POST, "https://api.zws.im", json, RequestHelpers.ContentTypeJSON);

            if (!string.IsNullOrEmpty(response))
            {
                ZeroWidthURLShortenerResponse jsonResponse = JsonConvert.DeserializeObject <ZeroWidthURLShortenerResponse>(response);

                if (jsonResponse != null)
                {
                    if (!string.IsNullOrEmpty(jsonResponse.URL))
                    {
                        result.ShortenedURL = jsonResponse.URL;
                    }
                    else
                    {
                        result.ShortenedURL = URLHelpers.CombineURL("https://zws.im", jsonResponse.Short);
                    }
                }
            }

            return(result);
        }
Beispiel #2
0
        public override UploadResult ShortenURL(string url)
        {
            UploadResult result = new UploadResult {
                URL = url
            };

            Dictionary <string, string> args = new Dictionary <string, string>();

            args.Add("url", url);

            string response = SendRequest(HttpMethod.GET, "https://us-central1-zero-width-shortener.cloudfunctions.net/shortenURL", args);

            if (!string.IsNullOrEmpty(response))
            {
                ZeroWidthURLShortenerResponse jsonResponse = JsonConvert.DeserializeObject <ZeroWidthURLShortenerResponse>(response);

                if (jsonResponse != null)
                {
                    result.ShortenedURL = URLHelpers.CombineURL("https://zws.im", jsonResponse.Short);
                }
            }

            return(result);
        }