Skip to content

Commit

Permalink
feat(clients): helper to switch API key in use (generated)
Browse files Browse the repository at this point in the history
algolia/api-clients-automation#3616

Co-authored-by: algolia-bot <accounts+algolia-api-client-bot@algolia.com>
Co-authored-by: Thomas Raffray <Fluf22@users.noreply.github.com>
Co-authored-by: Pierre Millot <pierre.millot@algolia.com>
  • Loading branch information
3 people committed Sep 6, 2024
1 parent ba7afea commit 2da109e
Show file tree
Hide file tree
Showing 12 changed files with 133 additions and 12 deletions.
13 changes: 12 additions & 1 deletion algoliasearch/Clients/AbtestingClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ public interface IAbtestingClient
/// </summary>
public partial class AbtestingClient : IAbtestingClient
{
private readonly HttpTransport _transport;
internal HttpTransport _transport;
private readonly ILogger<AbtestingClient> _logger;

/// <summary>
Expand Down Expand Up @@ -382,6 +382,17 @@ public AbtestingClient(AbtestingConfig config, IHttpRequester httpRequester, ILo
}
}

/// <summary>
/// Helper to switch the API key sent with each request
/// </summary>
/// <param name="apiKey">Your new API Key</param>
/// <returns></returns>
public void SetClientApiKey(string apiKey)
{
_transport._algoliaConfig.SetClientApiKey(apiKey);
}



/// <inheritdoc />
public async Task<ABTestResponse> AddABTestsAsync(AddABTestsRequest addABTestsRequest, RequestOptions options = null, CancellationToken cancellationToken = default)
Expand Down
13 changes: 12 additions & 1 deletion algoliasearch/Clients/AlgoliaConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ protected AlgoliaConfig(string appId, string apiKey, string clientName, string c
/// The admin API Key
/// </summary>
/// <returns></returns>
public string ApiKey { get; }
public string ApiKey { get; set; }

/// <summary>
/// Configurations hosts
Expand Down Expand Up @@ -97,5 +97,16 @@ internal Dictionary<string, string> BuildHeaders()
DefaultHeaders[Defaults.UserAgentHeader.ToLowerInvariant()] = UserAgent.ToString();
return DefaultHeaders;
}

/// <summary>
/// Helper to switch the API key sent with each request
/// </summary>
/// <param name="apiKey">Your API Key</param>
/// <returns></returns>
public void SetClientApiKey(string apiKey)
{
ApiKey = apiKey;
DefaultHeaders[Defaults.AlgoliaApiKeyHeader.ToLowerInvariant()] = apiKey;
}
}
}
13 changes: 12 additions & 1 deletion algoliasearch/Clients/AnalyticsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,7 @@ public interface IAnalyticsClient
/// </summary>
public partial class AnalyticsClient : IAnalyticsClient
{
private readonly HttpTransport _transport;
internal HttpTransport _transport;
private readonly ILogger<AnalyticsClient> _logger;

/// <summary>
Expand Down Expand Up @@ -964,6 +964,17 @@ public AnalyticsClient(AnalyticsConfig config, IHttpRequester httpRequester, ILo
}
}

/// <summary>
/// Helper to switch the API key sent with each request
/// </summary>
/// <param name="apiKey">Your new API Key</param>
/// <returns></returns>
public void SetClientApiKey(string apiKey)
{
_transport._algoliaConfig.SetClientApiKey(apiKey);
}



/// <inheritdoc />
public async Task<object> CustomDeleteAsync(string path, Dictionary<string, object> parameters = default, RequestOptions options = null, CancellationToken cancellationToken = default)
Expand Down
13 changes: 12 additions & 1 deletion algoliasearch/Clients/IngestionClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2040,7 +2040,7 @@ public interface IIngestionClient
/// </summary>
public partial class IngestionClient : IIngestionClient
{
private readonly HttpTransport _transport;
internal HttpTransport _transport;
private readonly ILogger<IngestionClient> _logger;

/// <summary>
Expand Down Expand Up @@ -2098,6 +2098,17 @@ public IngestionClient(IngestionConfig config, IHttpRequester httpRequester, ILo
}
}

