Ejemplo n.º 1
0
        /// <inheritdoc />
        public async Task <PlaidResult <ItemResponse> > UpdateWebHookAsync(string accessToken, string webhook)
        {
            //conditions
            Condition.Requires(accessToken).IsNotNullOrWhiteSpace();
            Condition.Requires(webhook).IsNotNullOrWhiteSpace();

            //create the payload to pass
            var payload = new UpdateWebHookRequest(clientId, clientSecret, accessToken, webhook);

            //serialize object
            HttpContent content = ContentExtensions.ToJsonContent(payload);

            //post it and get the response
            HttpResponseMessage response = await this.httpClient.PostAsync(PlaidInformation.ItemManagement_UpdateWebhook, content);

            //read the string
            string responseJson = await response.Content.ReadAsStringAsync();

            //create the result
            PlaidResult <ItemResponse> result = new PlaidResult <ItemResponse>(responseJson);

            //is it ok
            if (response.StatusCode == HttpStatusCode.OK)
            {
                ItemResponse itemResponse = JsonConvert.DeserializeObject <ItemResponse>(responseJson);
                result.Value = itemResponse;
            }

            //parse the exception
            result.Exception = await this.ParseException(response, responseJson);

            //return
            return(result);
        }
        public async Task Can_update_webhook()
        {
            var request  = CreateAddWebHookRequest();
            var response = await _publisherClient.PostAsJson(request, "hooks");

            var webHookUri = $"hooks/{response.Headers.Location}";

            var addWebHook = new UpdateWebHookRequest
            {
                PayloadTargetUri   = new Uri("http://example.com/sink2"),
                Enabled            = false,
                SubscribeToEvents  = new[] { "baz" },
                SubscriptionChoice = SubscriptionChoice.Everything,
                Secret             = ""
            };

            await _publisherClient.PostAsJson(addWebHook, webHookUri);

            response = await _publisherClient.GetAsync(webHookUri);

            var webHook = await response.Content.ReadAs <WebHook>();

            webHook.Enabled.ShouldBe(addWebHook.Enabled);
            webHook.HasSecret.ShouldBeFalse();
            webHook.PayloadTargetUri.ShouldBe(addWebHook.PayloadTargetUri);
            webHook.SubscribeToEvents.ShouldBe(addWebHook.SubscribeToEvents);
            webHook.CreatedUtc.ShouldBeGreaterThan(DateTime.MinValue);
            webHook.UpdatedUtc.ShouldBeGreaterThan(DateTime.MinValue);
            webHook.SubscriptionChoice.ShouldBe((int)addWebHook.SubscriptionChoice);
        }
        public async Task When_update_non_existent_webhook_then_should_get_not_found()
        {
            var webHookUri = $"hooks/{Guid.NewGuid()}";

            var addWebHook = new UpdateWebHookRequest
            {
                PayloadTargetUri   = new Uri("http://example.com/sink2"),
                Enabled            = false,
                SubscribeToEvents  = new[] { "baz" },
                SubscriptionChoice = SubscriptionChoice.Everything,
                Secret             = ""
            };
            var response = await _publisherClient.PostAsJson(addWebHook, webHookUri);

            response.StatusCode.ShouldBe(HttpStatusCode.NotFound);
        }