-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from dutchgrit/develop
merge: develop into main
- Loading branch information
Showing
71 changed files
with
4,202 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -191,3 +191,6 @@ NuGetBackup | |
error-*.xml | ||
|
||
PublishOutput/ | ||
|
||
# afascli | ||
afas-cli.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.4.33213.308 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AfasClient", "src\AfasClient.csproj", "{EADE59A9-F190-4CE8-96F9-FDFCA6ED0C89}" | ||
EndProject | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AfasClient.Test", "test\AfasClient.Test.csproj", "{7474F40B-DE4A-43AB-9151-205323440276}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{EADE59A9-F190-4CE8-96F9-FDFCA6ED0C89}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{EADE59A9-F190-4CE8-96F9-FDFCA6ED0C89}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{EADE59A9-F190-4CE8-96F9-FDFCA6ED0C89}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{EADE59A9-F190-4CE8-96F9-FDFCA6ED0C89}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{7474F40B-DE4A-43AB-9151-205323440276}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{7474F40B-DE4A-43AB-9151-205323440276}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{7474F40B-DE4A-43AB-9151-205323440276}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{7474F40B-DE4A-43AB-9151-205323440276}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {BCA53C4B-1269-40BF-AB07-744328BE6610} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# LICENSE | ||
(c) DutchGrit 2022, a Lucrasoft Digital B.V. brand. All rights reservered. | ||
|
||
Please contact us at DutchGrit.nl for licensing options. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
# Afas Library | ||
|
||
The documentation is maintained on a public github repository [here](https://github.com/dutchgrit/afasclient) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
using Newtonsoft.Json; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Net; | ||
using System.Net.Http; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace DutchGrit.Afas | ||
{ | ||
public class AfasBase : GeneralBase | ||
{ | ||
|
||
protected HttpClient httpClient = GeneralBase.httpClientInternal; | ||
|
||
protected int MemberNumber { get; set; } | ||
|
||
protected Environments Environment { get; set; } | ||
|
||
protected string Token64 { get; set; } | ||
|
||
protected override string GetBaseUrl | ||
{ | ||
get | ||
{ | ||
return $"https://{MemberNumber}.rest{Environment.AsUrlAddition()}.afas.online/profitrestservices/"; | ||
} | ||
} | ||
|
||
protected override async Task<HttpResponseMessage> GetAuthHttp(string urlPath) | ||
{ | ||
using (var httpRequestMessage = new HttpRequestMessage | ||
{ | ||
Method = HttpMethod.Get, | ||
RequestUri = new Uri(this.GetBaseUrl + urlPath), | ||
Headers = { | ||
{ "Authorization", this.Token64 } | ||
} | ||
}) | ||
{ | ||
return await httpClient.SendAsync(httpRequestMessage); | ||
} | ||
} | ||
|
||
|
||
protected override async Task<HttpResponseMessage> SendAuthHttp(string urlPath, string content, HttpMethod method) | ||
{ | ||
using (var httpRequestMessage = new HttpRequestMessage | ||
{ | ||
Method = method, | ||
RequestUri = new Uri(this.GetBaseUrl + urlPath), | ||
Headers = { | ||
{ "Authorization", this.Token64 } | ||
}, | ||
Content = new StringContent(content) | ||
}) | ||
{ | ||
return await httpClient.SendAsync(httpRequestMessage); | ||
} | ||
} | ||
|
||
protected override async Task<HttpResponseMessage> OtpPost(string urlPath, string content) | ||
{ | ||
using (var httpRequestMessage = new HttpRequestMessage | ||
{ | ||
Method = HttpMethod.Post, | ||
RequestUri = new Uri(this.GetBaseUrl + urlPath), | ||
Content = new StringContent(content) | ||
}) | ||
{ | ||
return await httpClient.SendAsync(httpRequestMessage); | ||
} | ||
} | ||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
using Newtonsoft.Json; | ||
using System; | ||
using System.Net; | ||
using System.Net.Http; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace DutchGrit.Afas | ||
{ | ||
|
||
public class AfasClient : AfasBase, IAfasClient | ||
{ | ||
|
||
public AfasClient(int MemberNumber, string Token, Environments Env = Environments.Production, HttpClient customHttpClient=null) | ||
{ | ||
this.MemberNumber = MemberNumber; | ||
this.Environment = Env; | ||
//Convert the Token string into Base64. | ||
var authToken = Encoding.ASCII.GetBytes(Token); | ||
this.Token64 = "AfasToken " + Convert.ToBase64String(authToken); | ||
|
||
|
||
if (customHttpClient != null) | ||
{ | ||
this.httpClient = customHttpClient; | ||
} | ||
} | ||
|
||
public Task<SessionInfo> GetSessionInfoAsync() | ||
{ | ||
return GetApiAsync<SessionInfo>("metainfo"); | ||
} | ||
|
||
public Task<UpdateConMetaInfo> GetMetaDataUpdConAsync(string connector) | ||
{ | ||
return GetApiAsync<UpdateConMetaInfo>($"metainfo/update/{connector}"); | ||
} | ||
|
||
public Task<GetConMetaInfo> GetMetaDataGetConAsync(string connector) | ||
{ | ||
return GetApiAsync<GetConMetaInfo>($"metainfo/get/{connector}"); | ||
} | ||
|
||
public async Task<string> GetVersionAsync() | ||
{ | ||
//Only works when AppConnectorVersion is included! | ||
var z = await this.GetApiAsync<AfasVersion>("profitversion"); | ||
return z.Version; | ||
} | ||
|
||
|
||
public async Task<FileInfo> GetFileBySubjectAsync(int SubjectID, string FileID) | ||
{ | ||
using (var res = await this.GetAuthHttp($"subjectconnector/{SubjectID}/{FileID}")) | ||
{ | ||
int code = (int)res.StatusCode; | ||
if (code >= 200 && code <= 299) | ||
{ | ||
var txt = await res.Content.ReadAsStringAsync(); | ||
return JsonConvert.DeserializeObject<FileInfo>(txt); | ||
} | ||
if (res.StatusCode == HttpStatusCode.NotFound) | ||
{ | ||
return null; | ||
} | ||
//bij een andere reden, gewoon laten klappen! | ||
res.EnsureSuccessStatusCode(); | ||
return null; | ||
} | ||
} | ||
|
||
public AfasQuery<T> Query<T>() where T : IGetEntity | ||
{ | ||
return new AfasQuery<T>(this); | ||
} | ||
|
||
|
||
public string GetVersion() => AsyncHelpers.RunSync<string>(() => GetVersionAsync()); | ||
|
||
public SessionInfo GetSessionInfo() => AsyncHelpers.RunSync<SessionInfo>(() => GetSessionInfoAsync()); | ||
|
||
public FileInfo GetFileBySubject(int SubjectID, string FileID) => AsyncHelpers.RunSync<FileInfo>( () => GetFileBySubjectAsync(SubjectID, FileID )); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.1</TargetFramework> | ||
<UserSecretsId>2508f9d2-d815-49df-a709-f739ec918282</UserSecretsId> | ||
<RootNamespace>DutchGrit.Afas</RootNamespace> | ||
<AssemblyName>DutchGrit.AfasClient</AssemblyName> | ||
<Company>DutchGrit - Lucrasoft Digital BV</Company> | ||
<Copyright>Lucrasoft Digital BV</Copyright> | ||
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance> | ||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo> | ||
<GeneratePackageOnBuild>false</GeneratePackageOnBuild> | ||
<Authors>DutchGrit</Authors> | ||
<Description>.NET Standard 2.0 Library for interacting with the AFAS (Profit) RestAPI</Description> | ||
<PackageLicenseExpression></PackageLicenseExpression> | ||
<PackageLicenseFile>LICENSE.md</PackageLicenseFile> | ||
<AssemblyVersion>1.0.0.0</AssemblyVersion> | ||
<FileVersion>1.0.0.0</FileVersion> | ||
<Version>1.0.0.0</Version> | ||
<PackageProjectUrl></PackageProjectUrl> | ||
<RepositoryUrl>https://github.com/dutchgrit/afasclient</RepositoryUrl> | ||
<SignAssembly>false</SignAssembly> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" /> | ||
<PackageReference Include="System.ComponentModel.Annotations" Version="4.7.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Include="../LICENSE.md"> | ||
<Pack>True</Pack> | ||
<PackagePath></PackagePath> | ||
</None> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Folder Include="Images\" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Oops, something went wrong.