Example #1
0
        public async Task <Account> CreateAsync(Account account)
        {
            var memoryStream = new MemoryStream();
            var xmlWriter    = XmlWriter.Create(memoryStream);

            account.WriteXml(xmlWriter, "account");

            var requestUri = _requestFactory.MakeRequestUri(URL_PREFIX);
            var result     = await _requestFactory.SendXmlPostRequestAsync(requestUri, memoryStream).ConfigureAwait(false);

            if (result.StatusCode == HttpStatusCode.OK)
            {
                return(await Account.CreateFromReaderAsync(result.ResponseReader, requestUri).ConfigureAwait(false));
            }

            throw result.Exception ?? new Exception("Not sure what happened!");
        }
Example #2
0
        public async Task <Account> GetAsync(string accountCode)
        {
            var requestUri = _requestFactory.MakeRequestUri(URL_PREFIX, Uri.EscapeDataString(accountCode));

            using (var result = await _requestFactory.SendXmlGetRequestAsync(requestUri).ConfigureAwait(false))
            {
                switch (result.StatusCode)
                {
                case HttpStatusCode.NotFound:
                    return(Account.NotFound);

                case HttpStatusCode.OK:
                    var account = await Account.CreateFromReaderAsync(result.ResponseReader, requestUri).ConfigureAwait(false);

                    return(account);

                default:
                    throw result.Exception ?? new Exception("Not sure what happened!");
                }
            }
        }