Skip to content

Commit 3dc8edd

Browse files
authored
V2 SDK (#3)
* Add mise * Update to v3 api * Switch to AccountStatus * Update dotnet versions * Update github action * Update github action * Remove old dotnet versions * Update to support latest dotnet * Support dotnet 6 for testing * Add latest dotnet support * Use dotnet 9 to test all frameworks * Update readme * Add publish action * Add changelog
1 parent d4f1d5e commit 3dc8edd

16 files changed

+87
-65
lines changed

.github/workflows/main.yml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,17 @@ jobs:
66
strategy:
77
matrix:
88
dotnet-version:
9-
- '2.1'
10-
- '2.2'
9+
- '9.0'
1110
name: .NET ${{ matrix.dotnet-version }} sample
1211
steps:
13-
- uses: actions/checkout@v3
14-
- uses: actions/setup-dotnet@v2
12+
- uses: actions/checkout@v4
13+
- name: Setup .NET
14+
uses: actions/setup-dotnet@v4
1515
with:
1616
dotnet-version: ${{ matrix.dotnet-version }}
17-
- run: dotnet restore
18-
- env:
17+
- name: Restore dependencies
18+
run: dotnet restore
19+
- name: Run tests
20+
env:
1921
DETECTLANGUAGE_API_KEY: ${{ secrets.DETECTLANGUAGE_API_KEY }}
2022
run: dotnet test

.github/workflows/publish.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Publish dotnet package
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
publish:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout code
12+
uses: actions/checkout@v4
13+
- name: Setup .NET
14+
uses: actions/setup-dotnet@v4
15+
with:
16+
dotnet-version: 9.0
17+
- name: Build
18+
run: dotnet build --configuration Release
19+
- name: Pack
20+
run: dotnet pack --configuration Release
21+
- name: Publish the package to nuget.org
22+
run: dotnet nuget push */bin/Release/*.nupkg -k $NUGET_AUTH_TOKEN -s https://api.nuget.org/v3/index.json
23+
env:
24+
NUGET_AUTH_TOKEN: ${{ secrets.NUGET_TOKEN }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## files generated by popular Visual Studio add-ons.
44

55
# User-specific files
6+
.env.local
67
*.suo
78
*.user
89
*.sln.docstates

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
9+
## v2.0.0
10+
11+
### Changed
12+
- Switched to v3 API which uses updated language detection model
13+
- ⚠️ Added `DetectResult` field `score`, removed `confidence` and `reliable`
14+
- Renamed `GetUserStatusAsync` to `GetAccountStatusAsync`
15+
- Updated `Newtonsoft.Json` dependency to `13.0.3`

DetectLanguage.Tests/DetectLanguage.Tests.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp2.0</TargetFramework>
4+
<TargetFrameworks>net9.0</TargetFrameworks>
55

66
<IsPackable>false</IsPackable>
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="nunit" Version="3.11.0" />
11-
<PackageReference Include="NUnit3TestAdapter" Version="3.11.0" />
12-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
10+
<PackageReference Include="nunit" Version="3.14.0" />
11+
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
12+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
1313
</ItemGroup>
1414

1515
<ItemGroup>

DetectLanguage.Tests/DetectLanguageClientTest.cs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ public async Task TestDetectAsync() {
2424
var results = await client.DetectAsync("Labas rytas");
2525

2626
Assert.That(results[0].language, Is.EqualTo("lt"));
27-
Assert.That(results[0].reliable, Is.EqualTo(true));
28-
Assert.That(results[0].confidence, Is.GreaterThan(0));
27+
Assert.That(results[0].score, Is.GreaterThan(0));
2928
}
3029

3130
[Test]
@@ -37,7 +36,7 @@ public async Task TestDetectCodeAsync() {
3736

3837
[Test]
3938
public async Task TestDetectCodeAsyncNull() {
40-
string language = await client.DetectCodeAsync("-");
39+
string language = await client.DetectCodeAsync(" ");
4140

4241
Assert.IsNull(language);
4342
}
@@ -48,8 +47,7 @@ public async Task TestBatchDetectAsync() {
4847
var results = await client.BatchDetectAsync(texts);
4948

5049
Assert.That(results[0][0].language, Is.EqualTo("en"));
51-
Assert.That(results[0][0].reliable, Is.EqualTo(true));
52-
Assert.That(results[0][0].confidence, Is.GreaterThan(0));
50+
Assert.That(results[0][0].score, Is.GreaterThan(0));
5351
Assert.That(results[1][0].language, Is.EqualTo("lt"));
5452
}
5553

@@ -58,12 +56,12 @@ public async Task TestGetLanguagesAsync() {
5856
var languages = await client.GetLanguagesAsync();
5957

6058
Assert.That(languages[0].code, Is.EqualTo("aa"));
61-
Assert.That(languages[0].name, Is.EqualTo("AFAR"));
59+
Assert.That(languages[0].name, Is.EqualTo("Afar"));
6260
}
6361

6462
[Test]
65-
public async Task TestGetUserStatusAsync() {
66-
var userStatus = await client.GetUserStatusAsync();
63+
public async Task TestGetAccountStatusAsync() {
64+
var userStatus = await client.GetAccountStatusAsync();
6765

6866
Assert.IsNotEmpty(userStatus.date);
6967
Assert.IsNotEmpty(userStatus.plan);
@@ -75,9 +73,9 @@ public async Task TestGetUserStatusAsync() {
7573
}
7674

7775
[Test]
78-
public void TestGetUserStatusAsyncError() {
76+
public void TestGetAccountStatusAsyncError() {
7977
var testClient = new DetectLanguageClient("someApiKey");
80-
var ex = Assert.ThrowsAsync<DetectLanguageException>(() => testClient.GetUserStatusAsync());
78+
var ex = Assert.ThrowsAsync<DetectLanguageException>(() => testClient.GetAccountStatusAsync());
8179

8280
Assert.IsNotEmpty(ex.Message);
8381
Assert.IsNotNull(ex.Error);

DetectLanguage.Tests/DetectLanguageConfigurationTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public void TestApiKeyConstructor() {
1010
var config = new DetectLanguageConfiguration("someApiKey");
1111

1212
Assert.That(config.ApiKey, Is.EqualTo("someApiKey"));
13-
Assert.That(config.ApiBase, Is.EqualTo("https://ws.detectlanguage.com/0.2/"));
13+
Assert.That(config.ApiBase, Is.EqualTo("https://ws.detectlanguage.com/v3/"));
1414
Assert.That(config.UserAgent, Does.Match("detectlanguage-dotnet/\\d+"));
1515
}
1616
}

DetectLanguage/DetectLanguage.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@
44
<Description>Language Detection API Client for .NET (Official Library)</Description>
55
<AssemblyName>DetectLanguage</AssemblyName>
66
<PackageId>DetectLanguage</PackageId>
7-
<Version>1.0.0</Version>
7+
<Version>2.0.0</Version>
88
<PackageTags>detect;identify;language;text;detectlanguage;detection;identification;nlp</PackageTags>
99
<Authors>Laurynas Butkus</Authors>
1010
<Company>detectlanguage.com</Company>
1111
<PackageProjectUrl>https://github.com/detectlanguage/detectlanguage-dotnet</PackageProjectUrl>
1212
<RepositoryUrl>https://github.com/detectlanguage/detectlanguage-dotnet</RepositoryUrl>
1313
<PackageLicenseExpression>MIT</PackageLicenseExpression>
1414
<PackageIconUrl>https://www.nuget.org/profiles/detectlanguage/avatar?imageSize=128</PackageIconUrl>
15-
<TargetFramework>netstandard2.0</TargetFramework>
15+
<TargetFrameworks>net5.0;net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
1616
<PackageReadmeFile>README.md</PackageReadmeFile>
1717
</PropertyGroup>
1818

1919
<ItemGroup>
20-
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
20+
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
2121
<None Include="..\README.md" Pack="true" PackagePath=""/>
2222
</ItemGroup>
2323

DetectLanguage/DetectLanguageClient.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ public DetectLanguageClient(DetectLanguageConfiguration configuration) {
2828
/// <exception cref="DetectLanguageException">Thrown if the request fails.</exception>
2929
public async Task<DetectResult[]> DetectAsync(string text) {
3030
var request = new DetectRequest{ q = text };
31-
var response = await httpClient.PostAsync<DetectResponse>("detect", request);
32-
33-
return response.data.detections;
31+
return await httpClient.PostAsync<DetectResult[]>("detect", request);
3432
}
3533

3634
/// <summary>
@@ -56,17 +54,15 @@ public async Task<string> DetectCodeAsync(string text) {
5654
/// <exception cref="DetectLanguageException">Thrown if the request fails.</exception>
5755
public async Task<DetectResult[][]> BatchDetectAsync(string[] texts) {
5856
var request = new BatchDetectRequest{ q = texts };
59-
var response = await httpClient.PostAsync<BatchDetectResponse>("detect", request);
60-
61-
return response.data.detections;
57+
return await httpClient.PostAsync<DetectResult[][]>("detect-batch", request);
6258
}
6359

6460
/// <summary>
6561
/// Get account status
6662
/// </summary>
6763
/// <exception cref="DetectLanguageException">Thrown if the request fails.</exception>
68-
public async Task<UserStatus> GetUserStatusAsync() {
69-
return await httpClient.GetAsync<UserStatus>("user/status");
64+
public async Task<AccountStatus> GetAccountStatusAsync() {
65+
return await httpClient.GetAsync<AccountStatus>("account/status");
7066
}
7167

7268
/// <summary>

DetectLanguage/DetectLanguageConfiguration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class DetectLanguageConfiguration {
1414
/// <summary>
1515
/// The API base URI to use on a per-request basis
1616
/// </summary>
17-
public string ApiBase { get; set; } = "https://ws.detectlanguage.com/0.2/";
17+
public string ApiBase { get; set; } = "https://ws.detectlanguage.com/v3/";
1818

1919
/// <summary>
2020
/// HTTP request timeout

0 commit comments

Comments
 (0)