Skip to content

Commit

Permalink
Added methods to list event log items (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
mroloux authored Jan 17, 2024
1 parent 27c29b0 commit 6273cc7
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 0 deletions.
37 changes: 37 additions & 0 deletions SeatsioDotNet.Test/EventLog/ListEventLogItemsTest.cs
Original file line number Diff line number Diff line change
@@ -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<string, object> {{"key", chart.Key}}, eventLogItem.Data);
}
}
40 changes: 40 additions & 0 deletions SeatsioDotNet/EventLog/EventLog.cs
Original file line number Diff line number Diff line change
@@ -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<EventLogItem> ListAll()
{
return ParametrizedList().All();
}

public Page<EventLogItem> ListFirstPage(int? pageSize = null)
{
return ParametrizedList().FirstPage(pageSize);
}

public Page<EventLogItem> ListPageAfter(long id, int? pageSize = null)
{
return ParametrizedList().PageAfter(id, pageSize);
}

public Page<EventLogItem> ListPageBefore(long id, int? pageSize = null)
{
return ParametrizedList().PageBefore(id, pageSize);
}

private EventLogItemLister ParametrizedList()
{
return new EventLogItemLister(new PageFetcher<EventLogItem>(_restClient, "/event-log"));
}
}
13 changes: 13 additions & 0 deletions SeatsioDotNet/EventLog/EventLogItem.cs
Original file line number Diff line number Diff line change
@@ -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<string, object> Data { get; set; }
}
34 changes: 34 additions & 0 deletions SeatsioDotNet/EventLog/EventLogItemLister.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System.Collections.Generic;
using SeatsioDotNet.Util;

namespace SeatsioDotNet.EventLog;

public class EventLogItemLister
{
private readonly PageFetcher<EventLogItem> _pageFetcher;

public EventLogItemLister(PageFetcher<EventLogItem> pageFetcher)
{
_pageFetcher = pageFetcher;
}

public IEnumerable<EventLogItem> All()
{
return new PagedEnumerable<EventLogItem>(_pageFetcher, null);
}

public Page<EventLogItem> FirstPage(int? pageSize = null)
{
return _pageFetcher.FetchFirstPage(null, pageSize);
}

public Page<EventLogItem> PageAfter(long id, int? pageSize = null)
{
return _pageFetcher.FetchAfter(id, null, pageSize);
}

public Page<EventLogItem> PageBefore(long id, int? pageSize = null)
{
return _pageFetcher.FetchBefore(id, null, pageSize);
}
}
2 changes: 2 additions & 0 deletions SeatsioDotNet/SeatsioClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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,
Expand Down

0 comments on commit 6273cc7

Please sign in to comment.