private object RequestEndpoint(string endpoint, string method, object query, object body)
        {
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
            WebRequest request = this.httpHelper.GetWebRequest(endpoint, method, query);

            request.Headers.Add("Authorization", string.Format("Bearer {0}", this.token));
            request.Headers.Add("api-sdk", string.Format("dotnet-{0}", Version));
            if (partnerToken != null)
            {
                request.Headers.Add("partner-token", this.partnerToken);
            }

            try
            {
                //return httpHelper.SendRequestNoJsonObject(request, body);
                return(httpHelper.SendRequest(request, body));
            }
            catch (WebException e)
            {
                if (e.Response != null && (e.Response is HttpWebResponse))
                {
                    var          statusCode = (int)((HttpWebResponse)e.Response).StatusCode;
                    StreamReader reader     = new StreamReader(e.Response.GetResponseStream());
                    throw GnException.Build(reader.ReadToEnd(), statusCode);
                }
                else
                {
                    throw GnException.Build("", 500);
                }
            }
        }
        private object RequestEndpoint(string endpoint, string method, object query, object body)
        {
            WebRequest request = this.httpHelper.GetWebRequest(endpoint, method, query);

            request.Headers.Add("Authorization", string.Format("Bearer {0}", this.token));
            request.Headers.Add("api-sdk", string.Format("dotnet-{0}", Version));

            try
            {
                return(httpHelper.SendRequest(request, body));
            }
            catch (WebException e)
            {
                if (e.Response != null && (e.Response is HttpWebResponse))
                {
                    var          statusCode = (int)((HttpWebResponse)e.Response).StatusCode;
                    StreamReader reader     = new StreamReader(e.Response.GetResponseStream());
                    throw GnException.Build(reader.ReadToEnd(), statusCode);
                }
                else
                {
                    throw GnException.Build("", 500);
                }
            }
        }
Example #3
0
        private void Authenticate()
        {
            object body = new {
                grant_type = "client_credentials"
            };

            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
            var request     = HttpHelper.GetWebRequest("/authorize", "post", null);
            var credentials = string.Format("{0}:{1}", ClientId, ClientSecret);
            var encodedAuth = Convert.ToBase64String(Encoding.GetEncoding("UTF-8").GetBytes(credentials));

            request.Headers.Add("Authorization", string.Format("Basic {0}", encodedAuth));
            request.Headers.Add("api-sdk", string.Format("dotnet-core-{0}", version));

            try {
                var response = HttpHelper.SendRequest(request, body);
                Token = response.access_token;
            } catch (WebException) {
                throw GnException.Build("", 401);
            }
        }