Esempio n. 1
0
        /// <summary>
        /// Expands a short URL or gets creation time and analytics.
        /// Documentation https://developers.google.com/urlshortener/v1/reference/url/get
        /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
        /// </summary>
        /// <param name="service">Authenticated urlshortener service.</param>
        /// <param name="shortUrl">The short URL, including the protocol.</param>
        /// <param name="optional">Optional paramaters.</param>        /// <returns>UrlResponse</returns>
        public static Url Get(urlshortenerService service, string shortUrl, UrlGetOptionalParms optional = null)
        {
            try
            {
                // Initial validation.
                if (service == null)
                {
                    throw new ArgumentNullException("service");
                }
                if (shortUrl == null)
                {
                    throw new ArgumentNullException(shortUrl);
                }

                // Building the initial request.
                var request = service.Url.Get(shortUrl);

                // Applying optional parameters to the request.
                request = (UrlResource.GetRequest)SampleHelpers.ApplyOptionalParms(request, optional);

                // Requesting data.
                return(request.Execute());
            }
            catch (Exception ex)
            {
                throw new Exception("Request Url.Get failed.", ex);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Creates a new short URL.
        /// Documentation https://developers.google.com/urlshortener/v1/reference/url/insert
        /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
        /// </summary>
        /// <param name="service">Authenticated urlshortener service.</param>
        /// <param name="body">A valid urlshortener v1 body.</param>
        /// <returns>UrlResponse</returns>
        public static Url Insert(urlshortenerService service, Url body)
        {
            try
            {
                // Initial validation.
                if (service == null)
                {
                    throw new ArgumentNullException("service");
                }
                if (body == null)
                {
                    throw new ArgumentNullException("body");
                }

                // Make the request.
                return(service.Url.Insert(body).Execute());
            }
            catch (Exception ex)
            {
                throw new Exception("Request Url.Insert failed.", ex);
            }
        }