Exemplo n.º 1
0
        private void AddCredentials(IPlaidRequest request)
        {
            if (request is IHasClientId clientReq)
            {
                if (string.IsNullOrEmpty(clientReq.ClientId))
                {
                    clientReq.ClientId = ClientId;
                }
            }

            if (request is IHasSecret secretReq)
            {
                if (string.IsNullOrEmpty(secretReq.Secret))
                {
                    secretReq.Secret = Secret;
                }
            }

            if (request is IHasPublicKey pkReq)
            {
                if (string.IsNullOrEmpty(pkReq.PublicKey))
                {
                    pkReq.PublicKey = PublicKey;
                }
            }
        }
Exemplo n.º 2
0
        public async Task <TResponse> PostAsync <TResponse>(IPlaidRequest request) where TResponse : IPlaidResponse
        {
            AddCredentials(request);
#if DEBUG
            System.Diagnostics.Debug.WriteLine(request.ToJson());
#endif
            var content = new StringContent(request.ToJson(), System.Text.Encoding.UTF8, "application/json");

            var req = new HttpRequestMessage(HttpMethod.Post, request.Endpoint)
            {
                Content = content
            };
            var response = await client.SendAsync(req);

            if (!response.IsSuccessStatusCode)
            {
                var responseContent = await response.Content.ReadAsStringAsync();

#if DEBUG
                System.Diagnostics.Debug.WriteLine(responseContent);
#endif
                var error = JsonConvert.DeserializeObject <Error.ErrorResponse>(responseContent);
                throw new PlaidException(error);
            }

            return(JsonConvert.DeserializeObject <TResponse>(await response.Content.ReadAsStringAsync()));
        }