Compare commits
7 Commits
v0.1.0
...
7392b0eb98
| Author | SHA1 | Date | |
|---|---|---|---|
| 7392b0eb98 | |||
| 3f8cece95c | |||
| 79567c730c | |||
| 94706dd82d | |||
| 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
|
|
||||||
|
|
||||||
28
CHANGELOG.md
28
CHANGELOG.md
@@ -7,7 +7,30 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
_No changes yet_
|
### Added
|
||||||
|
|
||||||
|
- `Validation` utility class for specifications as MSISDN
|
||||||
|
- Docs rendering using DocFX
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Channel implementations (SMS, WhatsApp, ...) are extensions to the `ILinkMobilityClient` interface.
|
||||||
|
- Reorganized namespaces to reflect parts of the API
|
||||||
|
|
||||||
|
### Removed
|
||||||
|
|
||||||
|
- `IQueryParameter` as no usage on API docs found (for now)
|
||||||
|
|
||||||
|
|
||||||
|
## [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 +48,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" />
|
||||||
|
|||||||
@@ -10,11 +10,11 @@ So I decided to implement the current available API myself with a more modern (a
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
Published under [MIT License] (see [**tl;dr**Legal])
|
Published under [MIT License] (see [choose a license])
|
||||||
|
|
||||||
|
|
||||||
[LINK Mobility REST API]: https://developer.linkmobility.eu/
|
[LINK Mobility REST API]: https://developer.linkmobility.eu/
|
||||||
[outdated repository]: https://github.com/websms-com/websmscom-csharp
|
[outdated repository]: https://github.com/websms-com/websmscom-csharp
|
||||||
[.NET Standard 2.0]: https://learn.microsoft.com/en-us/dotnet/standard/net-standard?tabs=net-standard-2-0
|
[.NET Standard 2.0]: https://learn.microsoft.com/en-us/dotnet/standard/net-standard?tabs=net-standard-2-0
|
||||||
[MIT License]: LICENSE.txt
|
[MIT License]: LICENSE.txt
|
||||||
[**tl;dr**Legal]: https://www.tldrlegal.com/license/mit-license
|
[choose a license]: https://choosealicense.com/licenses/mit/
|
||||||
|
|||||||
61
docs/docfx.json
Normal file
61
docs/docfx.json
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
{
|
||||||
|
"$schema": "https://raw.githubusercontent.com/dotnet/docfx/main/schemas/docfx.schema.json",
|
||||||
|
"metadata": [
|
||||||
|
{
|
||||||
|
"src": [
|
||||||
|
{
|
||||||
|
"src": "../",
|
||||||
|
"files": [
|
||||||
|
"src/LinkMobility/bin/Release/netstandard2.0/amwd-linkmobility.dll"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"dest": "api",
|
||||||
|
"outputFormat": "apiPage"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"build": {
|
||||||
|
"content": [
|
||||||
|
{
|
||||||
|
"files": [ "**/*.{md,yml}" ],
|
||||||
|
"exclude": [ "_site/**", "obj/**" ]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"resource": [
|
||||||
|
{
|
||||||
|
"files": [ "images/**" ],
|
||||||
|
"exclude": [ "_site/**", "obj/**" ]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"output": "_site",
|
||||||
|
"template": [ "default", "modern", "templates/amwd" ],
|
||||||
|
"postProcessors": ["ExtractSearchIndex"],
|
||||||
|
"globalMetadata": {
|
||||||
|
"_appName": "LINK Mobility REST API for .NET",
|
||||||
|
"_appTitle": "LINK Mobility REST API for .NET",
|
||||||
|
"_appFooter": "<span>© AM.WD — Docs generated using <a href=\"https://dotnet.github.io/docfx\" target=\"_blank\">docfx</a>.</span>",
|
||||||
|
"_appLogoPath": "images/icon.png",
|
||||||
|
"_appFaviconPath": "images/favicon.ico",
|
||||||
|
"_disableBreadcrumb": true,
|
||||||
|
"_disableContribution": true,
|
||||||
|
"_enableSearch": true,
|
||||||
|
"_enableNewTab": true,
|
||||||
|
"pdf": false
|
||||||
|
},
|
||||||
|
"markdownEngineName": "markdig",
|
||||||
|
"markdownEngineProperties": {
|
||||||
|
"alerts": {
|
||||||
|
"TODO": "alert alert-secondary"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"sitemap": {
|
||||||
|
"baseUrl": "https://docs.am-wd.de/linkmobility",
|
||||||
|
"priority": 0.5,
|
||||||
|
"changefreq": "weekly"
|
||||||
|
},
|
||||||
|
"noLangKeyword": false,
|
||||||
|
"keepFileLink": false,
|
||||||
|
"cleanupCacheHistory": false,
|
||||||
|
"disableGitFeatures": true
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
docs/images/favicon.ico
Normal file
BIN
docs/images/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 66 KiB |
BIN
docs/images/icon.png
Normal file
BIN
docs/images/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 978 B |
22
docs/index.md
Normal file
22
docs/index.md
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
---
|
||||||
|
_layout: landing
|
||||||
|
---
|
||||||
|
|
||||||
|
# LINK Mobility API
|
||||||
|
|
||||||
|
[LINK Mobility] is a company specialized in customer communication.
|
||||||
|
|
||||||
|
The available channels are SMS, RCS and WhatsApp Business.
|
||||||
|
|
||||||
|
## NuGet packages
|
||||||
|
|
||||||
|
Here is an overview of the latest package.
|
||||||
|
|
||||||
|
| Package URL | Version | Short Description |
|
||||||
|
|-------------|---------|-------------------|
|
||||||
|
| [AMWD.Net.Api.LinkMobility] |  | Package contains the interfaces to handle the API. |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[LINK Mobility]: https://linkmobility.eu
|
||||||
|
[AMWD.Net.Api.LinkMobility]: https://www.nuget.org/packages/AMWD.Net.Api.LinkMobility
|
||||||
3
docs/templates/amwd/public/main.css
vendored
Normal file
3
docs/templates/amwd/public/main.css
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
#logo {
|
||||||
|
margin-right: 8px;
|
||||||
|
}
|
||||||
4
docs/toc.yml
Normal file
4
docs/toc.yml
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
- name: API
|
||||||
|
href: api/
|
||||||
|
- name: GitHub
|
||||||
|
href: https://github.com/AM-WD/LinkMobility
|
||||||
@@ -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; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
namespace AMWD.Net.Api.LinkMobility
|
namespace AMWD.Net.Api.LinkMobility
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Custom status codes as defined by <see href="https://developer.linkmobility.eu/sms-api/rest-api#section/Status-codes">Link Mobility</see>.
|
/// Custom status codes as defined by
|
||||||
|
/// <see href="https://developer.linkmobility.eu/sms-api/rest-api#section/Status-codes">LINK Mobility</see>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public enum StatusCodes : int
|
public enum StatusCodes : int
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -9,17 +9,13 @@ namespace AMWD.Net.Api.LinkMobility
|
|||||||
public interface ILinkMobilityClient
|
public interface ILinkMobilityClient
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sends a text message to a list of recipients.
|
/// Performs a POST request to the LINK mobility API.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <typeparam name="TResponse">The type of the response.</typeparam>
|
||||||
|
/// <typeparam name="TRequest">The type of the request.</typeparam>
|
||||||
|
/// <param name="requestPath">The path of the API endpoint.</param>
|
||||||
/// <param name="request">The request data.</param>
|
/// <param name="request">The request data.</param>
|
||||||
/// <param name="cancellationToken">A cancellation token to propagate notification that operations should be canceled.</param>
|
/// <param name="cancellationToken">A cancellation token to propagate notification that operations should be canceled.</param>
|
||||||
Task<SendMessageResponse> SendTextMessage(SendTextMessageRequest request, CancellationToken cancellationToken = default);
|
Task<TResponse> PostAsync<TResponse, TRequest>(string requestPath, TRequest? request, CancellationToken cancellationToken = default);
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Sends a binary message to a list of recipients.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="request">The request data.</param>
|
|
||||||
/// <param name="cancellationToken">A cancellation token to propagate notification that operations should be canceled.</param>
|
|
||||||
Task<SendMessageResponse> SendBinaryMessage(SendBinaryMessageRequest request, CancellationToken cancellationToken = default);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|||||||
@@ -1,67 +0,0 @@
|
|||||||
using System.Text.RegularExpressions;
|
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace AMWD.Net.Api.LinkMobility
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Implementation of text messaging (SMS). <see href="https://developer.linkmobility.eu/sms-api/rest-api">API</see>
|
|
||||||
/// </summary>
|
|
||||||
public partial class LinkMobilityClient : ILinkMobilityClient, IDisposable
|
|
||||||
{
|
|
||||||
/// <inheritdoc/>
|
|
||||||
public Task<SendMessageResponse> SendTextMessage(SendTextMessageRequest request, CancellationToken cancellationToken = default)
|
|
||||||
{
|
|
||||||
if (request == null)
|
|
||||||
throw new ArgumentNullException(nameof(request));
|
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(request.MessageContent))
|
|
||||||
throw new ArgumentException("A message must be provided.", nameof(request.MessageContent));
|
|
||||||
|
|
||||||
if (request.RecipientAddressList == null || request.RecipientAddressList.Count == 0)
|
|
||||||
throw new ArgumentException("At least one recipient must be provided.", nameof(request.RecipientAddressList));
|
|
||||||
|
|
||||||
foreach (string recipient in request.RecipientAddressList)
|
|
||||||
{
|
|
||||||
if (!IsValidMSISDN(recipient))
|
|
||||||
throw new ArgumentException($"Recipient address '{recipient}' is not a valid MSISDN format.", nameof(request.RecipientAddressList));
|
|
||||||
}
|
|
||||||
|
|
||||||
return PostAsync<SendMessageResponse, SendTextMessageRequest>("/smsmessaging/text", request, cancellationToken: cancellationToken);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc/>
|
|
||||||
public Task<SendMessageResponse> SendBinaryMessage(SendBinaryMessageRequest request, CancellationToken cancellationToken = default)
|
|
||||||
{
|
|
||||||
if (request == null)
|
|
||||||
throw new ArgumentNullException(nameof(request));
|
|
||||||
|
|
||||||
if (request.MessageContent?.Count > 0)
|
|
||||||
{
|
|
||||||
// Validate that the string is a valid Base64 string
|
|
||||||
// Might throw a ArgumentNullException or FormatException
|
|
||||||
foreach (string str in request.MessageContent)
|
|
||||||
Convert.FromBase64String(str);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (request.RecipientAddressList == null || request.RecipientAddressList.Count == 0)
|
|
||||||
throw new ArgumentException("At least one recipient must be provided.", nameof(request.RecipientAddressList));
|
|
||||||
|
|
||||||
foreach (string recipient in request.RecipientAddressList)
|
|
||||||
{
|
|
||||||
if (!IsValidMSISDN(recipient))
|
|
||||||
throw new ArgumentException($"Recipient address '{recipient}' is not a valid MSISDN format.", nameof(request.RecipientAddressList));
|
|
||||||
}
|
|
||||||
|
|
||||||
return PostAsync<SendMessageResponse, SendBinaryMessageRequest>("/smsmessaging/binary", request, cancellationToken: cancellationToken);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static bool IsValidMSISDN(string msisdn)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrWhiteSpace(msisdn))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return Regex.IsMatch(msisdn, @"^[1-9][0-9]{7,14}$", RegexOptions.Compiled);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -7,13 +7,14 @@ using System.Security.Authentication;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using AMWD.Net.Api.LinkMobility.Utils;
|
||||||
|
|
||||||
namespace AMWD.Net.Api.LinkMobility
|
namespace AMWD.Net.Api.LinkMobility
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Provides a client for interacting with the Link Mobility API.
|
/// Provides a client for interacting with the Link Mobility API.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class LinkMobilityClient : ILinkMobilityClient, IDisposable
|
public class LinkMobilityClient : ILinkMobilityClient, IDisposable
|
||||||
{
|
{
|
||||||
private readonly ClientOptions _clientOptions;
|
private readonly ClientOptions _clientOptions;
|
||||||
private readonly HttpClient _httpClient;
|
private readonly HttpClient _httpClient;
|
||||||
@@ -26,8 +27,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 +38,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 +50,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 +59,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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,6 +79,45 @@ namespace AMWD.Net.Api.LinkMobility
|
|||||||
GC.SuppressFinalize(this);
|
GC.SuppressFinalize(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public async Task<TResponse> PostAsync<TResponse, TRequest>(string requestPath, TRequest? request, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
ThrowIfDisposed();
|
||||||
|
ValidateRequestPath(requestPath);
|
||||||
|
|
||||||
|
string requestUrl = BuildRequestUrl(requestPath);
|
||||||
|
var httpContent = ConvertRequest(request);
|
||||||
|
|
||||||
|
var httpRequest = new HttpRequestMessage
|
||||||
|
{
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
string path = requestPath.Trim().TrimStart('/');
|
||||||
|
var param = new Dictionary<string, string>();
|
||||||
|
|
||||||
|
if (_clientOptions.DefaultQueryParams.Count > 0)
|
||||||
|
{
|
||||||
|
foreach (var kvp in _clientOptions.DefaultQueryParams)
|
||||||
|
param[kvp.Key] = kvp.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (param.Count == 0)
|
||||||
|
return path;
|
||||||
|
|
||||||
|
string queryString = string.Join("&", param.Select(kvp => $"{WebUtility.UrlEncode(kvp.Key)}={WebUtility.UrlEncode(kvp.Value)}"));
|
||||||
|
return $"{path}?{queryString}";
|
||||||
|
}
|
||||||
|
|
||||||
private void ValidateClientOptions()
|
private void ValidateClientOptions()
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(_clientOptions.BaseUrl))
|
if (string.IsNullOrWhiteSpace(_clientOptions.BaseUrl))
|
||||||
@@ -118,61 +163,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)
|
|
||||||
{
|
|
||||||
ThrowIfDisposed();
|
|
||||||
ValidateRequestPath(requestPath);
|
|
||||||
|
|
||||||
string requestUrl = BuildRequestUrl(requestPath, queryParams);
|
|
||||||
var httpContent = ConvertRequest(request);
|
|
||||||
|
|
||||||
var response = await _httpClient.PostAsync(requestUrl, httpContent, cancellationToken).ConfigureAwait(false);
|
|
||||||
return await GetResponse<TResponse>(response, cancellationToken).ConfigureAwait(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
private string BuildRequestUrl(string requestPath, IQueryParameter? queryParams = null)
|
|
||||||
{
|
|
||||||
string path = requestPath.Trim().TrimStart('/');
|
|
||||||
var param = new Dictionary<string, string>();
|
|
||||||
|
|
||||||
if (_clientOptions.DefaultQueryParams.Count > 0)
|
|
||||||
{
|
|
||||||
foreach (var kvp in _clientOptions.DefaultQueryParams)
|
|
||||||
param[kvp.Key] = kvp.Value;
|
|
||||||
}
|
|
||||||
|
|
||||||
var customQueryParams = queryParams?.GetQueryParameters();
|
|
||||||
if (customQueryParams?.Count > 0)
|
|
||||||
{
|
|
||||||
foreach (var kvp in customQueryParams)
|
|
||||||
param[kvp.Key] = kvp.Value;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (param.Count == 0)
|
|
||||||
return path;
|
|
||||||
|
|
||||||
string queryString = string.Join("&", param.Select(kvp => $"{WebUtility.UrlEncode(kvp.Key)}={WebUtility.UrlEncode(kvp.Value)}"));
|
|
||||||
return $"{path}?{queryString}";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static HttpContent? ConvertRequest<T>(T request)
|
private static HttpContent? ConvertRequest<T>(T request)
|
||||||
|
|||||||
@@ -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; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
namespace AMWD.Net.Api.LinkMobility
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Represents options defined via query parameters.
|
|
||||||
/// </summary>
|
|
||||||
public interface IQueryParameter
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Retrieves the query parameters.
|
|
||||||
IReadOnlyDictionary<string, string> GetQueryParameters();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -12,7 +12,7 @@ In this project the REST API of LINK Mobility will be implemented.
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
Published under MIT License (see [**tl;dr**Legal])
|
Published under MIT License (see [choose a license])
|
||||||
|
|
||||||
[LINK Mobility REST API]: https://developer.linkmobility.eu/
|
[LINK Mobility REST API]: https://developer.linkmobility.eu/
|
||||||
[**tl;dr**Legal]: https://www.tldrlegal.com/license/mit-license
|
[choose a license]: https://choosealicense.com/licenses/mit/
|
||||||
|
|||||||
@@ -11,12 +11,6 @@
|
|||||||
[JsonProperty("clientMessageId")]
|
[JsonProperty("clientMessageId")]
|
||||||
public string? ClientMessageId { get; set; }
|
public string? ClientMessageId { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The actual number of generated SMS.
|
|
||||||
/// </summary>
|
|
||||||
[JsonProperty("smsCount")]
|
|
||||||
public int? SmsCount { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Status code.
|
/// Status code.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
14
src/LinkMobility/Responses/SendTextMessageResponse.cs
Normal file
14
src/LinkMobility/Responses/SendTextMessageResponse.cs
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
namespace AMWD.Net.Api.LinkMobility
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Response of a text message sent to a list of recipients.
|
||||||
|
/// </summary>
|
||||||
|
public class SendTextMessageResponse : SendMessageResponse
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The actual number of generated SMS.
|
||||||
|
/// </summary>
|
||||||
|
[JsonProperty("smsCount")]
|
||||||
|
public int? SmsCount { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
using System.Runtime.Serialization;
|
using System.Runtime.Serialization;
|
||||||
using Newtonsoft.Json.Converters;
|
using Newtonsoft.Json.Converters;
|
||||||
|
|
||||||
namespace AMWD.Net.Api.LinkMobility
|
namespace AMWD.Net.Api.LinkMobility.Text
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Specifies the type of sender address.
|
/// Specifies the type of sender address.
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
using System.Runtime.Serialization;
|
using System.Runtime.Serialization;
|
||||||
using Newtonsoft.Json.Converters;
|
using Newtonsoft.Json.Converters;
|
||||||
|
|
||||||
namespace AMWD.Net.Api.LinkMobility
|
namespace AMWD.Net.Api.LinkMobility.Text
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Defines the types of delivery methods on a report.
|
/// Defines the types of delivery methods on a report.
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
using System.Runtime.Serialization;
|
using System.Runtime.Serialization;
|
||||||
using Newtonsoft.Json.Converters;
|
using Newtonsoft.Json.Converters;
|
||||||
|
|
||||||
namespace AMWD.Net.Api.LinkMobility
|
namespace AMWD.Net.Api.LinkMobility.Text
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Specifies the message type.
|
/// Specifies the message type.
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace AMWD.Net.Api.LinkMobility
|
namespace AMWD.Net.Api.LinkMobility.Text
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Request to send a text message to a list of recipients.
|
/// Request to send a text message to a list of recipients.
|
||||||
@@ -8,9 +8,11 @@
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="SendBinaryMessageRequest"/> class.
|
/// Initializes a new instance of the <see cref="SendBinaryMessageRequest"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="recipientAddressList">The recipient list.</param>
|
/// <param name="messageContent">A binary message as base64 encoded lines.</param>
|
||||||
public SendBinaryMessageRequest(IReadOnlyCollection<string> recipientAddressList)
|
/// <param name="recipientAddressList">A list of recipient numbers.</param>
|
||||||
|
public SendBinaryMessageRequest(IReadOnlyCollection<string> messageContent, IReadOnlyCollection<string> recipientAddressList)
|
||||||
{
|
{
|
||||||
|
MessageContent = messageContent;
|
||||||
RecipientAddressList = recipientAddressList;
|
RecipientAddressList = recipientAddressList;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,7 +43,7 @@
|
|||||||
/// The binary data is transmitted without being changed (using 8 bit alphabet).
|
/// The binary data is transmitted without being changed (using 8 bit alphabet).
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
[JsonProperty("messageContent")]
|
[JsonProperty("messageContent")]
|
||||||
public IReadOnlyCollection<string>? MessageContent { get; set; }
|
public IReadOnlyCollection<string> MessageContent { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <em>Optional</em>.
|
/// <em>Optional</em>.
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace AMWD.Net.Api.LinkMobility
|
namespace AMWD.Net.Api.LinkMobility.Text
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Request to send a text message to a list of recipients.
|
/// Request to send a text message to a list of recipients.
|
||||||
@@ -8,8 +8,8 @@
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="SendTextMessageRequest"/> class.
|
/// Initializes a new instance of the <see cref="SendTextMessageRequest"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="messageContent">The message.</param>
|
/// <param name="messageContent">A text message.</param>
|
||||||
/// <param name="recipientAddressList">The recipient list.</param>
|
/// <param name="recipientAddressList">A list of recipient numbers.</param>
|
||||||
public SendTextMessageRequest(string messageContent, IReadOnlyCollection<string> recipientAddressList)
|
public SendTextMessageRequest(string messageContent, IReadOnlyCollection<string> recipientAddressList)
|
||||||
{
|
{
|
||||||
MessageContent = messageContent;
|
MessageContent = messageContent;
|
||||||
78
src/LinkMobility/Text/TextMessageExtensions.cs
Normal file
78
src/LinkMobility/Text/TextMessageExtensions.cs
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using AMWD.Net.Api.LinkMobility.Utils;
|
||||||
|
|
||||||
|
namespace AMWD.Net.Api.LinkMobility.Text
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Implementation of text messaging (SMS). <see href="https://developer.linkmobility.eu/sms-api/rest-api">API</see>
|
||||||
|
/// </summary>
|
||||||
|
public static class TextMessageExtensions
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Sends a text message to a list of recipients.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="client">The <see cref="ILinkMobilityClient"/> instance.</param>
|
||||||
|
/// <param name="request">The request data.</param>
|
||||||
|
/// <param name="cancellationToken">A cancellation token to propagate notification that operations should be canceled.</param>
|
||||||
|
public static Task<SendTextMessageResponse> SendTextMessage(this ILinkMobilityClient client, SendTextMessageRequest request, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
if (request == null)
|
||||||
|
throw new ArgumentNullException(nameof(request));
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(request.MessageContent))
|
||||||
|
throw new ArgumentException("A message must be provided.", nameof(request.MessageContent));
|
||||||
|
|
||||||
|
ValidateRecipientList(request.RecipientAddressList);
|
||||||
|
ValidateContentCategory(request.ContentCategory);
|
||||||
|
|
||||||
|
return client.PostAsync<SendTextMessageResponse, SendTextMessageRequest>("/smsmessaging/text", request, cancellationToken: cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sends a binary message to a list of recipients.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="client">The <see cref="ILinkMobilityClient"/> instance.</param>
|
||||||
|
/// <param name="request">The request data.</param>
|
||||||
|
/// <param name="cancellationToken">A cancellation token to propagate notification that operations should be canceled.</param>
|
||||||
|
public static Task<SendTextMessageResponse> SendBinaryMessage(this ILinkMobilityClient client, SendBinaryMessageRequest request, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
if (request == null)
|
||||||
|
throw new ArgumentNullException(nameof(request));
|
||||||
|
|
||||||
|
if (request.MessageContent == null || request.MessageContent.Count == 0)
|
||||||
|
throw new ArgumentException("A message must be provided.", nameof(request.MessageContent));
|
||||||
|
|
||||||
|
// Easiest way to validate that the string is a valid Base64 string.
|
||||||
|
// Might throw a ArgumentNullException or FormatException.
|
||||||
|
foreach (string str in request.MessageContent)
|
||||||
|
Convert.FromBase64String(str);
|
||||||
|
|
||||||
|
ValidateRecipientList(request.RecipientAddressList);
|
||||||
|
ValidateContentCategory(request.ContentCategory);
|
||||||
|
|
||||||
|
return client.PostAsync<SendTextMessageResponse, SendBinaryMessageRequest>("/smsmessaging/binary", request, cancellationToken: cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void ValidateRecipientList(IReadOnlyCollection<string>? recipientAddressList)
|
||||||
|
{
|
||||||
|
if (recipientAddressList == null || recipientAddressList.Count == 0)
|
||||||
|
throw new ArgumentException("At least one recipient must be provided.", nameof(recipientAddressList));
|
||||||
|
|
||||||
|
foreach (string recipient in recipientAddressList)
|
||||||
|
{
|
||||||
|
if (!Validation.IsValidMSISDN(recipient))
|
||||||
|
throw new ArgumentException($"Recipient address '{recipient}' is not a valid MSISDN format.", nameof(recipientAddressList));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void ValidateContentCategory(ContentCategory? contentCategory)
|
||||||
|
{
|
||||||
|
if (!contentCategory.HasValue)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (contentCategory.Value != ContentCategory.Informational && contentCategory.Value != ContentCategory.Advertisement)
|
||||||
|
throw new ArgumentException($"Content category '{contentCategory.Value}' is not valid.", nameof(contentCategory));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
|
|
||||||
namespace AMWD.Net.Api.LinkMobility
|
namespace AMWD.Net.Api.LinkMobility.Utils
|
||||||
{
|
{
|
||||||
internal static class SerializerExtensions
|
internal static class SerializerExtensions
|
||||||
{
|
{
|
||||||
|
|||||||
25
src/LinkMobility/Utils/Validation.cs
Normal file
25
src/LinkMobility/Utils/Validation.cs
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
|
namespace AMWD.Net.Api.LinkMobility.Utils
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Validation helper for LINK Mobility API requirements.
|
||||||
|
/// </summary>
|
||||||
|
public static class Validation
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Validates whether the provided string is a valid MSISDN (E.164 formatted).
|
||||||
|
/// <br/>
|
||||||
|
/// See <see href="https://en.wikipedia.org/wiki/MSISDN">Wikipedia: MSISDN</see> for more information.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="msisdn">The string to validate.</param>
|
||||||
|
/// <returns><see langword="true"/> for a valid MSISDN number, <see langword="false"/> otherwise.</returns>
|
||||||
|
public static bool IsValidMSISDN(string msisdn)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(msisdn))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return Regex.IsMatch(msisdn, @"^[1-9][0-9]{7,14}$", RegexOptions.Compiled);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,9 +1,15 @@
|
|||||||
namespace AMWD.Net.Api.LinkMobility
|
using AMWD.Net.Api.LinkMobility.Utils;
|
||||||
|
|
||||||
|
namespace AMWD.Net.Api.LinkMobility.Webhook
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Representes the response to an incoming message notification. (<see href="https://developer.linkmobility.eu/sms-api/receive-incoming-messages">API</see>)
|
/// Representes the response to an incoming message notification.
|
||||||
|
/// (See <see href="https://developer.linkmobility.eu/sms-api/receive-incoming-messages">API</see>)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class IncomingMessageNotificationResponse
|
/// <remarks>
|
||||||
|
/// This notification acknowlegement is the same for all webhooks of LINK Mobility.
|
||||||
|
/// </remarks>
|
||||||
|
public class NotificationResponse
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the status code of the response.
|
/// Gets or sets the status code of the response.
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
using System.Runtime.Serialization;
|
using System.Runtime.Serialization;
|
||||||
using Newtonsoft.Json.Converters;
|
using Newtonsoft.Json.Converters;
|
||||||
|
|
||||||
namespace AMWD.Net.Api.LinkMobility
|
namespace AMWD.Net.Api.LinkMobility.Webhook.Text
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Defines the delivery status of a message on a report.
|
/// Defines the delivery status of a message on a report.
|
||||||
30
src/LinkMobility/Webhook/Text/TextMessageType.cs
Normal file
30
src/LinkMobility/Webhook/Text/TextMessageType.cs
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
using System.Runtime.Serialization;
|
||||||
|
using Newtonsoft.Json.Converters;
|
||||||
|
|
||||||
|
namespace AMWD.Net.Api.LinkMobility.Webhook.Text
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Defines the type of notification.
|
||||||
|
/// </summary>
|
||||||
|
[JsonConverter(typeof(StringEnumConverter))]
|
||||||
|
public enum TextMessageType
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Notification of an incoming text message.
|
||||||
|
/// </summary>
|
||||||
|
[EnumMember(Value = "text")]
|
||||||
|
Text = 1,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Notification of an incoming binary message.
|
||||||
|
/// </summary>
|
||||||
|
[EnumMember(Value = "binary")]
|
||||||
|
Binary = 2,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Notification of a delivery report.
|
||||||
|
/// </summary>
|
||||||
|
[EnumMember(Value = "deliveryReport")]
|
||||||
|
DeliveryReport = 3
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,19 +1,20 @@
|
|||||||
using System.Runtime.Serialization;
|
using AMWD.Net.Api.LinkMobility.Text;
|
||||||
using Newtonsoft.Json.Converters;
|
using AMWD.Net.Api.LinkMobility.Utils;
|
||||||
|
|
||||||
namespace AMWD.Net.Api.LinkMobility
|
namespace AMWD.Net.Api.LinkMobility.Webhook.Text
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents a notification for an incoming message or delivery report. (<see href="https://developer.linkmobility.eu/sms-api/receive-incoming-messages">API</see>)
|
/// Represents a notification for an incoming text message or delivery report.
|
||||||
|
/// (<see href="https://developer.linkmobility.eu/sms-api/receive-incoming-messages">API</see>)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class IncomingMessageNotification
|
public class TextNotification
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="IncomingMessageNotification"/> class.
|
/// Initializes a new instance of the <see cref="TextNotification"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="notificationId">The notification id.</param>
|
/// <param name="notificationId">The notification id.</param>
|
||||||
/// <param name="transferId">The transfer id.</param>
|
/// <param name="transferId">The transfer id.</param>
|
||||||
public IncomingMessageNotification(string notificationId, string transferId)
|
public TextNotification(string notificationId, string transferId)
|
||||||
{
|
{
|
||||||
NotificationId = notificationId;
|
NotificationId = notificationId;
|
||||||
TransferId = transferId;
|
TransferId = transferId;
|
||||||
@@ -23,7 +24,7 @@ namespace AMWD.Net.Api.LinkMobility
|
|||||||
/// Defines the content type of your notification.
|
/// Defines the content type of your notification.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty("messageType")]
|
[JsonProperty("messageType")]
|
||||||
public Type MessageType { get; set; }
|
public TextMessageType MessageType { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 20 digit long identification of your notification.
|
/// 20 digit long identification of your notification.
|
||||||
@@ -32,7 +33,7 @@ namespace AMWD.Net.Api.LinkMobility
|
|||||||
public string NotificationId { get; set; }
|
public string NotificationId { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <see cref="Type.DeliveryReport"/>:
|
/// <see cref="Text.TextMessageType.DeliveryReport"/>:
|
||||||
/// <br/>
|
/// <br/>
|
||||||
/// Unique transfer-id to connect the deliveryReport to the initial message.
|
/// Unique transfer-id to connect the deliveryReport to the initial message.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -40,7 +41,7 @@ namespace AMWD.Net.Api.LinkMobility
|
|||||||
public string TransferId { get; set; }
|
public string TransferId { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <see cref="Type.Text"/>, <see cref="Type.Binary"/>:
|
/// <see cref="Text.TextMessageType.Text"/>, <see cref="Text.TextMessageType.Binary"/>:
|
||||||
/// <br/>
|
/// <br/>
|
||||||
/// Indicates whether you received message is a SMS or a flash-SMS.
|
/// Indicates whether you received message is a SMS or a flash-SMS.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -54,9 +55,9 @@ namespace AMWD.Net.Api.LinkMobility
|
|||||||
public string? SenderAddress { get; set; }
|
public string? SenderAddress { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <see cref="Type.Text"/>, <see cref="Type.Binary"/>:
|
/// <see cref="Text.TextMessageType.Text"/>, <see cref="Text.TextMessageType.Binary"/>:
|
||||||
/// <br/>
|
/// <br/>
|
||||||
/// <see cref="AddressType.International"/> – defines the number format of the mobile originated <see cref="SenderAddress"/>.
|
/// <see cref="AddressType.International"/> - defines the number format of the mobile originated <see cref="SenderAddress"/>.
|
||||||
/// International numbers always includes the country prefix.
|
/// International numbers always includes the country prefix.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty("senderAddressType")]
|
[JsonProperty("senderAddressType")]
|
||||||
@@ -72,7 +73,7 @@ namespace AMWD.Net.Api.LinkMobility
|
|||||||
public string? RecipientAddress { get; set; }
|
public string? RecipientAddress { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <see cref="Type.Text"/>, <see cref="Type.Binary"/>:
|
/// <see cref="Text.TextMessageType.Text"/>, <see cref="Text.TextMessageType.Binary"/>:
|
||||||
/// <br/>
|
/// <br/>
|
||||||
/// Defines the number format of the mobile originated message.
|
/// Defines the number format of the mobile originated message.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -80,7 +81,7 @@ namespace AMWD.Net.Api.LinkMobility
|
|||||||
public AddressType? RecipientAddressType { get; set; }
|
public AddressType? RecipientAddressType { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <see cref="Type.Text"/>:
|
/// <see cref="Text.TextMessageType.Text"/>:
|
||||||
/// <br/>
|
/// <br/>
|
||||||
/// Text body of the message encoded in <c>UTF-8</c>.
|
/// Text body of the message encoded in <c>UTF-8</c>.
|
||||||
/// In the case of concatenated SMS it will contain the complete content of all segments.
|
/// In the case of concatenated SMS it will contain the complete content of all segments.
|
||||||
@@ -89,7 +90,7 @@ namespace AMWD.Net.Api.LinkMobility
|
|||||||
public string? TextMessageContent { get; set; }
|
public string? TextMessageContent { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <see cref="Type.Binary"/>:
|
/// <see cref="Text.TextMessageType.Binary"/>:
|
||||||
/// <br/>
|
/// <br/>
|
||||||
/// Indicates whether a user-data-header is included within a <c>Base64</c> encoded byte segment.
|
/// Indicates whether a user-data-header is included within a <c>Base64</c> encoded byte segment.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -97,7 +98,7 @@ namespace AMWD.Net.Api.LinkMobility
|
|||||||
public bool? UserDataHeaderPresent { get; set; }
|
public bool? UserDataHeaderPresent { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <see cref="Type.Binary"/>:
|
/// <see cref="Text.TextMessageType.Binary"/>:
|
||||||
/// <br/>
|
/// <br/>
|
||||||
/// Content of a binary SMS in an array of <c>Base64</c> strings (URL safe).
|
/// Content of a binary SMS in an array of <c>Base64</c> strings (URL safe).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -105,7 +106,7 @@ namespace AMWD.Net.Api.LinkMobility
|
|||||||
public IReadOnlyCollection<string>? BinaryMessageContent { get; set; }
|
public IReadOnlyCollection<string>? BinaryMessageContent { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <see cref="Type.DeliveryReport"/>:
|
/// <see cref="Text.TextMessageType.DeliveryReport"/>:
|
||||||
/// <br/>
|
/// <br/>
|
||||||
/// Status of the message.
|
/// Status of the message.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -113,7 +114,7 @@ namespace AMWD.Net.Api.LinkMobility
|
|||||||
public DeliveryStatus? DeliveryReportMessageStatus { get; set; }
|
public DeliveryStatus? DeliveryReportMessageStatus { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <see cref="Type.DeliveryReport"/>:
|
/// <see cref="Text.TextMessageType.DeliveryReport"/>:
|
||||||
/// <br/>
|
/// <br/>
|
||||||
/// ISO 8601 timestamp. Point of time sending the message to recipients address.
|
/// ISO 8601 timestamp. Point of time sending the message to recipients address.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -121,7 +122,7 @@ namespace AMWD.Net.Api.LinkMobility
|
|||||||
public DateTime? SentOn { get; set; }
|
public DateTime? SentOn { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <see cref="Type.DeliveryReport"/>:
|
/// <see cref="Text.TextMessageType.DeliveryReport"/>:
|
||||||
/// <br/>
|
/// <br/>
|
||||||
/// ISO 8601 timestamp. Point of time of submitting the message to the mobile operators network.
|
/// ISO 8601 timestamp. Point of time of submitting the message to the mobile operators network.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -129,7 +130,7 @@ namespace AMWD.Net.Api.LinkMobility
|
|||||||
public DateTime? DeliveredOn { get; set; }
|
public DateTime? DeliveredOn { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <see cref="Type.DeliveryReport"/>:
|
/// <see cref="Text.TextMessageType.DeliveryReport"/>:
|
||||||
/// <br/>
|
/// <br/>
|
||||||
/// Type of delivery used to send the message.
|
/// Type of delivery used to send the message.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -137,7 +138,7 @@ namespace AMWD.Net.Api.LinkMobility
|
|||||||
public DeliveryType? DeliveredAs { get; set; }
|
public DeliveryType? DeliveredAs { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <see cref="Type.DeliveryReport"/>:
|
/// <see cref="Text.TextMessageType.DeliveryReport"/>:
|
||||||
/// <br/>
|
/// <br/>
|
||||||
/// In the case of a delivery report, the <see cref="ClientMessageId"/> contains the optional submitted message id.
|
/// In the case of a delivery report, the <see cref="ClientMessageId"/> contains the optional submitted message id.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -145,43 +146,18 @@ namespace AMWD.Net.Api.LinkMobility
|
|||||||
public string? ClientMessageId { get; set; }
|
public string? ClientMessageId { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Defines the type of notification.
|
/// Tries to parse the given content as <see cref="TextNotification"/>.
|
||||||
/// </summary>
|
|
||||||
[JsonConverter(typeof(StringEnumConverter))]
|
|
||||||
public enum Type
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Notification of an incoming text message.
|
|
||||||
/// </summary>
|
|
||||||
[EnumMember(Value = "text")]
|
|
||||||
Text = 1,
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Notification of an incoming binary message.
|
|
||||||
/// </summary>
|
|
||||||
[EnumMember(Value = "binary")]
|
|
||||||
Binary = 2,
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Notification of a delivery report.
|
|
||||||
/// </summary>
|
|
||||||
[EnumMember(Value = "deliveryReport")]
|
|
||||||
DeliveryReport = 3
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Tries to parse the given content as <see cref="IncomingMessageNotification"/>.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="json">The given content (should be the notification json).</param>
|
/// <param name="json">The given content (should be the notification json).</param>
|
||||||
/// <param name="notification">The deserialized notification.</param>
|
/// <param name="notification">The deserialized notification.</param>
|
||||||
/// <returns>
|
/// <returns>
|
||||||
/// <see langword="true"/> if the content could be parsed; otherwise, <see langword="false"/>.
|
/// <see langword="true"/> if the content could be parsed; otherwise, <see langword="false"/>.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public static bool TryParse(string json, out IncomingMessageNotification? notification)
|
public static bool TryParse(string json, out TextNotification? notification)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
notification = json.DeserializeObject<IncomingMessageNotification>();
|
notification = json.DeserializeObject<TextNotification>();
|
||||||
return notification != null;
|
return notification != null;
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
@@ -39,6 +39,8 @@ namespace LinkMobility.Tests.Helpers
|
|||||||
public Queue<HttpResponseMessage> Responses { get; } = new();
|
public Queue<HttpResponseMessage> Responses { get; } = new();
|
||||||
|
|
||||||
public Mock<HttpClientHandler> Mock { get; }
|
public Mock<HttpClientHandler> Mock { get; }
|
||||||
|
|
||||||
|
public IProtectedMock<HttpClientHandler> Protected => Mock.Protected();
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class HttpRequestMessageCallback
|
internal class HttpRequestMessageCallback
|
||||||
|
|||||||
@@ -145,7 +145,7 @@ namespace LinkMobility.Tests
|
|||||||
var client = GetClient();
|
var client = GetClient();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var response = await ReflectionHelper.InvokePrivateMethodAsync<TestClass>(client, "PostAsync", "test", _request, null, TestContext.CancellationToken);
|
var response = await client.PostAsync<TestClass, TestClass>("test", _request, TestContext.CancellationToken);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.IsNotNull(response);
|
Assert.IsNotNull(response);
|
||||||
@@ -166,57 +166,12 @@ namespace LinkMobility.Tests
|
|||||||
Assert.AreEqual("Scheme Parameter", callback.Headers["Authorization"]);
|
Assert.AreEqual("Scheme Parameter", callback.Headers["Authorization"]);
|
||||||
Assert.AreEqual("LinkMobilityClient/1.0.0", callback.Headers["User-Agent"]);
|
Assert.AreEqual("LinkMobilityClient/1.0.0", callback.Headers["User-Agent"]);
|
||||||
|
|
||||||
_httpMessageHandlerMock.Mock
|
_httpMessageHandlerMock.Protected.Verify("SendAsync", Times.Once(), ItExpr.IsAny<HttpRequestMessage>(), ItExpr.IsAny<CancellationToken>());
|
||||||
.Protected()
|
|
||||||
.Verify("SendAsync", Times.Once(), ItExpr.IsAny<HttpRequestMessage>(), ItExpr.IsAny<CancellationToken>());
|
|
||||||
|
|
||||||
_clientOptionsMock.VerifyGet(o => o.DefaultQueryParams, Times.Exactly(2));
|
_clientOptionsMock.VerifyGet(o => o.DefaultQueryParams, Times.Exactly(2));
|
||||||
VerifyNoOtherCalls();
|
VerifyNoOtherCalls();
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
|
||||||
public async Task ShouldAddCustomQueryParameters()
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
var queryParams = new TestParams();
|
|
||||||
_httpMessageHandlerMock.Responses.Enqueue(new HttpResponseMessage
|
|
||||||
{
|
|
||||||
StatusCode = HttpStatusCode.OK,
|
|
||||||
Content = new StringContent(@"{ ""string"": ""some-string"", ""integer"": 123 }", Encoding.UTF8, "application/json"),
|
|
||||||
});
|
|
||||||
|
|
||||||
var client = GetClient();
|
|
||||||
|
|
||||||
// Act
|
|
||||||
var response = await ReflectionHelper.InvokePrivateMethodAsync<TestClass>(client, "PostAsync", "params/path", _request, queryParams, TestContext.CancellationToken);
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Assert.IsNotNull(response);
|
|
||||||
|
|
||||||
Assert.HasCount(1, _httpMessageHandlerMock.RequestCallbacks);
|
|
||||||
|
|
||||||
var callback = _httpMessageHandlerMock.RequestCallbacks.First();
|
|
||||||
Assert.AreEqual(HttpMethod.Post, callback.HttpMethod);
|
|
||||||
Assert.AreEqual("https://localhost/rest/params/path?test=query+text", callback.Url);
|
|
||||||
Assert.AreEqual(@"{""string"":""Happy Testing"",""integer"":54321}", callback.Content);
|
|
||||||
|
|
||||||
Assert.HasCount(3, callback.Headers);
|
|
||||||
Assert.IsTrue(callback.Headers.ContainsKey("Accept"));
|
|
||||||
Assert.IsTrue(callback.Headers.ContainsKey("Authorization"));
|
|
||||||
Assert.IsTrue(callback.Headers.ContainsKey("User-Agent"));
|
|
||||||
|
|
||||||
Assert.AreEqual("application/json", callback.Headers["Accept"]);
|
|
||||||
Assert.AreEqual("Scheme Parameter", callback.Headers["Authorization"]);
|
|
||||||
Assert.AreEqual("LinkMobilityClient/1.0.0", callback.Headers["User-Agent"]);
|
|
||||||
|
|
||||||
_httpMessageHandlerMock.Mock
|
|
||||||
.Protected()
|
|
||||||
.Verify("SendAsync", Times.Once(), ItExpr.IsAny<HttpRequestMessage>(), ItExpr.IsAny<CancellationToken>());
|
|
||||||
|
|
||||||
_clientOptionsMock.VerifyGet(o => o.DefaultQueryParams, Times.Once);
|
|
||||||
VerifyNoOtherCalls();
|
|
||||||
}
|
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void ShouldDisposeHttpClient()
|
public void ShouldDisposeHttpClient()
|
||||||
{
|
{
|
||||||
@@ -227,9 +182,7 @@ namespace LinkMobility.Tests
|
|||||||
client.Dispose();
|
client.Dispose();
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
_httpMessageHandlerMock.Mock
|
_httpMessageHandlerMock.Protected.Verify("Dispose", Times.Once(), exactParameterMatch: true, true);
|
||||||
.Protected()
|
|
||||||
.Verify("Dispose", Times.Once(), exactParameterMatch: true, true);
|
|
||||||
|
|
||||||
VerifyNoOtherCalls();
|
VerifyNoOtherCalls();
|
||||||
}
|
}
|
||||||
@@ -245,9 +198,7 @@ namespace LinkMobility.Tests
|
|||||||
client.Dispose();
|
client.Dispose();
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
_httpMessageHandlerMock.Mock
|
_httpMessageHandlerMock.Protected.Verify("Dispose", Times.Once(), exactParameterMatch: true, true);
|
||||||
.Protected()
|
|
||||||
.Verify("Dispose", Times.Once(), exactParameterMatch: true, true);
|
|
||||||
|
|
||||||
VerifyNoOtherCalls();
|
VerifyNoOtherCalls();
|
||||||
}
|
}
|
||||||
@@ -256,7 +207,7 @@ namespace LinkMobility.Tests
|
|||||||
public void ShouldAssertClientOptions()
|
public void ShouldAssertClientOptions()
|
||||||
{
|
{
|
||||||
// Arrange + Act
|
// Arrange + Act
|
||||||
var client = GetClient();
|
_ = GetClient();
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
VerifyNoOtherCalls();
|
VerifyNoOtherCalls();
|
||||||
@@ -320,7 +271,7 @@ namespace LinkMobility.Tests
|
|||||||
// Act & Assert
|
// Act & Assert
|
||||||
await Assert.ThrowsExactlyAsync<ObjectDisposedException>(async () =>
|
await Assert.ThrowsExactlyAsync<ObjectDisposedException>(async () =>
|
||||||
{
|
{
|
||||||
await ReflectionHelper.InvokePrivateMethodAsync<object>(client, "PostAsync", "/request/path", _request, null, TestContext.CancellationToken);
|
await client.PostAsync<object, TestClass>("/request/path", _request, TestContext.CancellationToken);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -336,7 +287,7 @@ namespace LinkMobility.Tests
|
|||||||
// Act & Assert
|
// Act & Assert
|
||||||
await Assert.ThrowsExactlyAsync<ArgumentNullException>(async () =>
|
await Assert.ThrowsExactlyAsync<ArgumentNullException>(async () =>
|
||||||
{
|
{
|
||||||
await ReflectionHelper.InvokePrivateMethodAsync<object>(client, "PostAsync", path, _request, null, TestContext.CancellationToken);
|
await client.PostAsync<object, TestClass>(path, _request, TestContext.CancellationToken);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -349,7 +300,7 @@ namespace LinkMobility.Tests
|
|||||||
// Act & Assert
|
// Act & Assert
|
||||||
await Assert.ThrowsExactlyAsync<ArgumentException>(async () =>
|
await Assert.ThrowsExactlyAsync<ArgumentException>(async () =>
|
||||||
{
|
{
|
||||||
await ReflectionHelper.InvokePrivateMethodAsync<object>(client, "PostAsync", "foo?bar=baz", _request, null, TestContext.CancellationToken);
|
await client.PostAsync<object, TestClass>("foo?bar=baz", _request, TestContext.CancellationToken);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -366,7 +317,7 @@ namespace LinkMobility.Tests
|
|||||||
var client = GetClient();
|
var client = GetClient();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var response = await ReflectionHelper.InvokePrivateMethodAsync<TestClass>(client, "PostAsync", "/request/path", _request, null, TestContext.CancellationToken);
|
var response = await client.PostAsync<TestClass, TestClass>("/request/path", _request, TestContext.CancellationToken);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.IsNotNull(response);
|
Assert.IsNotNull(response);
|
||||||
@@ -389,9 +340,7 @@ namespace LinkMobility.Tests
|
|||||||
Assert.AreEqual("Scheme Parameter", callback.Headers["Authorization"]);
|
Assert.AreEqual("Scheme Parameter", callback.Headers["Authorization"]);
|
||||||
Assert.AreEqual("LinkMobilityClient/1.0.0", callback.Headers["User-Agent"]);
|
Assert.AreEqual("LinkMobilityClient/1.0.0", callback.Headers["User-Agent"]);
|
||||||
|
|
||||||
_httpMessageHandlerMock.Mock
|
_httpMessageHandlerMock.Protected.Verify("SendAsync", Times.Once(), ItExpr.IsAny<HttpRequestMessage>(), ItExpr.IsAny<CancellationToken>());
|
||||||
.Protected()
|
|
||||||
.Verify("SendAsync", Times.Once(), ItExpr.IsAny<HttpRequestMessage>(), ItExpr.IsAny<CancellationToken>());
|
|
||||||
|
|
||||||
_clientOptionsMock.VerifyGet(o => o.DefaultQueryParams, Times.Once);
|
_clientOptionsMock.VerifyGet(o => o.DefaultQueryParams, Times.Once);
|
||||||
VerifyNoOtherCalls();
|
VerifyNoOtherCalls();
|
||||||
@@ -411,7 +360,7 @@ namespace LinkMobility.Tests
|
|||||||
var client = GetClient();
|
var client = GetClient();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var response = await ReflectionHelper.InvokePrivateMethodAsync<TestClass>(client, "PostAsync", "/request/path", stringContent, null, TestContext.CancellationToken);
|
var response = await client.PostAsync<TestClass, HttpContent>("/request/path", stringContent, TestContext.CancellationToken);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.IsNotNull(response);
|
Assert.IsNotNull(response);
|
||||||
@@ -434,9 +383,7 @@ namespace LinkMobility.Tests
|
|||||||
Assert.AreEqual("Scheme Parameter", callback.Headers["Authorization"]);
|
Assert.AreEqual("Scheme Parameter", callback.Headers["Authorization"]);
|
||||||
Assert.AreEqual("LinkMobilityClient/1.0.0", callback.Headers["User-Agent"]);
|
Assert.AreEqual("LinkMobilityClient/1.0.0", callback.Headers["User-Agent"]);
|
||||||
|
|
||||||
_httpMessageHandlerMock.Mock
|
_httpMessageHandlerMock.Protected.Verify("SendAsync", Times.Once(), ItExpr.IsAny<HttpRequestMessage>(), ItExpr.IsAny<CancellationToken>());
|
||||||
.Protected()
|
|
||||||
.Verify("SendAsync", Times.Once(), ItExpr.IsAny<HttpRequestMessage>(), ItExpr.IsAny<CancellationToken>());
|
|
||||||
|
|
||||||
_clientOptionsMock.VerifyGet(o => o.DefaultQueryParams, Times.Once);
|
_clientOptionsMock.VerifyGet(o => o.DefaultQueryParams, Times.Once);
|
||||||
VerifyNoOtherCalls();
|
VerifyNoOtherCalls();
|
||||||
@@ -455,7 +402,7 @@ namespace LinkMobility.Tests
|
|||||||
var client = GetClient();
|
var client = GetClient();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var response = await ReflectionHelper.InvokePrivateMethodAsync<TestClass>(client, "PostAsync", "posting", null, null, TestContext.CancellationToken);
|
var response = await client.PostAsync<TestClass, object>("posting", null, TestContext.CancellationToken);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.IsNotNull(response);
|
Assert.IsNotNull(response);
|
||||||
@@ -479,9 +426,7 @@ namespace LinkMobility.Tests
|
|||||||
Assert.AreEqual("Scheme Parameter", callback.Headers["Authorization"]);
|
Assert.AreEqual("Scheme Parameter", callback.Headers["Authorization"]);
|
||||||
Assert.AreEqual("LinkMobilityClient/1.0.0", callback.Headers["User-Agent"]);
|
Assert.AreEqual("LinkMobilityClient/1.0.0", callback.Headers["User-Agent"]);
|
||||||
|
|
||||||
_httpMessageHandlerMock.Mock
|
_httpMessageHandlerMock.Protected.Verify("SendAsync", Times.Once(), ItExpr.IsAny<HttpRequestMessage>(), ItExpr.IsAny<CancellationToken>());
|
||||||
.Protected()
|
|
||||||
.Verify("SendAsync", Times.Once(), ItExpr.IsAny<HttpRequestMessage>(), ItExpr.IsAny<CancellationToken>());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
@@ -501,7 +446,7 @@ namespace LinkMobility.Tests
|
|||||||
// Act & Assert
|
// Act & Assert
|
||||||
var ex = await Assert.ThrowsExactlyAsync<AuthenticationException>(async () =>
|
var ex = await Assert.ThrowsExactlyAsync<AuthenticationException>(async () =>
|
||||||
{
|
{
|
||||||
await ReflectionHelper.InvokePrivateMethodAsync<object>(client, "PostAsync", "foo", _request, null, TestContext.CancellationToken);
|
await client.PostAsync<object, TestClass>("foo", _request, TestContext.CancellationToken);
|
||||||
});
|
});
|
||||||
Assert.IsNull(ex.InnerException);
|
Assert.IsNull(ex.InnerException);
|
||||||
Assert.AreEqual($"HTTP auth missing: {statusCode}", ex.Message);
|
Assert.AreEqual($"HTTP auth missing: {statusCode}", ex.Message);
|
||||||
@@ -524,7 +469,7 @@ namespace LinkMobility.Tests
|
|||||||
// Act & Assert
|
// Act & Assert
|
||||||
var ex = await Assert.ThrowsExactlyAsync<ApplicationException>(async () =>
|
var ex = await Assert.ThrowsExactlyAsync<ApplicationException>(async () =>
|
||||||
{
|
{
|
||||||
await ReflectionHelper.InvokePrivateMethodAsync<object>(client, "PostAsync", "foo", _request, null, TestContext.CancellationToken);
|
await client.PostAsync<object, TestClass>("foo", _request, TestContext.CancellationToken);
|
||||||
});
|
});
|
||||||
Assert.IsNull(ex.InnerException);
|
Assert.IsNull(ex.InnerException);
|
||||||
Assert.AreEqual($"Unknown HTTP response: {statusCode}", ex.Message);
|
Assert.AreEqual($"Unknown HTTP response: {statusCode}", ex.Message);
|
||||||
@@ -545,7 +490,7 @@ namespace LinkMobility.Tests
|
|||||||
// Act & Assert
|
// Act & Assert
|
||||||
await Assert.ThrowsExactlyAsync<JsonReaderException>(async () =>
|
await Assert.ThrowsExactlyAsync<JsonReaderException>(async () =>
|
||||||
{
|
{
|
||||||
await ReflectionHelper.InvokePrivateMethodAsync<TestClass>(client, "PostAsync", "some-path", _request, null, TestContext.CancellationToken);
|
await client.PostAsync<TestClass, TestClass>("some-path", _request, TestContext.CancellationToken);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -563,7 +508,7 @@ namespace LinkMobility.Tests
|
|||||||
var client = GetClient();
|
var client = GetClient();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
string response = await ReflectionHelper.InvokePrivateMethodAsync<string>(client, "PostAsync", "path", _request, null, TestContext.CancellationToken);
|
string response = await client.PostAsync<string, TestClass>("path", _request, TestContext.CancellationToken);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.IsNotNull(response);
|
Assert.IsNotNull(response);
|
||||||
@@ -586,9 +531,7 @@ namespace LinkMobility.Tests
|
|||||||
Assert.AreEqual("Scheme Parameter", callback.Headers["Authorization"]);
|
Assert.AreEqual("Scheme Parameter", callback.Headers["Authorization"]);
|
||||||
Assert.AreEqual("LinkMobilityClient/1.0.0", callback.Headers["User-Agent"]);
|
Assert.AreEqual("LinkMobilityClient/1.0.0", callback.Headers["User-Agent"]);
|
||||||
|
|
||||||
_httpMessageHandlerMock.Mock
|
_httpMessageHandlerMock.Protected.Verify("SendAsync", Times.Once(), ItExpr.IsAny<HttpRequestMessage>(), ItExpr.IsAny<CancellationToken>());
|
||||||
.Protected()
|
|
||||||
.Verify("SendAsync", Times.Once(), ItExpr.IsAny<HttpRequestMessage>(), ItExpr.IsAny<CancellationToken>());
|
|
||||||
|
|
||||||
_clientOptionsMock.VerifyGet(o => o.DefaultQueryParams, Times.Once);
|
_clientOptionsMock.VerifyGet(o => o.DefaultQueryParams, Times.Once);
|
||||||
VerifyNoOtherCalls();
|
VerifyNoOtherCalls();
|
||||||
@@ -638,16 +581,5 @@ namespace LinkMobility.Tests
|
|||||||
[JsonProperty("integer")]
|
[JsonProperty("integer")]
|
||||||
public int Int { get; set; }
|
public int Int { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
private class TestParams : IQueryParameter
|
|
||||||
{
|
|
||||||
public IReadOnlyDictionary<string, string> GetQueryParameters()
|
|
||||||
{
|
|
||||||
return new Dictionary<string, string>
|
|
||||||
{
|
|
||||||
{ "test", "query text" }
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,10 +6,11 @@ using System.Text;
|
|||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using AMWD.Net.Api.LinkMobility;
|
using AMWD.Net.Api.LinkMobility;
|
||||||
|
using AMWD.Net.Api.LinkMobility.Text;
|
||||||
using LinkMobility.Tests.Helpers;
|
using LinkMobility.Tests.Helpers;
|
||||||
using Moq.Protected;
|
using Moq.Protected;
|
||||||
|
|
||||||
namespace LinkMobility.Tests.Sms
|
namespace LinkMobility.Tests.Text
|
||||||
{
|
{
|
||||||
[TestClass]
|
[TestClass]
|
||||||
public class SendBinaryMessageTest
|
public class SendBinaryMessageTest
|
||||||
@@ -42,10 +43,7 @@ namespace LinkMobility.Tests.Sms
|
|||||||
_clientOptionsMock.Setup(c => c.AllowRedirects).Returns(true);
|
_clientOptionsMock.Setup(c => c.AllowRedirects).Returns(true);
|
||||||
_clientOptionsMock.Setup(c => c.UseProxy).Returns(false);
|
_clientOptionsMock.Setup(c => c.UseProxy).Returns(false);
|
||||||
|
|
||||||
_request = new SendBinaryMessageRequest(["436991234567"])
|
_request = new SendBinaryMessageRequest(["SGVsbG8gV29ybGQ="], ["436991234567"]); // "Hello World" in Base64
|
||||||
{
|
|
||||||
MessageContent = ["SGVsbG8gV29ybGQ="] // "Hello World" base64
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
@@ -87,14 +85,27 @@ namespace LinkMobility.Tests.Sms
|
|||||||
Assert.AreEqual("Scheme Parameter", callback.Headers["Authorization"]);
|
Assert.AreEqual("Scheme Parameter", callback.Headers["Authorization"]);
|
||||||
Assert.AreEqual("LinkMobilityClient/1.0.0", callback.Headers["User-Agent"]);
|
Assert.AreEqual("LinkMobilityClient/1.0.0", callback.Headers["User-Agent"]);
|
||||||
|
|
||||||
_httpMessageHandlerMock.Mock
|
_httpMessageHandlerMock.Protected.Verify("SendAsync", Times.Once(), ItExpr.IsAny<HttpRequestMessage>(), ItExpr.IsAny<CancellationToken>());
|
||||||
.Protected()
|
|
||||||
.Verify("SendAsync", Times.Once(), ItExpr.IsAny<HttpRequestMessage>(), ItExpr.IsAny<CancellationToken>());
|
|
||||||
|
|
||||||
_clientOptionsMock.VerifyGet(o => o.DefaultQueryParams, Times.Once);
|
_clientOptionsMock.VerifyGet(o => o.DefaultQueryParams, Times.Once);
|
||||||
VerifyNoOtherCalls();
|
VerifyNoOtherCalls();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void ShouldThrowOnInvalidContentCategoryForBinary()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
_request.ContentCategory = 0;
|
||||||
|
var client = GetClient();
|
||||||
|
|
||||||
|
// Act & Assert
|
||||||
|
var ex = Assert.ThrowsExactly<ArgumentException>(() => client.SendBinaryMessage(_request, TestContext.CancellationToken));
|
||||||
|
Assert.AreEqual("contentCategory", ex.ParamName);
|
||||||
|
Assert.StartsWith("Content category '0' is not valid.", ex.Message);
|
||||||
|
|
||||||
|
VerifyNoOtherCalls();
|
||||||
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public async Task ShouldSendBinaryMessageFullDetails()
|
public async Task ShouldSendBinaryMessageFullDetails()
|
||||||
{
|
{
|
||||||
@@ -145,9 +156,7 @@ namespace LinkMobility.Tests.Sms
|
|||||||
Assert.AreEqual("Scheme Parameter", callback.Headers["Authorization"]);
|
Assert.AreEqual("Scheme Parameter", callback.Headers["Authorization"]);
|
||||||
Assert.AreEqual("LinkMobilityClient/1.0.0", callback.Headers["User-Agent"]);
|
Assert.AreEqual("LinkMobilityClient/1.0.0", callback.Headers["User-Agent"]);
|
||||||
|
|
||||||
_httpMessageHandlerMock.Mock
|
_httpMessageHandlerMock.Protected.Verify("SendAsync", Times.Once(), ItExpr.IsAny<HttpRequestMessage>(), ItExpr.IsAny<CancellationToken>());
|
||||||
.Protected()
|
|
||||||
.Verify("SendAsync", Times.Once(), ItExpr.IsAny<HttpRequestMessage>(), ItExpr.IsAny<CancellationToken>());
|
|
||||||
|
|
||||||
_clientOptionsMock.VerifyGet(o => o.DefaultQueryParams, Times.Once);
|
_clientOptionsMock.VerifyGet(o => o.DefaultQueryParams, Times.Once);
|
||||||
VerifyNoOtherCalls();
|
VerifyNoOtherCalls();
|
||||||
@@ -167,6 +176,36 @@ namespace LinkMobility.Tests.Sms
|
|||||||
VerifyNoOtherCalls();
|
VerifyNoOtherCalls();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void ShouldThrowOnNullMessageContentList()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
_request.MessageContent = null;
|
||||||
|
var client = GetClient();
|
||||||
|
|
||||||
|
// Act & Assert
|
||||||
|
var ex = Assert.ThrowsExactly<ArgumentException>(() => client.SendBinaryMessage(_request, TestContext.CancellationToken));
|
||||||
|
|
||||||
|
Assert.AreEqual("MessageContent", ex.ParamName);
|
||||||
|
|
||||||
|
VerifyNoOtherCalls();
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void ShouldThrowOnEmptyMessageContentList()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
_request.MessageContent = [];
|
||||||
|
var client = GetClient();
|
||||||
|
|
||||||
|
// Act & Assert
|
||||||
|
var ex = Assert.ThrowsExactly<ArgumentException>(() => client.SendBinaryMessage(_request, TestContext.CancellationToken));
|
||||||
|
|
||||||
|
Assert.AreEqual("MessageContent", ex.ParamName);
|
||||||
|
|
||||||
|
VerifyNoOtherCalls();
|
||||||
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void ShouldThrowOnInvalidMessageEncoding()
|
public void ShouldThrowOnInvalidMessageEncoding()
|
||||||
{
|
{
|
||||||
@@ -205,7 +244,7 @@ namespace LinkMobility.Tests.Sms
|
|||||||
// Act & Assert
|
// Act & Assert
|
||||||
var ex = Assert.ThrowsExactly<ArgumentException>(() => client.SendBinaryMessage(_request, TestContext.CancellationToken));
|
var ex = Assert.ThrowsExactly<ArgumentException>(() => client.SendBinaryMessage(_request, TestContext.CancellationToken));
|
||||||
|
|
||||||
Assert.AreEqual("RecipientAddressList", ex.ParamName);
|
Assert.AreEqual("recipientAddressList", ex.ParamName);
|
||||||
|
|
||||||
VerifyNoOtherCalls();
|
VerifyNoOtherCalls();
|
||||||
}
|
}
|
||||||
@@ -224,7 +263,7 @@ namespace LinkMobility.Tests.Sms
|
|||||||
// Act & Assert
|
// Act & Assert
|
||||||
var ex = Assert.ThrowsExactly<ArgumentException>(() => client.SendBinaryMessage(_request, TestContext.CancellationToken));
|
var ex = Assert.ThrowsExactly<ArgumentException>(() => client.SendBinaryMessage(_request, TestContext.CancellationToken));
|
||||||
|
|
||||||
Assert.AreEqual("RecipientAddressList", ex.ParamName);
|
Assert.AreEqual("recipientAddressList", ex.ParamName);
|
||||||
Assert.StartsWith($"Recipient address '{recipient}' is not a valid MSISDN format.", ex.Message);
|
Assert.StartsWith($"Recipient address '{recipient}' is not a valid MSISDN format.", ex.Message);
|
||||||
|
|
||||||
VerifyNoOtherCalls();
|
VerifyNoOtherCalls();
|
||||||
@@ -6,10 +6,11 @@ using System.Text;
|
|||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using AMWD.Net.Api.LinkMobility;
|
using AMWD.Net.Api.LinkMobility;
|
||||||
|
using AMWD.Net.Api.LinkMobility.Text;
|
||||||
using LinkMobility.Tests.Helpers;
|
using LinkMobility.Tests.Helpers;
|
||||||
using Moq.Protected;
|
using Moq.Protected;
|
||||||
|
|
||||||
namespace LinkMobility.Tests.Sms
|
namespace LinkMobility.Tests.Text
|
||||||
{
|
{
|
||||||
[TestClass]
|
[TestClass]
|
||||||
public class SendTextMessageTest
|
public class SendTextMessageTest
|
||||||
@@ -85,14 +86,27 @@ namespace LinkMobility.Tests.Sms
|
|||||||
Assert.AreEqual("Scheme Parameter", callback.Headers["Authorization"]);
|
Assert.AreEqual("Scheme Parameter", callback.Headers["Authorization"]);
|
||||||
Assert.AreEqual("LinkMobilityClient/1.0.0", callback.Headers["User-Agent"]);
|
Assert.AreEqual("LinkMobilityClient/1.0.0", callback.Headers["User-Agent"]);
|
||||||
|
|
||||||
_httpMessageHandlerMock.Mock
|
_httpMessageHandlerMock.Protected.Verify("SendAsync", Times.Once(), ItExpr.IsAny<HttpRequestMessage>(), ItExpr.IsAny<CancellationToken>());
|
||||||
.Protected()
|
|
||||||
.Verify("SendAsync", Times.Once(), ItExpr.IsAny<HttpRequestMessage>(), ItExpr.IsAny<CancellationToken>());
|
|
||||||
|
|
||||||
_clientOptionsMock.VerifyGet(o => o.DefaultQueryParams, Times.Once);
|
_clientOptionsMock.VerifyGet(o => o.DefaultQueryParams, Times.Once);
|
||||||
VerifyNoOtherCalls();
|
VerifyNoOtherCalls();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void ShouldThrowOnInvalidContentCategory()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
_request.ContentCategory = 0;
|
||||||
|
var client = GetClient();
|
||||||
|
|
||||||
|
// Act & Assert
|
||||||
|
var ex = Assert.ThrowsExactly<ArgumentException>(() => client.SendTextMessage(_request, TestContext.CancellationToken));
|
||||||
|
Assert.AreEqual("contentCategory", ex.ParamName);
|
||||||
|
Assert.StartsWith("Content category '0' is not valid.", ex.Message);
|
||||||
|
|
||||||
|
VerifyNoOtherCalls();
|
||||||
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public async Task ShouldSendTextMessageFullDetails()
|
public async Task ShouldSendTextMessageFullDetails()
|
||||||
{
|
{
|
||||||
@@ -145,9 +159,7 @@ namespace LinkMobility.Tests.Sms
|
|||||||
Assert.AreEqual("Scheme Parameter", callback.Headers["Authorization"]);
|
Assert.AreEqual("Scheme Parameter", callback.Headers["Authorization"]);
|
||||||
Assert.AreEqual("LinkMobilityClient/1.0.0", callback.Headers["User-Agent"]);
|
Assert.AreEqual("LinkMobilityClient/1.0.0", callback.Headers["User-Agent"]);
|
||||||
|
|
||||||
_httpMessageHandlerMock.Mock
|
_httpMessageHandlerMock.Protected.Verify("SendAsync", Times.Once(), ItExpr.IsAny<HttpRequestMessage>(), ItExpr.IsAny<CancellationToken>());
|
||||||
.Protected()
|
|
||||||
.Verify("SendAsync", Times.Once(), ItExpr.IsAny<HttpRequestMessage>(), ItExpr.IsAny<CancellationToken>());
|
|
||||||
|
|
||||||
_clientOptionsMock.VerifyGet(o => o.DefaultQueryParams, Times.Once);
|
_clientOptionsMock.VerifyGet(o => o.DefaultQueryParams, Times.Once);
|
||||||
VerifyNoOtherCalls();
|
VerifyNoOtherCalls();
|
||||||
@@ -192,7 +204,7 @@ namespace LinkMobility.Tests.Sms
|
|||||||
|
|
||||||
// Act & Assert
|
// Act & Assert
|
||||||
var ex = Assert.ThrowsExactly<ArgumentException>(() => client.SendTextMessage(req, TestContext.CancellationToken));
|
var ex = Assert.ThrowsExactly<ArgumentException>(() => client.SendTextMessage(req, TestContext.CancellationToken));
|
||||||
Assert.AreEqual("RecipientAddressList", ex.ParamName);
|
Assert.AreEqual("recipientAddressList", ex.ParamName);
|
||||||
|
|
||||||
VerifyNoOtherCalls();
|
VerifyNoOtherCalls();
|
||||||
}
|
}
|
||||||
@@ -211,7 +223,7 @@ namespace LinkMobility.Tests.Sms
|
|||||||
// Act & Assert
|
// Act & Assert
|
||||||
var ex = Assert.ThrowsExactly<ArgumentException>(() => client.SendTextMessage(req, TestContext.CancellationToken));
|
var ex = Assert.ThrowsExactly<ArgumentException>(() => client.SendTextMessage(req, TestContext.CancellationToken));
|
||||||
|
|
||||||
Assert.AreEqual("RecipientAddressList", ex.ParamName);
|
Assert.AreEqual("recipientAddressList", ex.ParamName);
|
||||||
Assert.StartsWith($"Recipient address '{recipient}' is not a valid MSISDN format.", ex.Message);
|
Assert.StartsWith($"Recipient address '{recipient}' is not a valid MSISDN format.", ex.Message);
|
||||||
|
|
||||||
VerifyNoOtherCalls();
|
VerifyNoOtherCalls();
|
||||||
33
test/LinkMobility.Tests/Utils/ValidationTest.cs
Normal file
33
test/LinkMobility.Tests/Utils/ValidationTest.cs
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
using AMWD.Net.Api.LinkMobility.Utils;
|
||||||
|
|
||||||
|
namespace LinkMobility.Tests.Utils
|
||||||
|
{
|
||||||
|
[TestClass]
|
||||||
|
public class ValidationTest
|
||||||
|
{
|
||||||
|
[TestMethod]
|
||||||
|
[DataRow("10000000")]
|
||||||
|
[DataRow("12345678")]
|
||||||
|
[DataRow("123456789012345")]
|
||||||
|
[DataRow("14155552671")]
|
||||||
|
public void ShouldValidateMSISDNSuccessful(string msisdn)
|
||||||
|
{
|
||||||
|
Assert.IsTrue(Validation.IsValidMSISDN(msisdn));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
[DataRow(null)]
|
||||||
|
[DataRow("")]
|
||||||
|
[DataRow(" ")]
|
||||||
|
[DataRow("012345678")]
|
||||||
|
[DataRow("+123456789")]
|
||||||
|
[DataRow("1234 5678")]
|
||||||
|
[DataRow("1234567")]
|
||||||
|
[DataRow("1234567890123456")]
|
||||||
|
[DataRow("abc1234567")]
|
||||||
|
public void ShouldValidateMSISDNNotSuccessful(string msisdn)
|
||||||
|
{
|
||||||
|
Assert.IsFalse(Validation.IsValidMSISDN(msisdn));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,9 +1,10 @@
|
|||||||
using AMWD.Net.Api.LinkMobility;
|
using AMWD.Net.Api.LinkMobility.Text;
|
||||||
|
using AMWD.Net.Api.LinkMobility.Webhook.Text;
|
||||||
|
|
||||||
namespace LinkMobility.Tests.Models
|
namespace LinkMobility.Tests.Webhook.Text
|
||||||
{
|
{
|
||||||
[TestClass]
|
[TestClass]
|
||||||
public class IncomingMessageNotificationTest
|
public class TextNotificationTest
|
||||||
{
|
{
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void ShouldParseAllPropertiesForTextNotification()
|
public void ShouldParseAllPropertiesForTextNotification()
|
||||||
@@ -29,13 +30,13 @@ namespace LinkMobility.Tests.Models
|
|||||||
}";
|
}";
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
bool successful = IncomingMessageNotification.TryParse(json, out var notification);
|
bool successful = TextNotification.TryParse(json, out var notification);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.IsTrue(successful, "TryParse should return true for valid json");
|
Assert.IsTrue(successful, "TryParse should return true for valid json");
|
||||||
Assert.IsNotNull(notification);
|
Assert.IsNotNull(notification);
|
||||||
|
|
||||||
Assert.AreEqual(IncomingMessageNotification.Type.Text, notification.MessageType);
|
Assert.AreEqual(TextMessageType.Text, notification.MessageType);
|
||||||
Assert.AreEqual("notif-123", notification.NotificationId);
|
Assert.AreEqual("notif-123", notification.NotificationId);
|
||||||
Assert.AreEqual("trans-456", notification.TransferId);
|
Assert.AreEqual("trans-456", notification.TransferId);
|
||||||
|
|
||||||
@@ -80,7 +81,7 @@ namespace LinkMobility.Tests.Models
|
|||||||
string invalid = "this is not json";
|
string invalid = "this is not json";
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
bool successful = IncomingMessageNotification.TryParse(invalid, out var notification);
|
bool successful = TextNotification.TryParse(invalid, out var notification);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.IsFalse(successful);
|
Assert.IsFalse(successful);
|
||||||
Reference in New Issue
Block a user