/// <inheritdoc/>
        public HttpResponse GetResponse(HttpRequest request)
        {
            Preconditions.NotNull("request", request);

            var urlBuilder = new UrlBuilder().Url(request.Url);

            if (request.QueryString != null)
            {
                foreach (var item in request.QueryString)
                {
                    urlBuilder.AddParameter(item.Key, item.Value);
                }
            }

            var url = urlBuilder.Build();

            var httpRequest = (HttpWebRequest)WebRequest.Create(url);

            httpRequest.KeepAlive = true;
            httpRequest.Method = request.Method;
            httpRequest.UserAgent = UserAgentString;

            MapHeaders(request, httpRequest);

            try
            {
                WriteRequestBody(request, httpRequest);
                return GetResponse(httpRequest);
            }
            catch (Exception ex)
            {
                var message = string.Format(
                    "Failed to get a response to the request - {0}",
                    ex.Message);
                throw new CronofyException(message, ex);
            }
        }
            /// <summary>
            /// Generates an authorization URL based on the current state of the
            /// builder.
            /// </summary>
            /// <returns>
            /// An authorization URL based on the current state of the builder.
            /// </returns>
            public string Build()
            {
                var authUrl = this.enterpriseConnect ? EnterpriseConnectAuthorizationUrl : AuthorizationUrl;

                var urlBuilder = new UrlBuilder()
                    .Url(authUrl)
                    .AddParameter("client_id", this.clientId)
                    .AddParameter("response_type", "code")
                    .AddParameter("redirect_uri", this.redirectUri);

                if (this.enterpriseConnect)
                {
                    urlBuilder.AddParameter("delegated_scope", string.Join(" ", this.scope));
                    urlBuilder.AddParameter("scope", string.Join(" ", this.enterpriseConnectScope));
                }
                else
                {
                    urlBuilder.AddParameter("scope", string.Join(" ", this.scope));
                }

                if (this.state != null)
                {
                    urlBuilder.AddParameter("state", this.state);
                }

                if (this.avoidLinking.HasValue)
                {
                    urlBuilder.AddParameter("avoid_linking", this.avoidLinking.Value);
                }

                return urlBuilder.Build();
            }