Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix webhook events due to breaking change in the API #130

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/Moneybird.Net/Entities/Webhooks/Webhook.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text.Json.Serialization;

Expand All @@ -13,9 +14,13 @@ public class Webhook : IMoneybirdEntity

[JsonPropertyName("url")]
public string Url { get; set; }


[Obsolete("Use EnabledEvents instead as this attribute will be removed from the API on 1st of January 2025.")]
[JsonPropertyName("events")]
public List<WebhookEvent> Events { get; set; }

[JsonPropertyName("enabled_events")]
public List<WebhookEvent> EnabledEvents { get; set; }

[JsonPropertyName("last_http_status")]
public int? LastHttpStatus { get; set; }
Expand Down
7 changes: 6 additions & 1 deletion src/Moneybird.Net/Models/Webhooks/WebhookCreateOptions.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text.Json.Serialization;
using Moneybird.Net.Endpoints.Abstractions.Options;
Expand All @@ -10,7 +11,11 @@ public class WebhookCreateOptions : IMoneybirdCreateOptions
[JsonPropertyName("url")]
public string Url { get; set; }

[JsonPropertyName("events")]
[Obsolete("Use EnabledEvents instead as this attribute has been removed from the API.", true)]
[JsonIgnore]
public List<WebhookEvent> Events { get; set; }

[JsonPropertyName("enabled_events")]
public List<WebhookEvent> EnabledEvents { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
}

[Fact]
public async void GetWebhooksAsync_ByAccessToken_Returns_WebhookList()

Check warning on line 33 in tests/Moneybird.Net.Tests/Endpoints/WebhookEndpointTests.cs

View workflow job for this annotation

GitHub Actions / build

Support for 'async void' unit tests is being removed from xUnit.net v3. To simplify upgrading, convert the test to 'async Task' instead. (https://xunit.net/xunit.analyzers/rules/xUnit1048)
{
var webhookListJson = await File.ReadAllTextAsync(GetWebhooksResponsePath);

Expand Down Expand Up @@ -60,7 +60,7 @@
var options = new WebhookCreateOptions
{
Url = "http://www.mocky.io/v2/5185415ba171ea3a00704eed",
Events = new List<WebhookEvent>
EnabledEvents = new List<WebhookEvent>
{
WebhookEvent.ContactCreated
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"administration_id": "322056713748350877",
"url": "http://example.com/create_webhook",
"events": [],
"enabled_events": [],
"last_http_status": null,
"last_http_body": null,
"token": "9AqXyhfFXcqcaGHRWQZMbxuM"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"id": "392975655294207773",
"administration_id": "322056713748350877",
"url": "http://www.mocky.io/v2/5185415ba171ea3a00704eed",
"events": [],
"enabled_events": [],
"last_http_status": null,
"last_http_body": null,
"token": "YTVsrb3MLhMDgkQcc81MgHvE"
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"url":"http://www.mocky.io/v2/5185415ba171ea3a00704eed","events":["contact_created"]}
{"url":"http://www.mocky.io/v2/5185415ba171ea3a00704eed","enabled_events":["contact_created"]}
Loading