Ejemplo n.º 1
0
        private static async Task <SuccessResponse <T> > GetAndPrint <T>(string[] paths, Dictionary <string, string> queryStringParameters = null)
        {
            var queryRequest = GetRequest(paths, queryStringParameters);

            Console.WriteLine($"GET {queryRequest.Url}");

            var queryResult = await queryRequest.GetStringAsync();

            SuccessResponse <T> result = JsonConvert.DeserializeObject <SuccessResponse <T> >(queryResult);

            Console.WriteLine(JsonConvert.DeserializeObject(queryResult));
            Console.WriteLine("\r\nPress any key to continue\r\n");
            Console.ReadKey();
            return(result);
        }
Ejemplo n.º 2
0
        private static async Task <SuccessResponse <T> > VerbAndPrint <T>(HttpMethod verb, string[] paths, Dictionary <string, string> bodyParameters = null)
        {
            var queryRequest = GetRequest(paths);
            HttpResponseMessage queryResult = null;
            SuccessResponse <T> result      = null;

            if (verb == HttpMethod.Post)
            {
                queryResult = await queryRequest.PostJsonAsync(bodyParameters);
            }
            else if (verb == new HttpMethod("PATCH"))
            {
                queryResult = await queryRequest.PatchJsonAsync(bodyParameters);
            }
            else if (verb == HttpMethod.Delete)
            {
                queryResult = await queryRequest.DeleteAsync();
            }
            //todo put is not implemented

            if (queryResult != null)
            {
                Console.WriteLine($"{verb} {queryRequest.Url}");
                var responseString = await queryResult.Content.ReadAsStringAsync();

                result = JsonConvert.DeserializeObject <SuccessResponse <T> >(responseString);
                Console.WriteLine(JsonConvert.DeserializeObject(responseString));
            }
            else
            {
                Console.WriteLine($"{verb} is not supported");
            }

            Console.WriteLine("\r\nPress any key to continue\r\n");
            Console.ReadKey();
            return(result);
        }