diff --git a/SeatsioDotNet.Test/EventLog/ListEventLogItemsTest.cs b/SeatsioDotNet.Test/EventLog/ListEventLogItemsTest.cs new file mode 100644 index 0000000..98eb859 --- /dev/null +++ b/SeatsioDotNet.Test/EventLog/ListEventLogItemsTest.cs @@ -0,0 +1,37 @@ +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using Xunit; + +namespace SeatsioDotNet.Test.EventLog; + +public class ListEventLogItemsTest : SeatsioClientTest +{ + [Fact] + public void Test() + { + var chart = Client.Charts.Create(); + Client.Charts.Update(chart.Key, "a chart"); + + Thread.Sleep(2000); + + var eventLogItems = Client.EventLog.ListAll(); + + Assert.Equal(new[] {"chart.created", "chart.published"}, eventLogItems.Select(e => e.Type)); + } + + [Fact] + public void Properties() + { + var chart = Client.Charts.Create(); + + Thread.Sleep(2000); + + var eventLogItem = Client.EventLog.ListAll().ToList()[0]; + + Assert.True(eventLogItem.Id > 0); + Assert.Equal("chart.created", eventLogItem.Type); + Assert.Equal(Workspace.Key, eventLogItem.WorkspaceKey); + Assert.Equal(new Dictionary {{"key", chart.Key}}, eventLogItem.Data); + } +} \ No newline at end of file diff --git a/SeatsioDotNet/EventLog/EventLog.cs b/SeatsioDotNet/EventLog/EventLog.cs new file mode 100644 index 0000000..46518e3 --- /dev/null +++ b/SeatsioDotNet/EventLog/EventLog.cs @@ -0,0 +1,40 @@ +using System.Collections.Generic; +using RestSharp; +using SeatsioDotNet.Util; + +namespace SeatsioDotNet.EventLog; + +public class EventLog +{ + private readonly RestClient _restClient; + + public EventLog(RestClient restClient) + { + _restClient = restClient; + } + + public IEnumerable ListAll() + { + return ParametrizedList().All(); + } + + public Page ListFirstPage(int? pageSize = null) + { + return ParametrizedList().FirstPage(pageSize); + } + + public Page ListPageAfter(long id, int? pageSize = null) + { + return ParametrizedList().PageAfter(id, pageSize); + } + + public Page ListPageBefore(long id, int? pageSize = null) + { + return ParametrizedList().PageBefore(id, pageSize); + } + + private EventLogItemLister ParametrizedList() + { + return new EventLogItemLister(new PageFetcher(_restClient, "/event-log")); + } +} \ No newline at end of file diff --git a/SeatsioDotNet/EventLog/EventLogItem.cs b/SeatsioDotNet/EventLog/EventLogItem.cs new file mode 100644 index 0000000..267f97e --- /dev/null +++ b/SeatsioDotNet/EventLog/EventLogItem.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; + +namespace SeatsioDotNet.EventLog; + +public class EventLogItem +{ + public long Id { get; set; } + public string Type { get; set; } + public string WorkspaceKey { get; set; } + public DateTimeOffset Date { get; set; } + public Dictionary Data { get; set; } +} \ No newline at end of file diff --git a/SeatsioDotNet/EventLog/EventLogItemLister.cs b/SeatsioDotNet/EventLog/EventLogItemLister.cs new file mode 100644 index 0000000..af4dca1 --- /dev/null +++ b/SeatsioDotNet/EventLog/EventLogItemLister.cs @@ -0,0 +1,34 @@ +using System.Collections.Generic; +using SeatsioDotNet.Util; + +namespace SeatsioDotNet.EventLog; + +public class EventLogItemLister +{ + private readonly PageFetcher _pageFetcher; + + public EventLogItemLister(PageFetcher pageFetcher) + { + _pageFetcher = pageFetcher; + } + + public IEnumerable All() + { + return new PagedEnumerable(_pageFetcher, null); + } + + public Page FirstPage(int? pageSize = null) + { + return _pageFetcher.FetchFirstPage(null, pageSize); + } + + public Page PageAfter(long id, int? pageSize = null) + { + return _pageFetcher.FetchAfter(id, null, pageSize); + } + + public Page PageBefore(long id, int? pageSize = null) + { + return _pageFetcher.FetchBefore(id, null, pageSize); + } +} \ No newline at end of file diff --git a/SeatsioDotNet/SeatsioClient.cs b/SeatsioDotNet/SeatsioClient.cs index b6c48ce..253102c 100644 --- a/SeatsioDotNet/SeatsioClient.cs +++ b/SeatsioDotNet/SeatsioClient.cs @@ -22,6 +22,7 @@ public class SeatsioClient public Reports.Charts.ChartReports ChartReports { get; } public UsageReports UsageReports { get; } public Seasons.Seasons Seasons { get; } + public EventLog.EventLog EventLog { get; } private SeatsioRestClient RestClient; @@ -41,6 +42,7 @@ public SeatsioClient(string secretKey, string workspaceKey, string baseUrl) ChartReports = new Reports.Charts.ChartReports(RestClient); UsageReports = new UsageReports(RestClient); Seasons = new Seasons.Seasons(RestClient, this); + EventLog = new EventLog.EventLog(RestClient); } public SeatsioClient(Region region, string secretKey, string workspaceKey) : this(secretKey, workspaceKey,