Skip to content

Commit

Permalink
Update APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
jaymell committed Nov 17, 2023
1 parent 30776fc commit 89ef4ba
Show file tree
Hide file tree
Showing 18 changed files with 1,022 additions and 62 deletions.
20 changes: 20 additions & 0 deletions csharp/Svix/Abstractions/IStatistics.cs
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();

}
}
101 changes: 101 additions & 0 deletions csharp/Svix/Statistics.cs
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;
}
}
}
}
5 changes: 4 additions & 1 deletion csharp/Svix/SvixClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public sealed class SvixClient : ISvixClient

public IMessageAttempt MessageAttempt { get; }

public IStatistics Statistics { get; }

public ILogger Logger { get; }

public string ServerUrl => _options?.ServerUrl;
Expand All @@ -44,7 +46,7 @@ public sealed class SvixClient : ISvixClient
public SvixClient(string token, ISvixOptions options, ILogger<SvixClient> logger = null
, IApplicationApi applicationApi = null, IAuthenticationApi authenticationApi = null, IEndpointApi endpointApi = null
, IEventTypeApi eventTypeApi = null, IHealthApi healthApi = null, IIntegrationApi integrationApi = null
, IMessageApi messageApi = null, IMessageAttemptApi messageAttemptApi = null)
, IMessageApi messageApi = null, IMessageAttemptApi messageAttemptApi = null, IStatisticsApi statisticsApi = null)
{
Logger = logger;
_options = options ?? throw new ArgumentNullException(nameof(options));
Expand All @@ -58,6 +60,7 @@ public SvixClient(string token, ISvixOptions options, ILogger<SvixClient> logger
Integration = new Integration(this, integrationApi ?? new IntegrationApi(Config));
Message = new Message(this, messageApi ?? new MessageApi(Config));
MessageAttempt = new MessageAttempt(this, messageAttemptApi ?? new MessageAttemptApi(Config));
Statistics = new Statistics(this, statisticsApi ?? new StatisticsApi(Config));
}

public SvixClient(string token, ISvixOptions options, ILogger<SvixClient> logger)
Expand Down
174 changes: 174 additions & 0 deletions go/internal/openapi/api_statistics.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 89ef4ba

Please sign in to comment.