Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 15126003a9 | |||
| 762e3df704 | |||
| ec959f1500 |
59
.gitea/workflows/branch-build.yml
Normal file
59
.gitea/workflows/branch-build.yml
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
name: Branch Build
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- '**'
|
||||||
|
|
||||||
|
env:
|
||||||
|
TZ: 'Europe/Berlin'
|
||||||
|
LANG: 'de'
|
||||||
|
CONFIGURATION: 'Debug'
|
||||||
|
GITEA_SERVER_URL: ${{ gitea.server_url }}
|
||||||
|
CI_COMMIT_TAG: ${{ gitea.ref_name }}
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-test-deploy:
|
||||||
|
runs-on: ubuntu
|
||||||
|
defaults:
|
||||||
|
run:
|
||||||
|
shell: bash
|
||||||
|
steps:
|
||||||
|
- name: Setup dotnet
|
||||||
|
uses: actions/setup-dotnet@v5
|
||||||
|
with:
|
||||||
|
dotnet-version: 10.x
|
||||||
|
cache: false
|
||||||
|
|
||||||
|
- name: Checkout repository code
|
||||||
|
uses: actions/checkout@v6
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Restore tools
|
||||||
|
run: |
|
||||||
|
set -ex
|
||||||
|
dotnet tool restore -v q
|
||||||
|
dotnet tool install dotnet-reportgenerator-globaltool --tool-path /dotnet-tools
|
||||||
|
echo "CI_SERVER_HOST=${GITEA_SERVER_URL#https://}" >> "$GITEA_ENV"
|
||||||
|
|
||||||
|
- name: Build solution
|
||||||
|
run: |
|
||||||
|
set -ex
|
||||||
|
shopt -s globstar
|
||||||
|
mkdir /artifacts
|
||||||
|
dotnet build -c ${CONFIGURATION} --nologo --restore --force --no-cache
|
||||||
|
mv ./**/*.nupkg /artifacts/ || true
|
||||||
|
mv ./**/*.snupkg /artifacts/ || true
|
||||||
|
|
||||||
|
- name: Test solution
|
||||||
|
run: |
|
||||||
|
set -ex
|
||||||
|
dotnet test -c ${CONFIGURATION} --no-build --nologo /p:CoverletOutputFormat=Cobertura
|
||||||
|
/dotnet-tools/reportgenerator "-reports:${{ gitea.workspace }}/**/coverage.cobertura.xml" "-targetdir:/reports" "-reportType:TextSummary"
|
||||||
|
cat /reports/Summary.txt
|
||||||
|
|
||||||
|
- name: Publish packages
|
||||||
|
run: |
|
||||||
|
set -ex
|
||||||
|
dotnet nuget push -k "${{ secrets.BAGET_APIKEY }}" -s "https://nuget.am-wd.de/v3/index.json" --skip-duplicate /artifacts/*.nupkg
|
||||||
70
.gitea/workflows/release-build.yml
Normal file
70
.gitea/workflows/release-build.yml
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
name: Release Build
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- 'v*'
|
||||||
|
|
||||||
|
env:
|
||||||
|
TZ: 'Europe/Berlin'
|
||||||
|
LANG: 'de'
|
||||||
|
CONFIGURATION: 'Release'
|
||||||
|
GITEA_SERVER_URL: ${{ gitea.server_url }}
|
||||||
|
CI_COMMIT_TAG: ${{ gitea.ref_name }}
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-test-deploy:
|
||||||
|
runs-on: ubuntu
|
||||||
|
defaults:
|
||||||
|
run:
|
||||||
|
shell: bash
|
||||||
|
steps:
|
||||||
|
- name: Setup dotnet
|
||||||
|
uses: actions/setup-dotnet@v5
|
||||||
|
with:
|
||||||
|
dotnet-version: 10.x
|
||||||
|
cache: false
|
||||||
|
|
||||||
|
- name: Checkout repository code
|
||||||
|
uses: actions/checkout@v6
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Restore tools
|
||||||
|
run: |
|
||||||
|
set -ex
|
||||||
|
dotnet tool restore -v q
|
||||||
|
dotnet tool install dotnet-reportgenerator-globaltool --tool-path /dotnet-tools
|
||||||
|
dotnet tool install docfx --tool-path /dotnet-tools
|
||||||
|
echo "CI_SERVER_HOST=${GITEA_SERVER_URL#https://}" >> "$GITEA_ENV"
|
||||||
|
|
||||||
|
- name: Build solution
|
||||||
|
run: |
|
||||||
|
set -ex
|
||||||
|
shopt -s globstar
|
||||||
|
mkdir /artifacts
|
||||||
|
dotnet build -c ${CONFIGURATION} --nologo --restore --force --no-cache
|
||||||
|
mv ./**/*.nupkg /artifacts/ || true
|
||||||
|
mv ./**/*.snupkg /artifacts/ || true
|
||||||
|
|
||||||
|
- name: Test solution
|
||||||
|
run: |
|
||||||
|
set -ex
|
||||||
|
dotnet test -c ${CONFIGURATION} --no-build --nologo /p:CoverletOutputFormat=Cobertura
|
||||||
|
/dotnet-tools/reportgenerator "-reports:${{ gitea.workspace }}/**/coverage.cobertura.xml" "-targetdir:/reports" "-reportType:TextSummary"
|
||||||
|
cat /reports/Summary.txt
|
||||||
|
|
||||||
|
- name: Publish packages
|
||||||
|
run: |
|
||||||
|
set -ex
|
||||||
|
dotnet nuget push -k "${{ secrets.NUGET_APIKEY }}" -s "https://api.nuget.org/v3/index.json" --skip-duplicate /artifacts/*.nupkg
|
||||||
|
|
||||||
|
- name: Publish documentation
|
||||||
|
env:
|
||||||
|
DOCFX_SOURCE_REPOSITORY_URL: 'https://github.com/AM-WD/LinkMobility'
|
||||||
|
run: |
|
||||||
|
set -ex
|
||||||
|
/dotnet-tools/docfx metadata docs/docfx.json
|
||||||
|
/dotnet-tools/docfx build docs/docfx.json
|
||||||
|
tar -C "${{ gitea.workspace }}/docs/_site" -czf "/artifacts/docs.tar.gz" .
|
||||||
|
curl -sSL --no-progress-meter --user "${{ secrets.DOCS_DEPLOY_USER }}:${{ secrets.DOCS_DEPLOY_PASS }}" -F docs=linkmobility -F dump=@/artifacts/docs.tar.gz "${{ vars.DOCS_DEPLOY_URL }}"
|
||||||
130
.gitlab-ci.yml
130
.gitlab-ci.yml
@@ -1,130 +0,0 @@
|
|||||||
image: mcr.microsoft.com/dotnet/sdk:10.0
|
|
||||||
|
|
||||||
variables:
|
|
||||||
TZ: "Europe/Berlin"
|
|
||||||
LANG: "de"
|
|
||||||
|
|
||||||
stages:
|
|
||||||
- build
|
|
||||||
- test
|
|
||||||
- deploy
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
build-debug:
|
|
||||||
stage: build
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
- lnx
|
|
||||||
- 64bit
|
|
||||||
rules:
|
|
||||||
- if: $CI_COMMIT_TAG == null
|
|
||||||
script:
|
|
||||||
- dotnet build -c Debug --nologo
|
|
||||||
- mkdir ./artifacts
|
|
||||||
- shopt -s globstar
|
|
||||||
- mv ./**/*.nupkg ./artifacts/ || true
|
|
||||||
- mv ./**/*.snupkg ./artifacts/ || true
|
|
||||||
artifacts:
|
|
||||||
paths:
|
|
||||||
- artifacts/*.nupkg
|
|
||||||
- artifacts/*.snupkg
|
|
||||||
expire_in: 1 days
|
|
||||||
|
|
||||||
test-debug:
|
|
||||||
stage: test
|
|
||||||
dependencies:
|
|
||||||
- build-debug
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
- lnx
|
|
||||||
- 64bit
|
|
||||||
rules:
|
|
||||||
- if: $CI_COMMIT_TAG == null
|
|
||||||
coverage: /Branch coverage[\s\S].+%/
|
|
||||||
before_script:
|
|
||||||
- dotnet tool install dotnet-reportgenerator-globaltool --tool-path /dotnet-tools
|
|
||||||
script:
|
|
||||||
- dotnet test -c Debug --nologo /p:CoverletOutputFormat=Cobertura
|
|
||||||
- /dotnet-tools/reportgenerator "-reports:${CI_PROJECT_DIR}/**/coverage.cobertura.xml" "-targetdir:/reports" "-reportType:TextSummary"
|
|
||||||
- cat /reports/Summary.txt
|
|
||||||
artifacts:
|
|
||||||
when: always
|
|
||||||
reports:
|
|
||||||
coverage_report:
|
|
||||||
coverage_format: cobertura
|
|
||||||
path: ./**/coverage.cobertura.xml
|
|
||||||
|
|
||||||
deploy-debug:
|
|
||||||
stage: deploy
|
|
||||||
dependencies:
|
|
||||||
- build-debug
|
|
||||||
- test-debug
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
- lnx
|
|
||||||
- server
|
|
||||||
rules:
|
|
||||||
- if: $CI_COMMIT_TAG == null
|
|
||||||
script:
|
|
||||||
- dotnet nuget push -k $BAGET_APIKEY -s https://nuget.home.am-wd.de/v3/index.json --skip-duplicate artifacts/*.nupkg || true
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
build-release:
|
|
||||||
stage: build
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
- lnx
|
|
||||||
- 64bit
|
|
||||||
rules:
|
|
||||||
- if: $CI_COMMIT_TAG != null
|
|
||||||
script:
|
|
||||||
- dotnet build -c Release --nologo
|
|
||||||
- mkdir ./artifacts
|
|
||||||
- shopt -s globstar
|
|
||||||
- mv ./**/*.nupkg ./artifacts/
|
|
||||||
- mv ./**/*.snupkg ./artifacts/
|
|
||||||
artifacts:
|
|
||||||
paths:
|
|
||||||
- artifacts/*.nupkg
|
|
||||||
- artifacts/*.snupkg
|
|
||||||
expire_in: 7 days
|
|
||||||
|
|
||||||
test-release:
|
|
||||||
stage: test
|
|
||||||
dependencies:
|
|
||||||
- build-release
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
- lnx
|
|
||||||
- 64bit
|
|
||||||
rules:
|
|
||||||
- if: $CI_COMMIT_TAG != null
|
|
||||||
before_script:
|
|
||||||
- dotnet tool install dotnet-reportgenerator-globaltool --tool-path /dotnet-tools
|
|
||||||
script:
|
|
||||||
- dotnet test -c Release --nologo /p:CoverletOutputFormat=Cobertura
|
|
||||||
- /dotnet-tools/reportgenerator "-reports:${CI_PROJECT_DIR}/**/coverage.cobertura.xml" "-targetdir:/reports" -reportType:TextSummary
|
|
||||||
- cat /reports/Summary.txt
|
|
||||||
artifacts:
|
|
||||||
when: always
|
|
||||||
reports:
|
|
||||||
coverage_report:
|
|
||||||
coverage_format: cobertura
|
|
||||||
path: ./**/coverage.cobertura.xml
|
|
||||||
|
|
||||||
deploy-release:
|
|
||||||
stage: deploy
|
|
||||||
dependencies:
|
|
||||||
- build-release
|
|
||||||
- test-release
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
- lnx
|
|
||||||
- server
|
|
||||||
rules:
|
|
||||||
- if: $CI_COMMIT_TAG != null
|
|
||||||
script:
|
|
||||||
- dotnet nuget push -k $NUGET_APIKEY -s https://api.nuget.org/v3/index.json --skip-duplicate artifacts/*.nupkg
|
|
||||||
|
|
||||||
13
CHANGELOG.md
13
CHANGELOG.md
@@ -9,6 +9,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
_No changes yet_
|
_No changes yet_
|
||||||
|
|
||||||
|
## [v0.1.1] - 2026-03-13
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Added optional parameter to inject your own `HttpClient`
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Migrated main repository from Gitlab to Gitea
|
||||||
|
|
||||||
|
|
||||||
## [v0.1.0] - 2025-12-03
|
## [v0.1.0] - 2025-12-03
|
||||||
|
|
||||||
@@ -25,6 +35,7 @@ _Initial release, SMS only._
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
[Unreleased]: https://github.com/AM-WD/LinkMobility/compare/v0.1.0...HEAD
|
[Unreleased]: https://github.com/AM-WD/LinkMobility/compare/v0.1.1...HEAD
|
||||||
|
|
||||||
|
[v0.1.1]: https://github.com/AM-WD/LinkMobility/compare/v0.1.0...v0.1.1
|
||||||
[v0.1.0]: https://github.com/AM-WD/LinkMobility/commits/v0.1.0
|
[v0.1.0]: https://github.com/AM-WD/LinkMobility/commits/v0.1.0
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<LangVersion>14.0</LangVersion>
|
<LangVersion>14.0</LangVersion>
|
||||||
<NrtRevisionFormat>{semvertag:main}{!:-dev}</NrtRevisionFormat>
|
<NrtRevisionFormat>{semvertag:main}{!:-dev}</NrtRevisionFormat>
|
||||||
|
<NrtContinuousIntegrationBuild>$(ContinuousIntegrationBuild)</NrtContinuousIntegrationBuild>
|
||||||
|
|
||||||
<AppendTargetFrameworkToOutputPath>true</AppendTargetFrameworkToOutputPath>
|
<AppendTargetFrameworkToOutputPath>true</AppendTargetFrameworkToOutputPath>
|
||||||
<CopyRefAssembliesToPublishDirectory>false</CopyRefAssembliesToPublishDirectory>
|
<CopyRefAssembliesToPublishDirectory>false</CopyRefAssembliesToPublishDirectory>
|
||||||
@@ -16,20 +17,21 @@
|
|||||||
<Copyright>© {copyright:2025-} AM.WD</Copyright>
|
<Copyright>© {copyright:2025-} AM.WD</Copyright>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup Condition="'$(GITLAB_CI)' == 'true'">
|
<PropertyGroup Condition="'$(CI)' == 'true'">
|
||||||
|
<EmbedUntrackedSources>true</EmbedUntrackedSources>
|
||||||
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
|
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup Condition="'$(GITLAB_CI)' == 'true'">
|
<ItemGroup Condition="'$(CI)' == 'true'">
|
||||||
<SourceLinkGitLabHost Include="$(CI_SERVER_HOST)" Version="$(CI_SERVER_VERSION)" />
|
<SourceLinkGiteaHost Include="$(CI_SERVER_HOST)" />
|
||||||
<PackageReference Include="Microsoft.SourceLink.GitLab" Version="8.0.0">
|
<PackageReference Include="Microsoft.SourceLink.Gitea" Version="8.0.0">
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="AMWD.NetRevisionTask" Version="1.3.0">
|
<PackageReference Include="AMWD.NetRevisionTask" Version="1.4.0">
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
<Solution>
|
<Solution>
|
||||||
<Folder Name="/Solution Items/" />
|
<Folder Name="/Solution Items/" />
|
||||||
<Folder Name="/Solution Items/build/">
|
<Folder Name="/Solution Items/build/">
|
||||||
<File Path=".gitlab-ci.yml" />
|
|
||||||
<File Path="Directory.Build.props" />
|
<File Path="Directory.Build.props" />
|
||||||
</Folder>
|
</Folder>
|
||||||
|
<Folder Name="/Solution Items/build/workflows/">
|
||||||
|
<File Path=".gitea/workflows/branch-build.yml" />
|
||||||
|
<File Path=".gitea/workflows/release-build.yml" />
|
||||||
|
</Folder>
|
||||||
<Folder Name="/Solution Items/config/">
|
<Folder Name="/Solution Items/config/">
|
||||||
<File Path=".editorconfig" />
|
<File Path=".editorconfig" />
|
||||||
<File Path=".gitignore" />
|
<File Path=".gitignore" />
|
||||||
|
|||||||
@@ -40,6 +40,6 @@ namespace AMWD.Net.Api.LinkMobility
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the proxy information.
|
/// Gets or sets the proxy information.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public virtual IWebProxy Proxy { get; set; }
|
public virtual IWebProxy? Proxy { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,10 +10,10 @@
|
|||||||
<AssemblyName>amwd-linkmobility</AssemblyName>
|
<AssemblyName>amwd-linkmobility</AssemblyName>
|
||||||
<RootNamespace>AMWD.Net.Api.LinkMobility</RootNamespace>
|
<RootNamespace>AMWD.Net.Api.LinkMobility</RootNamespace>
|
||||||
|
|
||||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
|
||||||
<IncludeSymbols>true</IncludeSymbols>
|
<IncludeSymbols>true</IncludeSymbols>
|
||||||
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
|
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
|
||||||
<EmbedUntrackedSources>false</EmbedUntrackedSources>
|
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||||
|
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||||
|
|
||||||
<PackageIcon>package-icon.png</PackageIcon>
|
<PackageIcon>package-icon.png</PackageIcon>
|
||||||
<PackageProjectUrl>https://developer.linkmobility.eu/</PackageProjectUrl>
|
<PackageProjectUrl>https://developer.linkmobility.eu/</PackageProjectUrl>
|
||||||
@@ -22,8 +22,6 @@
|
|||||||
|
|
||||||
<Product>LINK Mobility REST API</Product>
|
<Product>LINK Mobility REST API</Product>
|
||||||
<Description>Implementation of the LINK Mobility REST API using .NET</Description>
|
<Description>Implementation of the LINK Mobility REST API using .NET</Description>
|
||||||
|
|
||||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ namespace AMWD.Net.Api.LinkMobility
|
|||||||
return PostAsync<SendMessageResponse, SendBinaryMessageRequest>("/smsmessaging/binary", request, cancellationToken: cancellationToken);
|
return PostAsync<SendMessageResponse, SendBinaryMessageRequest>("/smsmessaging/binary", request, cancellationToken: cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://en.wikipedia.org/wiki/MSISDN
|
||||||
private static bool IsValidMSISDN(string msisdn)
|
private static bool IsValidMSISDN(string msisdn)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(msisdn))
|
if (string.IsNullOrWhiteSpace(msisdn))
|
||||||
|
|||||||
@@ -26,8 +26,9 @@ namespace AMWD.Net.Api.LinkMobility
|
|||||||
/// <param name="username">The username used for basic authentication.</param>
|
/// <param name="username">The username used for basic authentication.</param>
|
||||||
/// <param name="password">The password used for basic authentication.</param>
|
/// <param name="password">The password used for basic authentication.</param>
|
||||||
/// <param name="clientOptions">Optional configuration settings for the client.</param>
|
/// <param name="clientOptions">Optional configuration settings for the client.</param>
|
||||||
public LinkMobilityClient(string username, string password, ClientOptions? clientOptions = null)
|
/// <param name="httpClient">Optional <see cref="HttpClient"/> instance if you want a custom <see cref="HttpMessageHandler"/> implemented.</param>
|
||||||
: this(new BasicAuthentication(username, password), clientOptions)
|
public LinkMobilityClient(string username, string password, ClientOptions? clientOptions = null, HttpClient? httpClient = null)
|
||||||
|
: this(new BasicAuthentication(username, password), clientOptions, httpClient)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,8 +37,9 @@ namespace AMWD.Net.Api.LinkMobility
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="token">The bearer token used for authentication.</param>
|
/// <param name="token">The bearer token used for authentication.</param>
|
||||||
/// <param name="clientOptions">Optional configuration settings for the client.</param>
|
/// <param name="clientOptions">Optional configuration settings for the client.</param>
|
||||||
public LinkMobilityClient(string token, ClientOptions? clientOptions = null)
|
/// <param name="httpClient">Optional <see cref="HttpClient"/> instance if you want a custom <see cref="HttpMessageHandler"/> implemented.</param>
|
||||||
: this(new AccessTokenAuthentication(token), clientOptions)
|
public LinkMobilityClient(string token, ClientOptions? clientOptions = null, HttpClient? httpClient = null)
|
||||||
|
: this(new AccessTokenAuthentication(token), clientOptions, httpClient)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,7 +49,8 @@ namespace AMWD.Net.Api.LinkMobility
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="authentication">The authentication mechanism used to authorize requests.</param>
|
/// <param name="authentication">The authentication mechanism used to authorize requests.</param>
|
||||||
/// <param name="clientOptions">Optional client configuration settings.</param>
|
/// <param name="clientOptions">Optional client configuration settings.</param>
|
||||||
public LinkMobilityClient(IAuthentication authentication, ClientOptions? clientOptions = null)
|
/// <param name="httpClient">Optional <see cref="HttpClient"/> instance if you want a custom <see cref="HttpMessageHandler"/> implemented.</param>
|
||||||
|
public LinkMobilityClient(IAuthentication authentication, ClientOptions? clientOptions = null, HttpClient? httpClient = null)
|
||||||
{
|
{
|
||||||
if (authentication == null)
|
if (authentication == null)
|
||||||
throw new ArgumentNullException(nameof(authentication));
|
throw new ArgumentNullException(nameof(authentication));
|
||||||
@@ -55,7 +58,9 @@ namespace AMWD.Net.Api.LinkMobility
|
|||||||
_clientOptions = clientOptions ?? new ClientOptions();
|
_clientOptions = clientOptions ?? new ClientOptions();
|
||||||
ValidateClientOptions();
|
ValidateClientOptions();
|
||||||
|
|
||||||
_httpClient = CreateHttpClient();
|
_httpClient = httpClient ?? CreateHttpClient();
|
||||||
|
ConfigureHttpClient(_httpClient);
|
||||||
|
|
||||||
authentication.AddHeader(_httpClient);
|
authentication.AddHeader(_httpClient);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,24 +123,29 @@ namespace AMWD.Net.Api.LinkMobility
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var httpClient = new HttpClient(handler, disposeHandler: true);
|
||||||
|
|
||||||
|
httpClient.DefaultRequestHeaders.UserAgent.Clear();
|
||||||
|
httpClient.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue(nameof(LinkMobilityClient), version));
|
||||||
|
|
||||||
|
return httpClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ConfigureHttpClient(HttpClient httpClient)
|
||||||
|
{
|
||||||
string baseUrl = _clientOptions.BaseUrl.Trim().TrimEnd('/');
|
string baseUrl = _clientOptions.BaseUrl.Trim().TrimEnd('/');
|
||||||
|
|
||||||
var client = new HttpClient(handler, disposeHandler: true)
|
httpClient.BaseAddress = new Uri($"{baseUrl}/");
|
||||||
{
|
httpClient.Timeout = _clientOptions.Timeout;
|
||||||
BaseAddress = new Uri($"{baseUrl}/"),
|
|
||||||
Timeout = _clientOptions.Timeout
|
|
||||||
};
|
|
||||||
|
|
||||||
client.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue(nameof(LinkMobilityClient), version));
|
httpClient.DefaultRequestHeaders.Accept.Clear();
|
||||||
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||||
|
|
||||||
if (_clientOptions.DefaultHeaders.Count > 0)
|
if (_clientOptions.DefaultHeaders.Count > 0)
|
||||||
{
|
{
|
||||||
foreach (var headerKvp in _clientOptions.DefaultHeaders)
|
foreach (var headerKvp in _clientOptions.DefaultHeaders)
|
||||||
client.DefaultRequestHeaders.Add(headerKvp.Key, headerKvp.Value);
|
httpClient.DefaultRequestHeaders.Add(headerKvp.Key, headerKvp.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
return client;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<TResponse> PostAsync<TResponse, TRequest>(string requestPath, TRequest? request, IQueryParameter? queryParams = null, CancellationToken cancellationToken = default)
|
private async Task<TResponse> PostAsync<TResponse, TRequest>(string requestPath, TRequest? request, IQueryParameter? queryParams = null, CancellationToken cancellationToken = default)
|
||||||
@@ -146,8 +156,16 @@ namespace AMWD.Net.Api.LinkMobility
|
|||||||
string requestUrl = BuildRequestUrl(requestPath, queryParams);
|
string requestUrl = BuildRequestUrl(requestPath, queryParams);
|
||||||
var httpContent = ConvertRequest(request);
|
var httpContent = ConvertRequest(request);
|
||||||
|
|
||||||
var response = await _httpClient.PostAsync(requestUrl, httpContent, cancellationToken).ConfigureAwait(false);
|
var httpRequest = new HttpRequestMessage
|
||||||
return await GetResponse<TResponse>(response, cancellationToken).ConfigureAwait(false);
|
{
|
||||||
|
Method = HttpMethod.Post,
|
||||||
|
RequestUri = new Uri(requestUrl, UriKind.Relative),
|
||||||
|
Content = httpContent,
|
||||||
|
};
|
||||||
|
|
||||||
|
var httpResponse = await _httpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
|
||||||
|
var response = await GetResponse<TResponse>(httpResponse, cancellationToken).ConfigureAwait(false);
|
||||||
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
private string BuildRequestUrl(string requestPath, IQueryParameter? queryParams = null)
|
private string BuildRequestUrl(string requestPath, IQueryParameter? queryParams = null)
|
||||||
|
|||||||
@@ -1,20 +1,38 @@
|
|||||||
namespace AMWD.Net.Api.LinkMobility
|
namespace AMWD.Net.Api.LinkMobility
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A generic response of the LinkMobility API.
|
||||||
|
/// </summary>
|
||||||
public class LinkMobilityResponse
|
public class LinkMobilityResponse
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Contains the message id defined in the request.
|
||||||
|
/// </summary>
|
||||||
[JsonProperty("clientMessageId")]
|
[JsonProperty("clientMessageId")]
|
||||||
public string ClientMessageId { get; set; }
|
public string? ClientMessageId { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The actual number of generated SMS.
|
||||||
|
/// </summary>
|
||||||
[JsonProperty("smsCount")]
|
[JsonProperty("smsCount")]
|
||||||
public int SmsCount { get; set; }
|
public int? SmsCount { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Status code
|
||||||
|
/// </summary>
|
||||||
[JsonProperty("statusCode")]
|
[JsonProperty("statusCode")]
|
||||||
public StatusCodes StatusCode { get; set; }
|
public StatusCodes? StatusCode { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Description of the response status code.
|
||||||
|
/// </summary>
|
||||||
[JsonProperty("statusMessage")]
|
[JsonProperty("statusMessage")]
|
||||||
public string StatusMessage { get; set; }
|
public string? StatusMessage { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Unique identifier that is set after successful processing of the request.
|
||||||
|
/// </summary>
|
||||||
[JsonProperty("transferId")]
|
[JsonProperty("transferId")]
|
||||||
public string TransferId { get; set; }
|
public string? TransferId { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Retrieves the query parameters.
|
/// Retrieves the query parameters.
|
||||||
|
/// </summary>
|
||||||
IReadOnlyDictionary<string, string> GetQueryParameters();
|
IReadOnlyDictionary<string, string> GetQueryParameters();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user