public ExternalToken GetRefreshToken(string authCode, string redirectUri)
        {
            var tokenFromGoogle = jsonConverter.Deserilize <GoogleApiTokenResponse>(this.GetRestRefreshToken(authCode, redirectUri));

            if (!string.IsNullOrEmpty(tokenFromGoogle.refresh_token))
            {
                var refreshToken = new ExternalToken
                {
                    AccessToken    = tokenFromGoogle.refresh_token,
                    ExpirationDate = serverTime.RequestStarted.AddYears(100),
                    Type           = "Google_Refresh_Token"
                };
                externalTokenRepository.Add(refreshToken);
            }

            var accessToken = new ExternalToken
            {
                AccessToken    = tokenFromGoogle.access_token,
                Type           = "Google_Access_Token",
                ExpirationDate = serverTime.RequestStarted.AddSeconds(tokenFromGoogle.expires_in)
            };

            externalTokenRepository.Add(accessToken);
            externalTokenRepository.SaveChanges();

            return(externalTokenRepository.First(et => et.Type == "Google_Refresh_Token"));
        }
        public string GetShortUrl(string longUrl)
        {
            WebRequest request = WebRequest.Create("https://www.googleapis.com/urlshortener/v1/url?key=" + googleApiKey);

            request.Method      = "POST";
            request.ContentType = "application/json";
            var jsonData = jsonCoverter.Serilize(new GoogleUrlShortnerMessage {
                longUrl = longUrl
            });
            string requestData = jsonData;

            byte[] requestRawData = Encoding.ASCII.GetBytes(requestData);
            request.ContentLength = requestRawData.Length;
            Stream requestStream = request.GetRequestStream();

            requestStream.Write(requestRawData, 0, requestRawData.Length);
            requestStream.Close();

            WebResponse  response       = request.GetResponse();
            StreamReader responseReader = new StreamReader(response.GetResponseStream());
            string       responseData   = responseReader.ReadToEnd();

            responseReader.Close();

            var shortnerResult = jsonCoverter.Deserilize <GoogleUrlShortnerResponse>(responseData);

            return(shortnerResult.id);
        }