Skip to content

Commit

Permalink
Merge pull request #12 from dutchgrit/afasclient-optional-integrationid
Browse files Browse the repository at this point in the history
Added IntegrationId as optional param to AfasClient
  • Loading branch information
LucasVos authored Jan 27, 2025
2 parents 8058b85 + 7020878 commit 6414db4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
13 changes: 13 additions & 0 deletions src/src/AfasBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public class AfasBase : GeneralBase

protected string Token64 { get; set; }

protected string IntegrationId { get; set; }

protected override string GetBaseUrl
{
get
Expand All @@ -38,6 +40,7 @@ protected override async Task<HttpResponseMessage> GetAuthHttp(string urlPath)
}
})
{
AddIntegrationId(httpRequestMessage);
return await httpClient.SendAsync(httpRequestMessage);
}
}
Expand All @@ -55,6 +58,7 @@ protected override async Task<HttpResponseMessage> SendAuthHttp(string urlPath,
Content = new StringContent(content)
})
{
AddIntegrationId(httpRequestMessage);
return await httpClient.SendAsync(httpRequestMessage);
}
}
Expand All @@ -72,6 +76,15 @@ protected override async Task<HttpResponseMessage> OtpPost(string urlPath, strin
}
}

private void AddIntegrationId(HttpRequestMessage httpRequestMessage)
{
if (httpClient.DefaultRequestHeaders.Contains("IntegrationId"))
httpClient.DefaultRequestHeaders.Remove("IntegrationId");
if (!string.IsNullOrWhiteSpace(this.IntegrationId))
{
httpRequestMessage.Headers.Add("IntegrationId", this.IntegrationId);
}
}

}
}
11 changes: 9 additions & 2 deletions src/src/AfasClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,21 @@ namespace DutchGrit.Afas

public class AfasClient : AfasBase, IAfasClient
{

public AfasClient(int MemberNumber, string Token, Environments Env = Environments.Production, HttpClient customHttpClient=null)
/// <summary>
/// Constructor for the AfasClient
/// </summary>
/// <param name="integrationId">The integrationId to add as a request header. https://docs.afas.help/Profit/nl/IntegrationId</param>
/// <remarks>
/// Note: If a customHttpClient is provided, the integrationId header will be overwritten by the integrationId parameter.
/// </remarks>
public AfasClient(int MemberNumber, string Token, Environments Env = Environments.Production, HttpClient customHttpClient = null, string integrationId = 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);
this.IntegrationId = integrationId;


if (customHttpClient != null)
Expand Down

0 comments on commit 6414db4

Please sign in to comment.