Skip to content

Commit be41414

Browse files
Merge pull request #70 from notion-dotnet/10-add-usage-examples
Add usage examples ✨
2 parents e62153e + 89009c5 commit be41414

File tree

9 files changed

+181
-2
lines changed

9 files changed

+181
-2
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System.Threading.Tasks;
2+
using Microsoft.AspNetCore.Mvc;
3+
using Microsoft.Extensions.Logging;
4+
using Notion.Client;
5+
6+
namespace aspnet_core_app.Controllers
7+
{
8+
[ApiController]
9+
[Route("[controller]")]
10+
public class AppController : ControllerBase
11+
{
12+
private readonly ILogger<AppController> _logger;
13+
private readonly INotionClient _notionClient;
14+
15+
public AppController(ILogger<AppController> logger, INotionClient notionClient)
16+
{
17+
_logger = logger;
18+
_notionClient = notionClient;
19+
}
20+
21+
[HttpGet]
22+
public async Task<IActionResult> GetUsers()
23+
{
24+
return Ok(await _notionClient.Users.ListAsync());
25+
}
26+
}
27+
}

examples/aspnet-core-app/Program.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Microsoft.AspNetCore.Hosting;
6+
using Microsoft.Extensions.Configuration;
7+
using Microsoft.Extensions.Hosting;
8+
using Microsoft.Extensions.Logging;
9+
10+
namespace aspnet_core_app
11+
{
12+
public class Program
13+
{
14+
public static void Main(string[] args)
15+
{
16+
CreateHostBuilder(args).Build().Run();
17+
}
18+
19+
public static IHostBuilder CreateHostBuilder(string[] args) =>
20+
Host.CreateDefaultBuilder(args)
21+
.ConfigureWebHostDefaults(webBuilder =>
22+
{
23+
webBuilder.UseStartup<Startup>();
24+
});
25+
}
26+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"$schema": "http://json.schemastore.org/launchsettings.json",
3+
"iisSettings": {
4+
"windowsAuthentication": false,
5+
"anonymousAuthentication": true,
6+
"iisExpress": {
7+
"applicationUrl": "http://localhost:51055",
8+
"sslPort": 44372
9+
}
10+
},
11+
"profiles": {
12+
"IIS Express": {
13+
"commandName": "IISExpress",
14+
"launchBrowser": true,
15+
"launchUrl": "swagger",
16+
"environmentVariables": {
17+
"ASPNETCORE_ENVIRONMENT": "Development"
18+
}
19+
},
20+
"aspnet_core_app": {
21+
"commandName": "Project",
22+
"dotnetRunMessages": "true",
23+
"launchBrowser": true,
24+
"launchUrl": "swagger",
25+
"applicationUrl": "https://localhost:5001;http://localhost:5000",
26+
"environmentVariables": {
27+
"ASPNETCORE_ENVIRONMENT": "Development"
28+
}
29+
}
30+
}
31+
}

examples/aspnet-core-app/Startup.cs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Microsoft.AspNetCore.Builder;
6+
using Microsoft.AspNetCore.Hosting;
7+
using Microsoft.AspNetCore.HttpsPolicy;
8+
using Microsoft.AspNetCore.Mvc;
9+
using Microsoft.Extensions.Configuration;
10+
using Microsoft.Extensions.DependencyInjection;
11+
using Microsoft.Extensions.Hosting;
12+
using Microsoft.Extensions.Logging;
13+
using Microsoft.OpenApi.Models;
14+
using Notion.Client;
15+
16+
namespace aspnet_core_app
17+
{
18+
public class Startup
19+
{
20+
public Startup(IConfiguration configuration)
21+
{
22+
Configuration = configuration;
23+
}
24+
25+
public IConfiguration Configuration { get; }
26+
27+
// This method gets called by the runtime. Use this method to add services to the container.
28+
public void ConfigureServices(IServiceCollection services)
29+
{
30+
services.AddControllers();
31+
services.AddSwaggerGen(c =>
32+
{
33+
c.SwaggerDoc("v1", new OpenApiInfo { Title = "aspnet_core_app", Version = "v1" });
34+
});
35+
36+
services.AddSingleton<ClientOptions>(new ClientOptions{
37+
AuthToken = Configuration.GetValue<string>("AuthToken")
38+
});
39+
40+
services.AddSingleton<INotionClient, NotionClient>();
41+
}
42+
43+
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
44+
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
45+
{
46+
if (env.IsDevelopment())
47+
{
48+
app.UseDeveloperExceptionPage();
49+
app.UseSwagger();
50+
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "aspnet_core_app v1"));
51+
}
52+
53+
app.UseHttpsRedirection();
54+
55+
app.UseRouting();
56+
57+
app.UseAuthorization();
58+
59+
app.UseEndpoints(endpoints =>
60+
{
61+
endpoints.MapControllers();
62+
});
63+
}
64+
}
65+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft": "Warning",
6+
"Microsoft.Hosting.Lifetime": "Information"
7+
}
8+
}
9+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft": "Warning",
6+
"Microsoft.Hosting.Lifetime": "Information"
7+
}
8+
},
9+
"AllowedHosts": "*",
10+
"AuthToken": "<Your auth token>"
11+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
<PropertyGroup>
3+
<TargetFramework>net5.0</TargetFramework>
4+
<RootNamespace>aspnet_core_app</RootNamespace>
5+
</PropertyGroup>
6+
<ItemGroup>
7+
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3"/>
8+
<PackageReference Include="Notion.Net" Version="1.0.4"/>
9+
</ItemGroup>
10+
</Project>

examples/list-users/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System;
2-
using System.Threading.Tasks;
32
using System.Linq;
3+
using System.Threading.Tasks;
44
using Notion.Client;
55

66
namespace list_users

examples/list-users/list-users.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="Notion.Net" Version="0.2.0-beta" />
10+
<PackageReference Include="Notion.Net" Version="1.0.4"/>
1111
</ItemGroup>
1212

1313
</Project>

0 commit comments

Comments
 (0)