Skip to content

Commit

Permalink
Made changes from PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Norhaven committed Jan 24, 2024
1 parent 9623452 commit 4cc1732
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 52 deletions.
1 change: 0 additions & 1 deletion GrowthBook.Tests/ApiTests/ApiUnitTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public abstract class ApiUnitTest<T> : UnitTest

protected readonly ILogger<T> _logger;
protected readonly Mock<IGrowthBookFeatureCache> _cache;
protected readonly FeatureRefreshWorker _worker;
protected readonly Feature _firstFeature;
protected readonly Feature _secondFeature;
protected readonly Dictionary<string, Feature> _availableFeatures;
Expand Down
32 changes: 0 additions & 32 deletions GrowthBook.Tests/ApiTests/LoadFeaturesTests.cs

This file was deleted.

12 changes: 12 additions & 0 deletions GrowthBook/Api/ConfiguredClients.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace GrowthBook.Api
{
public static class ConfiguredClients
{
public const string DefaultApiClient = "growthbook-default-api-client";
public const string ServerSentEventsApiClient = "growthbook-sse-api-client";
}
}
17 changes: 12 additions & 5 deletions GrowthBook/Api/FeatureRefreshWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public async Task<IDictionary<string, Feature>> RefreshCacheFromApi(Cancellation
{
_logger.LogInformation($"Making an HTTP request to the default Features API endpoint '{_featuresApiEndpoint}'");

var httpClient = _httpClientFactory.CreateClient(HttpClientFactory.ConfiguredClients.DefaultApiClient);
var httpClient = _httpClientFactory.CreateClient(ConfiguredClients.DefaultApiClient);
var response = await httpClient.GetAsync(_featuresApiEndpoint, cancellationToken ?? _refreshWorkerCancellation.Token);

if (!response.IsSuccessStatusCode)
Expand Down Expand Up @@ -128,7 +128,7 @@ private Task ListenForServerSentEvents()
{
_logger.LogInformation($"Making an HTTP request to server sent events endpoint '{_serverSentEventsApiEndpoint}'");

var httpClient = _httpClientFactory.CreateClient(HttpClientFactory.ConfiguredClients.ServerSentEventsApiClient);
var httpClient = _httpClientFactory.CreateClient(ConfiguredClients.ServerSentEventsApiClient);
var stream = await httpClient.GetStreamAsync(_serverSentEventsApiEndpoint);

using (var reader = new StreamReader(stream))
Expand All @@ -137,15 +137,22 @@ private Task ListenForServerSentEvents()
{
var json = reader.ReadLine();

// Server sent events have a few potential different bits of information
// that may be sent along with the actual JSON data we care about. For now,
// we're just dropping those extra pieces and solely focusing on grabbing the JSON.
// All server sent events will have the format "<key>:<value>" and each message
// is a single line in the stream. Right now, the only message that we care about
// has a key of "data" and value of the JSON data sent from the server, so we're going
// to ignore everything that's doesn't contain a "data" key.

if (json?.StartsWith("data:") != true)
{
// No actual JSON data is present, ignore this message.

continue;
}

// Strip off the key and the colon so we can try to deserialize the JSON data. Keep in mind
// that the data key might be sent with no actual data present, so we're also checking up front
// to see whether we can just drop this as well or if it actually needs processing.

json = json.Substring(5).Trim();

if (string.IsNullOrWhiteSpace(json))
Expand Down
6 changes: 0 additions & 6 deletions GrowthBook/Api/HttpClientFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@ namespace GrowthBook.Api
{
public class HttpClientFactory : IHttpClientFactory
{
public static class ConfiguredClients
{
public const string DefaultApiClient = "growthbook-default-api-client";
public const string ServerSentEventsApiClient = "growthbook-sse-api-client";
}

private readonly int _requestTimeoutInSeconds;

public HttpClientFactory(int requestTimeoutInSeconds = 60) => _requestTimeoutInSeconds = requestTimeoutInSeconds;
Expand Down
6 changes: 0 additions & 6 deletions GrowthBook/AssemblyInfo.cs

This file was deleted.

7 changes: 5 additions & 2 deletions GrowthBook/GrowthBook.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Authors>Ben Whatley,Norhaven</Authors>
<Authors>Ben Whatley</Authors>
<Description>Powerful feature flagging and A/B testing for C# apps using GrowthBook.</Description>
<Company>GrowthBook</Company>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<Copyright>Copyright (c) 2022 GrowthBook</Copyright>
<PackageId>growthbook-c-sharp</PackageId>
<RepositoryUrl>https://github.com/growthbook/growthbook-csharp.git</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageTags>GrowthBook,A/B test,feature toggle</PackageTags>
<PackageTags>GrowthBook,A/B test,feature toggle,flag</PackageTags>
<Version>1.0.0</Version>
<Title>GrowthBook C# SDK</Title>
<PackageProjectUrl>https://www.growthbook.io/</PackageProjectUrl>
Expand All @@ -31,4 +31,7 @@
</None>
</ItemGroup>

<ItemGroup>
<InternalsVisibleTo Include="GrowthBook.Tests" />
</ItemGroup>
</Project>

0 comments on commit 4cc1732

Please sign in to comment.