/// <summary>
/// Helper to switch the API key sent with each request
/// </summary>
/// <param name="apiKey">Your new API Key</param>
/// <returns></returns>
public void SetClientApiKey(string apiKey)
{
_transport._algoliaConfig.SetClientApiKey(apiKey);
}



/// <inheritdoc />
public async Task<AuthenticationCreateResponse> CreateAuthenticationAsync(AuthenticationCreate authenticationCreate, RequestOptions options = null, CancellationToken cancellationToken = default)
Expand Down
13 changes: 12 additions & 1 deletion algoliasearch/Clients/InsightsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public interface IInsightsClient
/// </summary>
public partial class InsightsClient : IInsightsClient
{
private readonly HttpTransport _transport;
internal HttpTransport _transport;
private readonly ILogger<InsightsClient> _logger;

/// <summary>
Expand Down Expand Up @@ -244,6 +244,17 @@ public InsightsClient(InsightsConfig config, IHttpRequester httpRequester, ILogg
}
}

/// <summary>
/// Helper to switch the API key sent with each request
/// </summary>
/// <param name="apiKey">Your new API Key</param>
/// <returns></returns>
public void SetClientApiKey(string apiKey)
{
_transport._algoliaConfig.SetClientApiKey(apiKey);
}



/// <inheritdoc />
public async Task<object> CustomDeleteAsync(string path, Dictionary<string, object> parameters = default, RequestOptions options = null, CancellationToken cancellationToken = default)
Expand Down
13 changes: 12 additions & 1 deletion algoliasearch/Clients/MonitoringClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ public interface IMonitoringClient
/// </summary>
public partial class MonitoringClient : IMonitoringClient
{
private readonly HttpTransport _transport;
internal HttpTransport _transport;
private readonly ILogger<MonitoringClient> _logger;

/// <summary>
Expand Down Expand Up @@ -408,6 +408,17 @@ public MonitoringClient(MonitoringConfig config, IHttpRequester httpRequester, I
}
}

/// <summary>
/// Helper to switch the API key sent with each request
/// </summary>
/// <param name="apiKey">Your new API Key</param>
/// <returns></returns>
public void SetClientApiKey(string apiKey)
{
_transport._algoliaConfig.SetClientApiKey(apiKey);
}



/// <inheritdoc />
public async Task<object> CustomDeleteAsync(string path, Dictionary<string, object> parameters = default, RequestOptions options = null, CancellationToken cancellationToken = default)
Expand Down
13 changes: 12 additions & 1 deletion algoliasearch/Clients/PersonalizationClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ public interface IPersonalizationClient
/// </summary>
public partial class PersonalizationClient : IPersonalizationClient
{
private readonly HttpTransport _transport;
internal HttpTransport _transport;
private readonly ILogger<PersonalizationClient> _logger;

/// <summary>
Expand Down Expand Up @@ -314,6 +314,17 @@ public PersonalizationClient(PersonalizationConfig config, IHttpRequester httpRe
}
}

/// <summary>
/// Helper to switch the API key sent with each request
/// </summary>
/// <param name="apiKey">Your new API Key</param>
/// <returns></returns>
public void SetClientApiKey(string apiKey)
{
_transport._algoliaConfig.SetClientApiKey(apiKey);
}



/// <inheritdoc />
public async Task<object> CustomDeleteAsync(string path, Dictionary<string, object> parameters = default, RequestOptions options = null, CancellationToken cancellationToken = default)
Expand Down
13 changes: 12 additions & 1 deletion algoliasearch/Clients/QuerySuggestionsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ public interface IQuerySuggestionsClient
/// </summary>
public partial class QuerySuggestionsClient : IQuerySuggestionsClient
{
private readonly HttpTransport _transport;
internal HttpTransport _transport;
private readonly ILogger<QuerySuggestionsClient> _logger;

/// <summary>
Expand Down Expand Up @@ -406,6 +406,17 @@ public QuerySuggestionsClient(QuerySuggestionsConfig config, IHttpRequester http
}
}

