-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added methods to list event log items (#106)
- Loading branch information
Showing
5 changed files
with
126 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters