/// <summary>
        /// Posts an object and gets a fully qualified response
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <typeparam name="R"></typeparam>
        /// <param name="path"></param>
        /// <param name="content"></param>
        /// <returns></returns>
        public async Task <BaseResponse <R> > Post <T, R>(string path, T content)
        {
            var URL           = this._Host + path;
            var contentString = JsonConvert.SerializeObject(content, HttpClientHelpers.SerializerSettings());
            var sContent      = new StringContent(contentString, Encoding.UTF8, "application/json");
            var response      = await _Client.PostAsync(URL, sContent);

            var result = await response.Content.ReadAsStringAsync();

            return(DeserializeResponse <BaseResponse <R> >(result));
        }
Exemple #2
0
        /// <summary>
        /// Returns the string message from an HttpResponseMessage
        /// </summary>
        /// <param name="response"></param>
        /// <returns></returns>
        public static async Task <string> GetMessage(this HttpResponseMessage response)
        {
            var result = await response.Content.ReadAsStringAsync();

            try
            {
                //Try and convert the string to a Base REsponse so we can get the errors
                var obj = JsonConvert.DeserializeObject <BaseResponse <string> >(result, HttpClientHelpers.SerializerSettings());

                return(string.Join("\r\n", obj.errors.Select(e => e.Description).ToArray()));
            }
            catch
            {
                return(result);
            }
        }
Exemple #3
0
        private T DeserializeResponse <T>(string response)
        {
            var item = JsonConvert.DeserializeObject <T>(response, HttpClientHelpers.SerializerSettings());

            return(item);
        }