-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
1,022 additions
and
62 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,20 @@ | ||
using System.Collections.Generic; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Svix.Model; | ||
using Svix.Models; | ||
|
||
namespace Svix.Abstractions | ||
{ | ||
public interface IStatistics | ||
{ | ||
AppUsageStatsOut CalculateAggregateAppStats(AppUsageStatsIn appUsageStatsIn, string idempotencyKey = default); | ||
|
||
Task<AppUsageStatsOut> CalculateAggregateAppStatsAsync(AppUsageStatsIn appUsageStatsIn, string idempotencyKey = default); | ||
|
||
AggregateEventTypesOut AggregateEventTypes(); | ||
|
||
Task<AggregateEventTypesOut> AggregateEventTypesAsync(); | ||
|
||
} | ||
} |
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,101 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.Logging; | ||
using Svix.Abstractions; | ||
using Svix.Api; | ||
using Svix.Client; | ||
using Svix.Model; | ||
|
||
namespace Svix | ||
{ | ||
public sealed class Statistics : SvixResourceBase, IStatistics | ||
{ | ||
private readonly IStatisticsApi _statisticsApi; | ||
|
||
public Statistics(ISvixClient svixClient, IStatisticsApi statisticsApi) | ||
: base(svixClient) | ||
{ | ||
_statisticsApi = statisticsApi ?? throw new ArgumentNullException(nameof(statisticsApi)); | ||
} | ||
|
||
public AppUsageStatsOut CalculateAggregateAppStats(AppUsageStatsIn appUsageStatsIn, string idempotencyKey = default) | ||
{ | ||
try | ||
{ | ||
var res = _statisticsApi.CalculateAggregateAppStats( | ||
appUsageStatsIn, | ||
idempotencyKey); | ||
|
||
return res; | ||
} | ||
catch (ApiException e) | ||
{ | ||
Logger?.LogError(e, $"{nameof(CalculateAggregateAppStats)} failed"); | ||
|
||
if (Throw) | ||
throw; | ||
|
||
return null; | ||
} | ||
} | ||
|
||
public async Task<AppUsageStatsOut> CalculateAggregateAppStatsAsync(AppUsageStatsIn appUsageStatsIn, string idempotencyKey = default) | ||
{ | ||
try | ||
{ | ||
var res = await _statisticsApi.CalculateAggregateAppStatsAsync( | ||
appUsageStatsIn, | ||
idempotencyKey); | ||
|
||
return res; | ||
} | ||
catch (ApiException e) | ||
{ | ||
Logger?.LogError(e, $"{nameof(CalculateAggregateAppStatsAsync)} failed"); | ||
|
||
if (Throw) | ||
throw; | ||
|
||
return null; | ||
} | ||
} | ||
|
||
public AggregateEventTypesOut AggregateEventTypes() | ||
{ | ||
try | ||
{ | ||
var res = _statisticsApi.AggregateEventTypes(); | ||
|
||
return res; | ||
} | ||
catch (ApiException e) | ||
{ | ||
Logger?.LogError(e, $"{nameof(CalculateAggregateAppStatsAsync)} failed"); | ||
|
||
if (Throw) | ||
throw; | ||
|
||
return null; | ||
} | ||
} | ||
|
||
public async Task<AggregateEventTypesOut> AggregateEventTypesAsync() | ||
{ | ||
try | ||
{ | ||
var res = await _statisticsApi.AggregateEventTypesAsync(); | ||
|
||
return res; | ||
} | ||
catch (ApiException e) | ||
{ | ||
Logger?.LogError(e, $"{nameof(CalculateAggregateAppStatsAsync)} failed"); | ||
|
||
if (Throw) | ||
throw; | ||
|
||
return null; | ||
} | ||
} | ||
} | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.