Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update libs with Statistics endpoints #1119

Merged
merged 3 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -9,7 +9,7 @@
{
public sealed class SvixClient : ISvixClient
{
protected Configuration Config => new Configuration

Check warning on line 12 in csharp/Svix/SvixClient.cs

View workflow job for this annotation

GitHub Actions / C# Lint

'SvixClient.Config.get': new protected member declared in sealed type

Check warning on line 12 in csharp/Svix/SvixClient.cs

View workflow job for this annotation

GitHub Actions / C# Lint

'SvixClient.Config': new protected member declared in sealed type
{
BasePath = ServerUrl,
AccessToken = Token
Expand All @@ -31,6 +31,8 @@

public IMessageAttempt MessageAttempt { get; }

public IStatistics Statistics { get; }

public ILogger Logger { get; }

public string ServerUrl => _options?.ServerUrl;
Expand All @@ -44,7 +46,7 @@
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 @@
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
Loading