/// <summary>
/// Helper to switch the API key sent with each request
/// </summary>
/// <param name="apiKey">Your new API Key</param>
/// <returns></returns>
public void SetClientApiKey(string apiKey)
{
_transport._algoliaConfig.SetClientApiKey(apiKey);
}



/// <inheritdoc />
public async Task<BaseResponse> CreateConfigAsync(ConfigurationWithIndex configurationWithIndex, RequestOptions options = null, CancellationToken cancellationToken = default)
Expand Down
13 changes: 12 additions & 1 deletion algoliasearch/Clients/RecommendClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ public interface IRecommendClient
/// </summary>
public partial class RecommendClient : IRecommendClient
{
private readonly HttpTransport _transport;
internal HttpTransport _transport;
private readonly ILogger<RecommendClient> _logger;

/// <summary>
Expand Down Expand Up @@ -362,6 +362,17 @@ public RecommendClient(RecommendConfig config, IHttpRequester httpRequester, ILo
}
}

/// <summary>
/// Helper to switch the API key sent with each request
/// </summary>
/// <param name="apiKey">Your new API Key</param>
/// <returns></returns>
public void SetClientApiKey(string apiKey)
{
_transport._algoliaConfig.SetClientApiKey(apiKey);
}



/// <inheritdoc />
public async Task<object> CustomDeleteAsync(string path, Dictionary<string, object> parameters = default, RequestOptions options = null, CancellationToken cancellationToken = default)
Expand Down
13 changes: 12 additions & 1 deletion algoliasearch/Clients/SearchClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1950,7 +1950,7 @@ public partial interface ISearchClient
/// </summary>
public partial class SearchClient : ISearchClient
{
private readonly HttpTransport _transport;
internal HttpTransport _transport;
private readonly ILogger<SearchClient> _logger;

/// <summary>
Expand Down Expand Up @@ -2008,6 +2008,17 @@ public SearchClient(SearchConfig config, IHttpRequester httpRequester, ILoggerFa
}
}

/// <summary>
/// Helper to switch the API key sent with each request
/// </summary>
/// <param name="apiKey">Your new API Key</param>
/// <returns></returns>
public void SetClientApiKey(string apiKey)
{
_transport._algoliaConfig.SetClientApiKey(apiKey);
}



/// <inheritdoc />
public async Task<AddApiKeyResponse> AddApiKeyAsync(ApiKey apiKey, RequestOptions options = null, CancellationToken cancellationToken = default)
Expand Down
13 changes: 12 additions & 1 deletion algoliasearch/Clients/UsageClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public interface IUsageClient
/// </summary>
public partial class UsageClient : IUsageClient
{
private readonly HttpTransport _transport;
internal HttpTransport _transport;
private readonly ILogger<UsageClient> _logger;

/// <summary>
Expand Down Expand Up @@ -258,6 +258,17 @@ public UsageClient(UsageConfig config, IHttpRequester httpRequester, ILoggerFact
}
}

/// <summary>
/// Helper to switch the API key sent with each request
/// </summary>
/// <param name="apiKey">Your new API Key</param>
/// <returns></returns>
public void SetClientApiKey(string apiKey)
{
_transport._algoliaConfig.SetClientApiKey(apiKey);
}



/// <inheritdoc />
public async Task<object> CustomDeleteAsync(string path, Dictionary<string, object> parameters = default, RequestOptions options = null, CancellationToken cancellationToken = default)
Expand Down
2 changes: 1 addition & 1 deletion algoliasearch/Transport/HttpTransport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ internal class HttpTransport
private readonly IHttpRequester _httpClient;
private readonly ISerializer _serializer;
private readonly RetryStrategy _retryStrategy;
private readonly AlgoliaConfig _algoliaConfig;
internal AlgoliaConfig _algoliaConfig;
private string _errorMessage;
private readonly ILogger<HttpTransport> _logger;

Expand Down

0 comments on commit 2da109e

Please sign in to comment.