예제 #1
0
        private static string GetEndpoint(AuthenticationAgent authAgent, string path)
        {
            var base_uri   = authAgent.userInfo.GetDefaultAccount().base_uri;
            var account_id = authAgent.userInfo.GetDefaultAccount().account_id;

            return(base_uri + string.Format(api_endpoint, account_id) + path);
        }
예제 #2
0
        public static async Task <HttpResponseMessage> SendRestRequest(AuthenticationAgent authAgent, HttpMethod method, string path, object body, Dictionary <string, string> query = null, bool logRequest = false, string contentType = @"text/csv")
        {
            //Load the headers
            Dictionary <string, string> headers = new Dictionary <string, string>()
            {
                { "Authorization", "Bearer " + authAgent.authToken.access_token }
            };
            //Create the endpoint
            string endpoint = GetEndpoint(authAgent, path);

            if (method != HttpMethod.Put)
            {
                //Convert the object to json
                var jsonSettings = new JsonSerializerSettings
                {
                    //Converters = { new FormatNumbersAsTextConverter() },
                    NullValueHandling = NullValueHandling.Ignore
                };
                string json = JsonConvert.SerializeObject(body, jsonSettings);

                if (logRequest)
                {
                    string prettyJson = JsonConvert.SerializeObject(body, Formatting.Indented, jsonSettings);
                    Console.WriteLine(prettyJson);
                }

                return(await HttpAgent.Request(method, endpoint, query, json, headers));
            }
            else
            {
                return(await HttpAgent.UploadFile(endpoint, (String)body, headers, contentType));
            }
        }