예제 #1
0
        private async Task <T> GetResponse <T>(string requestUri)
        {
            Debug.WriteLine(requestUri);
            var response = await client.GetAsync(requestUri).ConfigureAwait(false);

            if (!response.IsSuccessStatusCode)
            {
                Trace.TraceError(response.Content.ReadAsStringAsync().Result);
                var errorInfo = await ConvertFromResponse <ErrorInfo>(response);

                if (errorInfo != null)
                {
                    throw OandaApiException.FromErrorInfo(errorInfo);
                }
                response.EnsureSuccessStatusCode();
            }
            return(await ConvertFromResponse <T>(response));
        }
예제 #2
0
        private async Task <T> PostResponse <T>(string requestUri, IEnumerable <KeyValuePair <string, string> > namedValueCollection)
        {
            Debug.WriteLine(requestUri);
            HttpContent content  = new FormUrlEncodedContent(namedValueCollection);
            var         response = await client.PostAsync(requestUri, content).ConfigureAwait(false);

            if (!response.IsSuccessStatusCode)
            {
                Trace.TraceError(response.Content.ReadAsStringAsync().Result);
                var errorInfo = await ConvertFromResponse <ErrorInfo>(response);

                if (errorInfo != null)
                {
                    throw OandaApiException.FromErrorInfo(errorInfo);
                }
                response.EnsureSuccessStatusCode();
            }
            return(await ConvertFromResponse <T>(response));
        }