예제 #1
0
        public async Task <AccountResponse> GetAccountDetailsById(string accountId)
        {
            AccountResponse accounResponse = await
                                             this.HttpRequestClient.ExecuteAccountRequest(accountId);

            return(accounResponse);
        }
예제 #2
0
        // Get the account details the user
        public async Task <AccountResponse> ExecuteAccountRequest(string accountId, bool executeWithANewToken = false)
        {
            // Check if the token is present in the global variable or when executeWithANewToken is true
            if (this.BearerToken == null || executeWithANewToken == true)
            {
                this.BearerToken = await ExecuteBearerTokenRequest();
            }

            try
            {
                SetRequestHeaders();

                // Make an Http request to retrieve user account information
                HttpResponseMessage response = await HttpClient.GetAsync($"{this.Constant.BaseUrl}/Accounts/{accountId}");

                response.EnsureSuccessStatusCode();

                // Cast the Json response to our custom data type
                AccountResponse accounResponse = await response.Content.ReadAsAsync <AccountResponse>();

                return(accounResponse);
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("401"))
                {
                    // Repeat the execution but with a new bearer token
                    AccountResponse accountResultsWithNewToken = await ExecuteAccountRequest(accountId, true);

                    return(accountResultsWithNewToken);
                }
                else if (ex.Message.Contains("400"))
                {
                    // Incorrect account ID (Bad Request)
                    throw new XenteIncorrectRequestException("Incorrect Account ID Provided");
                }
                else
                {
                    throw new XenteConnectionException(ex.Message);
                }
            }
        }