Skip to content

Commit 428e667

Browse files
Merge branch 'develop'
2 parents bcf4dc9 + bf4497b commit 428e667

40 files changed

Lines changed: 355 additions & 305 deletions

.github/workflows/ci.yml

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,53 @@
1-
name: CI
1+
name: Nuget Release Package
22

33
on:
4+
create:
5+
branches:
6+
- release/**
47
push:
5-
branches: [develop]
6-
8+
branches:
9+
- master
10+
pull_request:
11+
branches:
12+
- master
13+
714
jobs:
815
build:
16+
17+
env:
18+
BUILD_CONFIG: 'Release'
19+
SOLUTION: 'ESI.NET.sln'
20+
921
runs-on: ubuntu-latest
10-
timeout-minutes: 15
22+
1123
steps:
12-
- name: Checkout
13-
uses: actions/checkout@v2
24+
- uses: actions/checkout@v2
25+
26+
- name: Get Build Version
27+
run: |
28+
Import-Module .\build\GetBuildVersion.psm1
29+
Write-Host $Env:GITHUB_REF
30+
$version = GetBuildVersion -VersionString $Env:GITHUB_REF
31+
echo "BUILD_VERSION=$version" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append
32+
shell: pwsh
33+
34+
- name: Setup NuGet
35+
uses: NuGet/setup-nuget@v1.0.5
36+
37+
- name: Restore dependencies
38+
run: nuget restore $SOLUTION
39+
40+
- name: Setup .NET
41+
uses: actions/setup-dotnet@v1
42+
with:
43+
dotnet-version: 3.1.x
44+
1445
- name: Build
15-
run: dotnet build --configuration Release
46+
run: dotnet build $SOLUTION --configuration $BUILD_CONFIG -p:Version=$BUILD_VERSION --no-restore
47+
48+
- name: Run tests
49+
run: dotnet test /p:Configuration=$env:BUILD_CONFIG --no-restore --no-build --verbosity normal
1650

51+
- name: Publish
52+
if: startsWith(github.ref, 'refs/heads/release')
53+
run: nuget push **\*.nupkg -Source 'https://api.nuget.org/v3/index.json' -ApiKey ${{secrets.NUGET_API_KEY}}

ESI.NET/ESI.NET.csproj

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,14 @@
88
</PropertyGroup>
99

1010
<PropertyGroup>
11-
<TargetFrameworks>netcoreapp3.1;netstandard2.0;net461;net462;net47;net471;net5.0</TargetFrameworks>
11+
<TargetFrameworks>netcoreapp3.1;netstandard2.0;net462;net47;net471;net472;net48;net6.0;net7.0</TargetFrameworks>
1212
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
13-
<Version>2021.12.12</Version>
13+
<Version>2023.02.11</Version>
1414
<Authors>Psianna Archeia</Authors>
1515
<Company>Sukebe Corporation</Company>
1616
<Description>.NET Wrapper for the Eve Online API</Description>
1717
<RepositoryUrl>https://github.com/seraphx2/ESI.NET</RepositoryUrl>
1818
<RepositoryType>git</RepositoryType>
19-
<PackageLicenseUrl></PackageLicenseUrl>
2019
<PackageProjectUrl>https://github.com/seraphx2/ESI.NET</PackageProjectUrl>
2120
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
2221
</PropertyGroup>
@@ -28,7 +27,7 @@
2827
<PackageReference Include="Microsoft.Extensions.Options" Version="2.0.0" />
2928
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="2.0.0" />
3029
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="6.14.1" />
31-
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
30+
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
3231
<PackageReference Include="System.Collections.Immutable" Version="1.5.0" />
3332
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.14.1" />
3433
<PackageReference Include="System.Net.Http" Version="4.3.4" />
@@ -37,8 +36,14 @@
3736
<ItemGroup>
3837
<None Include="..\LICENSE.txt">
3938
<Pack>True</Pack>
40-
<PackagePath></PackagePath>
39+
<PackagePath>LICENSE.txt</PackagePath>
4140
</None>
4241
</ItemGroup>
4342

44-
</Project>
43+
<ItemGroup>
44+
<None Update="GetBuildVersion.psm1">
45+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
46+
</None>
47+
</ItemGroup>
48+
49+
</Project>

ESI.NET/EsiClient.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,22 @@ public class EsiClient : IEsiClient
1414
readonly EsiConfig config;
1515

1616
/// <summary>
17-
///
17+
/// Initializes a new instance of the <see cref="EsiClient"/> class.
1818
/// </summary>
19-
/// <param name="config"></param>
20-
public EsiClient(IOptions<EsiConfig> _config)
19+
/// <param name="_config">The configuration parameters of the <see cref="EsiClient"/>.</param>
20+
/// <param name="_client">The <see cref="HttpClient"/> to use for HTTP requests.</param>
21+
public EsiClient(IOptions<EsiConfig> _config, HttpClient _client = null)
2122
{
2223
config = _config.Value;
23-
client = new HttpClient(new HttpClientHandler
24+
client = _client ?? new HttpClient(new HttpClientHandler
2425
{
2526
AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate
2627
});
2728

2829
// Enforce user agent value
2930
if (string.IsNullOrEmpty(config.UserAgent))
3031
throw new ArgumentException("For your protection, please provide an X-User-Agent value. This can be your character name and/or project name. CCP will be more likely to contact you rather than just cut off access to ESI if you provide something that can identify you within the New Eden galaxy.");
31-
else
32-
client.DefaultRequestHeaders.Add("X-User-Agent", config.UserAgent);
32+
client.DefaultRequestHeaders.Add("X-User-Agent", config.UserAgent);
3333

3434
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
3535
client.DefaultRequestHeaders.AcceptEncoding.Add(new StringWithQualityHeaderValue("gzip"));

ESI.NET/EsiRequest.cs

Lines changed: 13 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -12,81 +12,48 @@ internal static class EsiRequest
1212
{
1313
internal static string ETag;
1414

15-
public static async Task<EsiResponse<T>> Execute<T>(HttpClient client, EsiConfig config, RequestSecurity security, RequestMethod method, string endpoint, Dictionary<string, string> replacements = null, string[] parameters = null, object body = null, string token = null)
15+
public static async Task<EsiResponse<T>> Execute<T>(HttpClient client, EsiConfig config, RequestSecurity security, HttpMethod httpMethod, string endpoint, Dictionary<string, string> replacements = null, string[] parameters = null, object body = null, string token = null)
1616
{
17-
client.DefaultRequestHeaders.Clear();
18-
19-
var path = $"{method.ToString()}|{endpoint}";
17+
var path = $"{httpMethod}|{endpoint}";
2018

2119
if (replacements != null)
2220
foreach (var property in replacements)
2321
endpoint = endpoint.Replace($"{{{property.Key}}}", property.Value);
2422

2523
var url = $"{config.EsiUrl}latest{endpoint}?datasource={config.DataSource.ToEsiValue()}";
2624

25+
//Attach query string parameters
26+
if (parameters != null)
27+
url += $"&{string.Join("&", parameters)}";
28+
29+
var request = new HttpRequestMessage(httpMethod, url);
30+
2731
//Attach token to request header if this endpoint requires an authorized character
2832
if (security == RequestSecurity.Authenticated)
2933
{
3034
if (token == null)
3135
throw new ArgumentException("The request endpoint requires SSO authentication and a Token has not been provided.");
32-
33-
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
36+
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token);
3437
}
3538

3639
if (ETag != null)
3740
{
38-
client.DefaultRequestHeaders.Add("If-None-Match", $"\"{ETag}\"");
41+
request.Headers.Add("If-None-Match", $"\"{ETag}\"");
3942
ETag = null;
4043
}
4144

42-
//Attach query string parameters
43-
if (parameters != null)
44-
url += $"&{string.Join("&", parameters)}";
45-
4645
//Serialize post body data
47-
HttpContent postBody = null;
4846
if (body != null)
49-
postBody = new StringContent(JsonConvert.SerializeObject(body), Encoding.UTF8, "application/json");
50-
51-
//Get response from client based on request type
52-
//This is also where body variables will be created and attached as necessary
53-
HttpResponseMessage response = null;
54-
switch (method)
55-
{
56-
case RequestMethod.Delete:
57-
response = await client.DeleteAsync(url).ConfigureAwait(false);
58-
break;
59-
60-
case RequestMethod.Get:
61-
response = await client.GetAsync(url).ConfigureAwait(false);
62-
break;
63-
64-
case RequestMethod.Post:
65-
response = await client.PostAsync(url, postBody).ConfigureAwait(false);
66-
break;
47+
request.Content = new StringContent(JsonConvert.SerializeObject(body), Encoding.UTF8, "application/json");
6748

68-
case RequestMethod.Put:
69-
response = await client.PutAsync(url, postBody).ConfigureAwait(false);
70-
break;
71-
}
72-
7349
//Output final object
74-
var obj = new EsiResponse<T>(response, path);
75-
return obj;
50+
return new EsiResponse<T>(await client.SendAsync(request).ConfigureAwait(false), path);
7651
}
7752

7853
public enum RequestSecurity
7954
{
8055
Public,
8156
Authenticated
8257
}
83-
84-
public enum RequestMethod
85-
{
86-
Delete,
87-
Get,
88-
Post,
89-
Put
90-
}
9158
}
92-
}
59+
}

ESI.NET/EsiResponse.cs

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,10 @@ public EsiResponse(HttpResponseMessage response, string path)
6464
Message = response.Content.ReadAsStringAsync().Result;
6565
Exception = ex;
6666
}
67-
67+
finally
68+
{
69+
response.Dispose();
70+
}
6871
}
6972

7073
public Guid RequestId { get; set; }
@@ -84,41 +87,41 @@ public EsiResponse(HttpResponseMessage response, string path)
8487
private readonly ImmutableDictionary<string, string> _noContentMessage = new Dictionary<string, string>()
8588
{
8689
//Calendar
87-
{"Put|/characters/{character_id}/calendar/{event_id}/", "Event updated"},
90+
{"PUT|/characters/{character_id}/calendar/{event_id}/", "Event updated"},
8891

8992
//Contacts
90-
{"Put|/characters/{character_id}/contacts/", "Contacts updated"},
91-
{"Delete|/characters/{character_id}/contacts/", "Contacts deleted"},
93+
{"PUT|/characters/{character_id}/contacts/", "Contacts updated"},
94+
{"DELETE|/characters/{character_id}/contacts/", "Contacts deleted"},
9295

9396
//Corporations
94-
{"Put|/corporations/{corporation_id}/structures/{structure_id}/", "Structure vulnerability window updated"},
97+
{"PUT|/corporations/{corporation_id}/structures/{structure_id}/", "Structure vulnerability window updated"},
9598

9699
//Fittings
97-
{"Delete|/characters/{character_id}/fittings/{fitting_id}/", "Fitting deleted"},
100+
{"DELETE|/characters/{character_id}/fittings/{fitting_id}/", "Fitting deleted"},
98101

99102
//Fleets
100-
{"Put|/fleets/{fleet_id}/", "Fleet updated"},
101-
{"Post|/fleets/{fleet_id}/members/", "Fleet invitation sent"},
102-
{"Delete|/fleets/{fleet_id}/members/{member_id}/", "Fleet member kicked"},
103-
{"Put|/fleets/{fleet_id}/members/{member_id}/", "Fleet invitation sent"},
104-
{"Delete|/fleets/{fleet_id}/wings/{wing_id}/", "Wing deleted"},
105-
{"Put|/fleets/{fleet_id}/wings/{wing_id}/", "Wing renamed"},
106-
{"Delete|/fleets/{fleet_id}/squads/{squad_id}/", "Squad deleted"},
107-
{"Put|/fleets/{fleet_id}/squads/{squad_id}/", "Squad renamed"},
103+
{"PUT|/fleets/{fleet_id}/", "Fleet updated"},
104+
{"POST|/fleets/{fleet_id}/members/", "Fleet invitation sent"},
105+
{"DELETE|/fleets/{fleet_id}/members/{member_id}/", "Fleet member kicked"},
106+
{"PUT|/fleets/{fleet_id}/members/{member_id}/", "Fleet invitation sent"},
107+
{"DELETE|/fleets/{fleet_id}/wings/{wing_id}/", "Wing deleted"},
108+
{"PUT|/fleets/{fleet_id}/wings/{wing_id}/", "Wing renamed"},
109+
{"DELETE|/fleets/{fleet_id}/squads/{squad_id}/", "Squad deleted"},
110+
{"PUT|/fleets/{fleet_id}/squads/{squad_id}/", "Squad renamed"},
108111

109112
//Mail
110-
{"Post|/characters/{character_id}/mail/", "Mail created"},
111-
{"Post|/characters/{character_id}/mail/labels/", "Label created"},
112-
{"Delete|/characters/{character_id}/mail/labels/{label_id}/", "Label deleted"},
113-
{"Put|/characters/{character_id}/mail/{mail_id}/", "Mail updated"},
114-
{"Delete|/characters/{character_id}/mail/{mail_id}/", "Mail deleted"},
113+
{"POST|/characters/{character_id}/mail/", "Mail created"},
114+
{"POST|/characters/{character_id}/mail/labels/", "Label created"},
115+
{"DELETE|/characters/{character_id}/mail/labels/{label_id}/", "Label deleted"},
116+
{"PUT|/characters/{character_id}/mail/{mail_id}/", "Mail updated"},
117+
{"DELETE|/characters/{character_id}/mail/{mail_id}/", "Mail deleted"},
115118

116119
//User Interface
117-
{"Post|/ui/openwindow/marketdetails/", "Open window request received"},
118-
{"Post|/ui/openwindow/contract/", "Open window request received"},
119-
{"Post|/ui/openwindow/information/", "Open window request received"},
120-
{"Post|/ui/autopilot/waypoint/", "Open window request received"},
121-
{"Post|/ui/openwindow/newmail/", "Open window request received"}
120+
{"POST|/ui/openwindow/marketdetails/", "Open window request received"},
121+
{"POST|/ui/openwindow/contract/", "Open window request received"},
122+
{"POST|/ui/openwindow/information/", "Open window request received"},
123+
{"POST|/ui/autopilot/waypoint/", "Open window request received"},
124+
{"POST|/ui/openwindow/newmail/", "Open window request received"}
122125
}.ToImmutableDictionary();
123126
}
124-
}
127+
}

ESI.NET/GetBuildVersion.psm1

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
Function GetBuildVersion {
2+
Param (
3+
[string]$VersionString
4+
)
5+
6+
# Process through regex
7+
$VersionString -match "(?<major>\d+)(\.(?<minor>\d+))?(\.(?<patch>\d+))?(\-(?<pre>[0-9A-Za-z\-\.]+))?(\+(?<build>\d+))?" | Out-Null
8+
9+
if ($matches -eq $null) {
10+
return "1.0.0-build"
11+
}
12+
13+
# Extract the build metadata
14+
$BuildRevision = [uint64]$matches['build']
15+
# Extract the pre-release tag
16+
$PreReleaseTag = [string]$matches['pre']
17+
# Extract the patch
18+
$Patch = [uint64]$matches['patch']
19+
# Extract the minor
20+
$Minor = [uint64]$matches['minor']
21+
# Extract the major
22+
$Major = [uint64]$matches['major']
23+
24+
$Version = [string]$Major + '.' + [string]$Minor + '.' + [string]$Patch;
25+
if ($PreReleaseTag -ne [string]::Empty) {
26+
$Version = $Version + '-' + $PreReleaseTag
27+
}
28+
29+
if ($BuildRevision -ne 0) {
30+
$Version = $Version + '.' + [string]$BuildRevision
31+
}
32+
33+
return $Version
34+
}

ESI.NET/Logic/AllianceLogic.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ public class AllianceLogic
1919
/// </summary>
2020
/// <returns></returns>
2121
public async Task<EsiResponse<int[]>> All()
22-
=> await Execute<int[]>(_client, _config, RequestSecurity.Public, RequestMethod.Get, "/alliances/");
22+
=> await Execute<int[]>(_client, _config, RequestSecurity.Public, HttpMethod.Get, "/alliances/");
2323

2424
/// <summary>
2525
/// /alliances/{alliance_id}/
2626
/// </summary>
2727
/// <param name="allianceId"></param>
2828
/// <returns></returns>
2929
public async Task<EsiResponse<Alliance>> Information(int alliance_id)
30-
=> await Execute<Alliance>(_client, _config, RequestSecurity.Public, RequestMethod.Get, "/alliances/{alliance_id}/",
30+
=> await Execute<Alliance>(_client, _config, RequestSecurity.Public, HttpMethod.Get, "/alliances/{alliance_id}/",
3131
replacements: new Dictionary<string, string>()
3232
{
3333
{ "alliance_id", alliance_id.ToString() }
@@ -39,7 +39,7 @@ public async Task<EsiResponse<Alliance>> Information(int alliance_id)
3939
/// <param name="alliance_id"></param>
4040
/// <returns></returns>
4141
public async Task<EsiResponse<int[]>> Corporations(int alliance_id)
42-
=> await Execute<int[]>(_client, _config, RequestSecurity.Public, RequestMethod.Get, "/alliances/{alliance_id}/corporations/",
42+
=> await Execute<int[]>(_client, _config, RequestSecurity.Public, HttpMethod.Get, "/alliances/{alliance_id}/corporations/",
4343
replacements: new Dictionary<string, string>()
4444
{
4545
{ "alliance_id", alliance_id.ToString() }
@@ -51,7 +51,7 @@ public async Task<EsiResponse<int[]>> Corporations(int alliance_id)
5151
/// <param name="alliance_id"></param>
5252
/// <returns></returns>
5353
public async Task<EsiResponse<Images>> Icons(int alliance_id)
54-
=> await Execute<Images>(_client, _config, RequestSecurity.Public, RequestMethod.Get, "/alliances/{alliance_id}/icons/",
54+
=> await Execute<Images>(_client, _config, RequestSecurity.Public, HttpMethod.Get, "/alliances/{alliance_id}/icons/",
5555
replacements: new Dictionary<string, string>()
5656
{
5757
{ "alliance_id", alliance_id.ToString() }

0 commit comments

Comments
 (0)