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

Add complex response components #53

Closed
wants to merge 26 commits into from
Closed
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
Prev Previous commit
Next Next commit
improve service generator
  • Loading branch information
tweakch committed Oct 4, 2021
commit 00e460c056d129821ad43c6b11b964f2a08653d1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Globalization;
using System.Linq;
using System.Net;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Linq;
using System.Net.Http;
using Blockfrost.Api.Options;
Expand Down Expand Up @@ -986,7 +986,6 @@ public static IServiceCollection AddCardanoServices(this IServiceCollection serv
// var options = provider.GetService<IOptions<BlockfrostOptions>>();
// return new BlockfrostAuthorizationHandler(options.Value[projectName].ApiKey);
//});

_ = services.AddHealthService(projectName);
_ = services.AddMetricsService(projectName);

Expand Down Expand Up @@ -1021,7 +1020,6 @@ public static IServiceCollection AddCardanoServices(this IServiceCollection serv
services.ConfigureBlockfrost(network, apiKey, projectName, connectionLimit);

_ = services.AddBasicBlockfrostService(projectName, connectionLimit);

_ = services.AddHealthService(projectName, connectionLimit);
_ = services.AddMetricsService(projectName, connectionLimit);

Expand Down Expand Up @@ -1228,4 +1226,3 @@ private static TService ServiceFactory<TService>(object migration, HttpClient cl
}
}
}

20 changes: 18 additions & 2 deletions src/Blockfrost.Api/Extensions/BlockfrostServiceExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Linq;
using Blockfrost.Api.Options;
using Microsoft.Extensions.Configuration;
Expand All @@ -22,6 +22,13 @@ public static IServiceCollection AddBlockfrost(this IServiceCollection services)
return services.AddBlockfrost(config["BFCLI_NETWORK"], config["BFCLI_API_KEY"]);
}

/// <summary>
/// Adds Blockfrost Services to the service collection and configures the specified projectName using the provided configuration
/// </summary>
/// <param name="services">The IServiceCollection</param>
/// <param name="projectName">The project name to use from the config</param>
/// <param name="configuration">The configuration</param>
/// <returns></returns>
public static IServiceCollection AddBlockfrost(this IServiceCollection services, string projectName, IConfiguration configuration)
{
_ = services.ConfigureBlockfrost(projectName, configuration);
Expand All @@ -31,6 +38,13 @@ public static IServiceCollection AddBlockfrost(this IServiceCollection services,
return services;
}

/// <summary>
/// Adds Blockfrost Services to the service collection and configures the services for the project from the provided configuration
/// </summary>
/// <param name="services">The IServiceCollection</param>
/// <param name="projectName">The project name to use from the config</param>
/// <param name="configuration">The configuration</param>
/// <returns></returns>
public static IServiceCollection AddBlockfrost(this IServiceCollection services, IConfiguration config)
{
var blockfrostConfig = config.GetSection("Blockfrost");
Expand All @@ -51,10 +65,12 @@ public static IServiceCollection AddBlockfrost(this IServiceCollection services,
return services.AddBlockfrost(project.Name, config);
}
}

/// <summary>
/// Adds Blockfrost Services to the service collection
/// Adds Blockfrost Services to the service collection and configures the services using the provided project
/// </summary>
/// <param name="services">The IServiceCollection</param>
/// <param name="project">The project to use</param>
/// <returns></returns>
public static IServiceCollection AddBlockfrost(this IServiceCollection services, BlockfrostProject project)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Blockfrost.Api/Extensions/StringBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static StringBuilder SetRouteParameter(this StringBuilder builder, string
public static StringBuilder AppendQueryParameter(this StringBuilder builder, string name, object value)
{
return name == null
? throw new System.ArgumentNullException(nameof(name))
? throw new System.ArgumentNullException(nameof(name))
: builder
.Append(System.Uri.EscapeDataString(name))
.Append('=')
Expand Down
6 changes: 3 additions & 3 deletions src/Blockfrost.Api/Services/ABlockfrostService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Net.Http;
Expand All @@ -19,9 +19,9 @@ public partial class ABlockfrostService : IBlockfrostService
private JsonSerializerOptions TextJsonSerializerSettings => _options.Value;

protected HttpClient HttpClient { get; set; }

public string Name { get; set; }

public string Network { get; set; }

public string BaseUrl
Expand Down
4 changes: 0 additions & 4 deletions src/Blockfrost.Api/Services/IBlockfrostService.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;

namespace Blockfrost.Api
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,10 @@ namespace Blockfrost.Api

private JsonSerializerOptions CreateSerializerOptions()
{
var options = new JsonSerializerOptions();
var options = new JsonSerializerOptions
{
AllowTrailingCommas = true,
};
UpdateJsonSerializerOptions(options);
return options;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@ namespace Blockfrost.Api.Extensions

var project = blockfrostSection.Get<BlockfrostProject>();

if (project == null)
if (string.IsNullOrEmpty(project.Name))
{
// try dictionary
project = blockfrostSection.GetSection($"{projectName}").Get<BlockfrostProject>();
project = blockfrostSection.GetProject(projectName);
}

if (!projectName.Equals(project.Name, StringComparison.Ordinal))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,6 @@ namespace Blockfrost.Api.Extensions
/// Adds Blockfrost Services to the service collection
/// </summary>
/// <param name="services">The IServiceCollection</param>
/// <param name="network">The network the services will use</param>
/// <param name="apiKey">The ApiKey used to authenticate</param>
/// <returns></returns>
public static IServiceCollection AddCardanoServices(this IServiceCollection services, string projectName)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ namespace Blockfrost.Api.Extensions
}

/// <summary>
/// Adds Blockfrost Services to the service collection
/// Adds Blockfrost Services to the service collection and configures the specified projectName using the provided configuration
/// </summary>
/// <param name="services">The IServiceCollection</param>
/// <param name="network">The network the services will use</param>
/// <param name="apiKey">The ApiKey used to authenticate</param>
/// <param name="projectName">The project name to use from the config</param>
/// <param name="configuration">The configuration</param>
/// <returns></returns>
public static IServiceCollection AddBlockfrost(this IServiceCollection services, string projectName, IConfiguration configuration)
{
Expand All @@ -38,6 +38,13 @@ namespace Blockfrost.Api.Extensions
return services;
}

/// <summary>
/// Adds Blockfrost Services to the service collection and configures the services for the project from the provided configuration
/// </summary>
/// <param name="services">The IServiceCollection</param>
/// <param name="projectName">The project name to use from the config</param>
/// <param name="configuration">The configuration</param>
/// <returns></returns>
public static IServiceCollection AddBlockfrost(this IServiceCollection services, IConfiguration config)
{
var blockfrostConfig = config.GetSection("Blockfrost");
Expand All @@ -58,12 +65,12 @@ namespace Blockfrost.Api.Extensions
return services.AddBlockfrost(project.Name, config);
}
}

/// <summary>
/// Adds Blockfrost Services to the service collection
/// Adds Blockfrost Services to the service collection and configures the services using the provided project
/// </summary>
/// <param name="services">The IServiceCollection</param>
/// <param name="network">The network the services will use</param>
/// <param name="apiKey">The ApiKey used to authenticate</param>
/// <param name="project">The project to use</param>
/// <returns></returns>
public static IServiceCollection AddBlockfrost(this IServiceCollection services, BlockfrostProject project)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;

namespace Blockfrost.Api
{
/// <summary>
Expand Down