Carried over contracts.
All checks were successful
Pack and Push NuGet Package / publish (push) Successful in 44s
All checks were successful
Pack and Push NuGet Package / publish (push) Successful in 44s
This commit is contained in:
38
.gitea/workflows/publish-nuget.yml
Normal file
38
.gitea/workflows/publish-nuget.yml
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
name: Pack and Push NuGet Package
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
publish:
|
||||||
|
container:
|
||||||
|
image: mcr.microsoft.com/dotnet/sdk:9.0
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Install Node.js and dependencies
|
||||||
|
run: |
|
||||||
|
apt-get update
|
||||||
|
apt-get install -y curl gnupg
|
||||||
|
curl -fsSL https://deb.nodesource.com/setup_18.x | bash -
|
||||||
|
apt-get install -y nodejs git
|
||||||
|
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Restore dependencies
|
||||||
|
run: dotnet restore ./code/MessengerApi.Contracts/MessengerApi.Contracts.csproj
|
||||||
|
|
||||||
|
- name: Build project
|
||||||
|
run: dotnet build ./code/MessengerApi.Contracts/MessengerApi.Contracts.csproj -c Release
|
||||||
|
|
||||||
|
- name: Pack NuGet Package
|
||||||
|
run: |
|
||||||
|
dotnet pack ./code/MessengerApi.Contracts/MessengerApi.Contracts.csproj -c Release -o out
|
||||||
|
|
||||||
|
- name: Push to Gitea NuGet Registry
|
||||||
|
run: |
|
||||||
|
dotnet nuget push out/*.nupkg \
|
||||||
|
--api-key "${{ secrets.NUGET_PUBLISH_TOKEN }}" \
|
||||||
|
--source "https://gitea.masita.net/api/packages/${{ secrets.NUGET_PUBLISH_USERNAME }}/nuget/index.json"
|
||||||
400
.gitignore
vendored
Normal file
400
.gitignore
vendored
Normal file
@ -0,0 +1,400 @@
|
|||||||
|
# ---> VisualStudio
|
||||||
|
## Ignore Visual Studio temporary files, build results, and
|
||||||
|
## files generated by popular Visual Studio add-ons.
|
||||||
|
##
|
||||||
|
## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore
|
||||||
|
|
||||||
|
# User-specific files
|
||||||
|
*.rsuser
|
||||||
|
*.suo
|
||||||
|
*.user
|
||||||
|
*.userosscache
|
||||||
|
*.sln.docstates
|
||||||
|
|
||||||
|
# User-specific files (MonoDevelop/Xamarin Studio)
|
||||||
|
*.userprefs
|
||||||
|
|
||||||
|
# Mono auto generated files
|
||||||
|
mono_crash.*
|
||||||
|
|
||||||
|
# Build results
|
||||||
|
[Dd]ebug/
|
||||||
|
[Dd]ebugPublic/
|
||||||
|
[Rr]elease/
|
||||||
|
[Rr]eleases/
|
||||||
|
x64/
|
||||||
|
x86/
|
||||||
|
[Ww][Ii][Nn]32/
|
||||||
|
[Aa][Rr][Mm]/
|
||||||
|
[Aa][Rr][Mm]64/
|
||||||
|
bld/
|
||||||
|
[Bb]in/
|
||||||
|
[Oo]bj/
|
||||||
|
[Ll]og/
|
||||||
|
[Ll]ogs/
|
||||||
|
|
||||||
|
# Visual Studio 2015/2017 cache/options directory
|
||||||
|
.vs/
|
||||||
|
# Uncomment if you have tasks that create the project's static files in wwwroot
|
||||||
|
#wwwroot/
|
||||||
|
|
||||||
|
# Visual Studio 2017 auto generated files
|
||||||
|
Generated\ Files/
|
||||||
|
|
||||||
|
# MSTest test Results
|
||||||
|
[Tt]est[Rr]esult*/
|
||||||
|
[Bb]uild[Ll]og.*
|
||||||
|
|
||||||
|
# NUnit
|
||||||
|
*.VisualState.xml
|
||||||
|
TestResult.xml
|
||||||
|
nunit-*.xml
|
||||||
|
|
||||||
|
# Build Results of an ATL Project
|
||||||
|
[Dd]ebugPS/
|
||||||
|
[Rr]eleasePS/
|
||||||
|
dlldata.c
|
||||||
|
|
||||||
|
# Benchmark Results
|
||||||
|
BenchmarkDotNet.Artifacts/
|
||||||
|
|
||||||
|
# .NET Core
|
||||||
|
project.lock.json
|
||||||
|
project.fragment.lock.json
|
||||||
|
artifacts/
|
||||||
|
|
||||||
|
# ASP.NET Scaffolding
|
||||||
|
ScaffoldingReadMe.txt
|
||||||
|
|
||||||
|
# StyleCop
|
||||||
|
StyleCopReport.xml
|
||||||
|
|
||||||
|
# Files built by Visual Studio
|
||||||
|
*_i.c
|
||||||
|
*_p.c
|
||||||
|
*_h.h
|
||||||
|
*.ilk
|
||||||
|
*.meta
|
||||||
|
*.obj
|
||||||
|
*.iobj
|
||||||
|
*.pch
|
||||||
|
*.pdb
|
||||||
|
*.ipdb
|
||||||
|
*.pgc
|
||||||
|
*.pgd
|
||||||
|
*.rsp
|
||||||
|
*.sbr
|
||||||
|
*.tlb
|
||||||
|
*.tli
|
||||||
|
*.tlh
|
||||||
|
*.tmp
|
||||||
|
*.tmp_proj
|
||||||
|
*_wpftmp.csproj
|
||||||
|
*.log
|
||||||
|
*.tlog
|
||||||
|
*.vspscc
|
||||||
|
*.vssscc
|
||||||
|
.builds
|
||||||
|
*.pidb
|
||||||
|
*.svclog
|
||||||
|
*.scc
|
||||||
|
|
||||||
|
# Chutzpah Test files
|
||||||
|
_Chutzpah*
|
||||||
|
|
||||||
|
# Visual C++ cache files
|
||||||
|
ipch/
|
||||||
|
*.aps
|
||||||
|
*.ncb
|
||||||
|
*.opendb
|
||||||
|
*.opensdf
|
||||||
|
*.sdf
|
||||||
|
*.cachefile
|
||||||
|
*.VC.db
|
||||||
|
*.VC.VC.opendb
|
||||||
|
|
||||||
|
# Visual Studio profiler
|
||||||
|
*.psess
|
||||||
|
*.vsp
|
||||||
|
*.vspx
|
||||||
|
*.sap
|
||||||
|
|
||||||
|
# Visual Studio Trace Files
|
||||||
|
*.e2e
|
||||||
|
|
||||||
|
# TFS 2012 Local Workspace
|
||||||
|
$tf/
|
||||||
|
|
||||||
|
# Guidance Automation Toolkit
|
||||||
|
*.gpState
|
||||||
|
|
||||||
|
# ReSharper is a .NET coding add-in
|
||||||
|
_ReSharper*/
|
||||||
|
*.[Rr]e[Ss]harper
|
||||||
|
*.DotSettings.user
|
||||||
|
|
||||||
|
# TeamCity is a build add-in
|
||||||
|
_TeamCity*
|
||||||
|
|
||||||
|
# DotCover is a Code Coverage Tool
|
||||||
|
*.dotCover
|
||||||
|
|
||||||
|
# AxoCover is a Code Coverage Tool
|
||||||
|
.axoCover/*
|
||||||
|
!.axoCover/settings.json
|
||||||
|
|
||||||
|
# Coverlet is a free, cross platform Code Coverage Tool
|
||||||
|
coverage*.json
|
||||||
|
coverage*.xml
|
||||||
|
coverage*.info
|
||||||
|
|
||||||
|
# Visual Studio code coverage results
|
||||||
|
*.coverage
|
||||||
|
*.coveragexml
|
||||||
|
|
||||||
|
# NCrunch
|
||||||
|
_NCrunch_*
|
||||||
|
.*crunch*.local.xml
|
||||||
|
nCrunchTemp_*
|
||||||
|
|
||||||
|
# MightyMoose
|
||||||
|
*.mm.*
|
||||||
|
AutoTest.Net/
|
||||||
|
|
||||||
|
# Web workbench (sass)
|
||||||
|
.sass-cache/
|
||||||
|
|
||||||
|
# Installshield output folder
|
||||||
|
[Ee]xpress/
|
||||||
|
|
||||||
|
# DocProject is a documentation generator add-in
|
||||||
|
DocProject/buildhelp/
|
||||||
|
DocProject/Help/*.HxT
|
||||||
|
DocProject/Help/*.HxC
|
||||||
|
DocProject/Help/*.hhc
|
||||||
|
DocProject/Help/*.hhk
|
||||||
|
DocProject/Help/*.hhp
|
||||||
|
DocProject/Help/Html2
|
||||||
|
DocProject/Help/html
|
||||||
|
|
||||||
|
# Click-Once directory
|
||||||
|
publish/
|
||||||
|
|
||||||
|
# Publish Web Output
|
||||||
|
*.[Pp]ublish.xml
|
||||||
|
*.azurePubxml
|
||||||
|
# Note: Comment the next line if you want to checkin your web deploy settings,
|
||||||
|
# but database connection strings (with potential passwords) will be unencrypted
|
||||||
|
*.pubxml
|
||||||
|
*.publishproj
|
||||||
|
|
||||||
|
# Microsoft Azure Web App publish settings. Comment the next line if you want to
|
||||||
|
# checkin your Azure Web App publish settings, but sensitive information contained
|
||||||
|
# in these scripts will be unencrypted
|
||||||
|
PublishScripts/
|
||||||
|
|
||||||
|
# NuGet Packages
|
||||||
|
*.nupkg
|
||||||
|
# NuGet Symbol Packages
|
||||||
|
*.snupkg
|
||||||
|
# The packages folder can be ignored because of Package Restore
|
||||||
|
**/[Pp]ackages/*
|
||||||
|
# except build/, which is used as an MSBuild target.
|
||||||
|
!**/[Pp]ackages/build/
|
||||||
|
# Uncomment if necessary however generally it will be regenerated when needed
|
||||||
|
#!**/[Pp]ackages/repositories.config
|
||||||
|
# NuGet v3's project.json files produces more ignorable files
|
||||||
|
*.nuget.props
|
||||||
|
*.nuget.targets
|
||||||
|
|
||||||
|
# Microsoft Azure Build Output
|
||||||
|
csx/
|
||||||
|
*.build.csdef
|
||||||
|
|
||||||
|
# Microsoft Azure Emulator
|
||||||
|
ecf/
|
||||||
|
rcf/
|
||||||
|
|
||||||
|
# Windows Store app package directories and files
|
||||||
|
AppPackages/
|
||||||
|
BundleArtifacts/
|
||||||
|
Package.StoreAssociation.xml
|
||||||
|
_pkginfo.txt
|
||||||
|
*.appx
|
||||||
|
*.appxbundle
|
||||||
|
*.appxupload
|
||||||
|
|
||||||
|
# Visual Studio cache files
|
||||||
|
# files ending in .cache can be ignored
|
||||||
|
*.[Cc]ache
|
||||||
|
# but keep track of directories ending in .cache
|
||||||
|
!?*.[Cc]ache/
|
||||||
|
|
||||||
|
# Others
|
||||||
|
ClientBin/
|
||||||
|
~$*
|
||||||
|
*~
|
||||||
|
*.dbmdl
|
||||||
|
*.dbproj.schemaview
|
||||||
|
*.jfm
|
||||||
|
*.pfx
|
||||||
|
*.publishsettings
|
||||||
|
orleans.codegen.cs
|
||||||
|
|
||||||
|
# Including strong name files can present a security risk
|
||||||
|
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
|
||||||
|
#*.snk
|
||||||
|
|
||||||
|
# Since there are multiple workflows, uncomment next line to ignore bower_components
|
||||||
|
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
|
||||||
|
#bower_components/
|
||||||
|
|
||||||
|
# RIA/Silverlight projects
|
||||||
|
Generated_Code/
|
||||||
|
|
||||||
|
# Backup & report files from converting an old project file
|
||||||
|
# to a newer Visual Studio version. Backup files are not needed,
|
||||||
|
# because we have git ;-)
|
||||||
|
_UpgradeReport_Files/
|
||||||
|
Backup*/
|
||||||
|
UpgradeLog*.XML
|
||||||
|
UpgradeLog*.htm
|
||||||
|
ServiceFabricBackup/
|
||||||
|
*.rptproj.bak
|
||||||
|
|
||||||
|
# SQL Server files
|
||||||
|
*.mdf
|
||||||
|
*.ldf
|
||||||
|
*.ndf
|
||||||
|
|
||||||
|
# Business Intelligence projects
|
||||||
|
*.rdl.data
|
||||||
|
*.bim.layout
|
||||||
|
*.bim_*.settings
|
||||||
|
*.rptproj.rsuser
|
||||||
|
*- [Bb]ackup.rdl
|
||||||
|
*- [Bb]ackup ([0-9]).rdl
|
||||||
|
*- [Bb]ackup ([0-9][0-9]).rdl
|
||||||
|
|
||||||
|
# Microsoft Fakes
|
||||||
|
FakesAssemblies/
|
||||||
|
|
||||||
|
# GhostDoc plugin setting file
|
||||||
|
*.GhostDoc.xml
|
||||||
|
|
||||||
|
# Node.js Tools for Visual Studio
|
||||||
|
.ntvs_analysis.dat
|
||||||
|
node_modules/
|
||||||
|
|
||||||
|
# Visual Studio 6 build log
|
||||||
|
*.plg
|
||||||
|
|
||||||
|
# Visual Studio 6 workspace options file
|
||||||
|
*.opt
|
||||||
|
|
||||||
|
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
|
||||||
|
*.vbw
|
||||||
|
|
||||||
|
# Visual Studio 6 auto-generated project file (contains which files were open etc.)
|
||||||
|
*.vbp
|
||||||
|
|
||||||
|
# Visual Studio 6 workspace and project file (working project files containing files to include in project)
|
||||||
|
*.dsw
|
||||||
|
*.dsp
|
||||||
|
|
||||||
|
# Visual Studio 6 technical files
|
||||||
|
*.ncb
|
||||||
|
*.aps
|
||||||
|
|
||||||
|
# Visual Studio LightSwitch build output
|
||||||
|
**/*.HTMLClient/GeneratedArtifacts
|
||||||
|
**/*.DesktopClient/GeneratedArtifacts
|
||||||
|
**/*.DesktopClient/ModelManifest.xml
|
||||||
|
**/*.Server/GeneratedArtifacts
|
||||||
|
**/*.Server/ModelManifest.xml
|
||||||
|
_Pvt_Extensions
|
||||||
|
|
||||||
|
# Paket dependency manager
|
||||||
|
.paket/paket.exe
|
||||||
|
paket-files/
|
||||||
|
|
||||||
|
# FAKE - F# Make
|
||||||
|
.fake/
|
||||||
|
|
||||||
|
# CodeRush personal settings
|
||||||
|
.cr/personal
|
||||||
|
|
||||||
|
# Python Tools for Visual Studio (PTVS)
|
||||||
|
__pycache__/
|
||||||
|
*.pyc
|
||||||
|
|
||||||
|
# Cake - Uncomment if you are using it
|
||||||
|
# tools/**
|
||||||
|
# !tools/packages.config
|
||||||
|
|
||||||
|
# Tabs Studio
|
||||||
|
*.tss
|
||||||
|
|
||||||
|
# Telerik's JustMock configuration file
|
||||||
|
*.jmconfig
|
||||||
|
|
||||||
|
# BizTalk build output
|
||||||
|
*.btp.cs
|
||||||
|
*.btm.cs
|
||||||
|
*.odx.cs
|
||||||
|
*.xsd.cs
|
||||||
|
|
||||||
|
# OpenCover UI analysis results
|
||||||
|
OpenCover/
|
||||||
|
|
||||||
|
# Azure Stream Analytics local run output
|
||||||
|
ASALocalRun/
|
||||||
|
|
||||||
|
# MSBuild Binary and Structured Log
|
||||||
|
*.binlog
|
||||||
|
|
||||||
|
# NVidia Nsight GPU debugger configuration file
|
||||||
|
*.nvuser
|
||||||
|
|
||||||
|
# MFractors (Xamarin productivity tool) working folder
|
||||||
|
.mfractor/
|
||||||
|
|
||||||
|
# Local History for Visual Studio
|
||||||
|
.localhistory/
|
||||||
|
|
||||||
|
# Visual Studio History (VSHistory) files
|
||||||
|
.vshistory/
|
||||||
|
|
||||||
|
# BeatPulse healthcheck temp database
|
||||||
|
healthchecksdb
|
||||||
|
|
||||||
|
# Backup folder for Package Reference Convert tool in Visual Studio 2017
|
||||||
|
MigrationBackup/
|
||||||
|
|
||||||
|
# Ionide (cross platform F# VS Code tools) working folder
|
||||||
|
.ionide/
|
||||||
|
|
||||||
|
# Fody - auto-generated XML schema
|
||||||
|
FodyWeavers.xsd
|
||||||
|
|
||||||
|
# VS Code files for those working on multiple tools
|
||||||
|
.vscode/*
|
||||||
|
!.vscode/settings.json
|
||||||
|
!.vscode/tasks.json
|
||||||
|
!.vscode/launch.json
|
||||||
|
!.vscode/extensions.json
|
||||||
|
*.code-workspace
|
||||||
|
|
||||||
|
# Local History for Visual Studio Code
|
||||||
|
.history/
|
||||||
|
|
||||||
|
# Windows Installer files from build outputs
|
||||||
|
*.cab
|
||||||
|
*.msi
|
||||||
|
*.msix
|
||||||
|
*.msm
|
||||||
|
*.msp
|
||||||
|
|
||||||
|
# JetBrains Rider
|
||||||
|
*.sln.iml
|
||||||
|
|
||||||
12
Directory.Packages.props
Normal file
12
Directory.Packages.props
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<Project>
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageVersion Include="Microsoft.EntityFrameworkCore" Version="9.0.6" />
|
||||||
|
<PackageVersion Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.6" />
|
||||||
|
<PackageVersion Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.6" />
|
||||||
|
<PackageVersion Include="portaloggy" Version="1.0.2" />
|
||||||
|
<PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="9.0.0" />
|
||||||
|
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.6" />
|
||||||
|
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
|
<PackageVersion Include="Swashbuckle.AspNetCore" Version="7.1.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
</Project>
|
||||||
7
LICENSE
Normal file
7
LICENSE
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
Copyright 2024 Ondřej Mašita
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
15
NuGet.config
Normal file
15
NuGet.config
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<configuration>
|
||||||
|
<packageSources>
|
||||||
|
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
|
||||||
|
<add key="mc" value="https://gitea.masita.net/api/packages/mc/nuget/index.json" />
|
||||||
|
</packageSources>
|
||||||
|
<packageSourceMapping>
|
||||||
|
<packageSource key="nuget.org">
|
||||||
|
<package pattern="*" />
|
||||||
|
</packageSource>
|
||||||
|
<packageSource key="mc">
|
||||||
|
<package pattern="portaloggy" />
|
||||||
|
</packageSource>
|
||||||
|
</packageSourceMapping>
|
||||||
|
</configuration>
|
||||||
23
code/MessengerApi.Contracts/MessengerApi.Contracts.csproj
Normal file
23
code/MessengerApi.Contracts/MessengerApi.Contracts.csproj
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net9.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>disable</Nullable>
|
||||||
|
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
|
||||||
|
<PackageOutputPath>$(OutputPath)</PackageOutputPath>
|
||||||
|
<AssemblyVersion>$([System.DateTime]::UtcNow.ToString("yyyy.MM.dd.HHmm"))</AssemblyVersion>
|
||||||
|
<PackageVersion>$([System.DateTime]::UtcNow.ToString("yyyy.MM.dd.HHmm"))</PackageVersion>
|
||||||
|
<BaseOutputPath>..\out\</BaseOutputPath>
|
||||||
|
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
|
||||||
|
<Title>$(AssemblyName)</Title>
|
||||||
|
<PackageProjectUrl>https://gitea.masita.net/mc/messengerapi-tools</PackageProjectUrl>
|
||||||
|
<RepositoryUrl>https://gitea.masita.net/mc/messengerapi-tools</RepositoryUrl>
|
||||||
|
<PackageTags>logging;log;logger</PackageTags>
|
||||||
|
<PackageLicenseExpression>mit-0</PackageLicenseExpression>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="portaloggy" />
|
||||||
|
</ItemGroup>
|
||||||
|
</Project>
|
||||||
186
code/MessengerApi.Contracts/MessengerClient.cs
Normal file
186
code/MessengerApi.Contracts/MessengerClient.cs
Normal file
@ -0,0 +1,186 @@
|
|||||||
|
using portaloggy;
|
||||||
|
using System.Text;
|
||||||
|
using System.Text.Json.Nodes;
|
||||||
|
|
||||||
|
namespace MessengerApi.Contracts
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Exists for mocking reason. This is implemented by <see cref="MessengerClient"/>.
|
||||||
|
/// </summary>
|
||||||
|
public interface IMessengerClient
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Receives pending messages from the messenger API.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="credentials">Credentials to the API.</param>
|
||||||
|
IEnumerable<InboxMessage> GetMessages();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Acknowledges message reception to the server.
|
||||||
|
/// </summary>
|
||||||
|
void AckMessage(InboxMessage message);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sends a message.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="credentials">Credentials to the API.</param>
|
||||||
|
void SendMessage(OutboxMessage outboxMessage);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns user ids for allowed message recipients.
|
||||||
|
/// </summary>
|
||||||
|
Contact[] GetYellowPages();
|
||||||
|
}
|
||||||
|
|
||||||
|
public class MessengerClient : IMessengerClient
|
||||||
|
{
|
||||||
|
private readonly HttpClient _httpClient;
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
|
||||||
|
private DateTime _lastReceivedUtc;
|
||||||
|
private Credentials _credentials;
|
||||||
|
|
||||||
|
public MessengerClient(Credentials credentials, HttpClient httpClient = null, ILogger logger = null)
|
||||||
|
{
|
||||||
|
_credentials = credentials;
|
||||||
|
_httpClient = httpClient ?? new HttpClient();
|
||||||
|
_logger = logger ?? new ConsoleLogger();
|
||||||
|
_lastReceivedUtc = DateTime.MinValue.ToUniversalTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<InboxMessage> GetMessages()
|
||||||
|
{
|
||||||
|
var since = Uri.EscapeDataString(this._lastReceivedUtc.ToString("o"));
|
||||||
|
var url = $"{_credentials.ApiUrl}/receive?sinceUtc={since}";
|
||||||
|
var request = new HttpRequestMessage(HttpMethod.Get, url);
|
||||||
|
request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", _credentials.ApiKey);
|
||||||
|
|
||||||
|
_logger.Debug($"Sending query to {url} with content {request.ToString()} to obtain messages.");
|
||||||
|
|
||||||
|
var response = _httpClient.Send(request);
|
||||||
|
|
||||||
|
if (!response.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
|
_logger.Error(response.ReasonPhrase);
|
||||||
|
throw new HttpRequestException("Can't receive.", null, response.StatusCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
var responseContent = response.Content
|
||||||
|
.ReadAsStringAsync()
|
||||||
|
.GetAwaiter()
|
||||||
|
.GetResult();
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(responseContent))
|
||||||
|
{
|
||||||
|
_logger.Debug($"Received response of {responseContent}.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(responseContent))
|
||||||
|
{
|
||||||
|
return Enumerable.Empty<InboxMessage>().ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
var json = JsonNode.Parse(responseContent);
|
||||||
|
var messages = new List<InboxMessage>();
|
||||||
|
|
||||||
|
foreach (var item in json["messages"].AsArray())
|
||||||
|
{
|
||||||
|
if (item["id"].GetValue<int>() == -1)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
messages.Add(new InboxMessage
|
||||||
|
{
|
||||||
|
Id = item["id"].GetValue<Guid>(),
|
||||||
|
Payload = item["payload"].ToJsonString(),
|
||||||
|
PayloadType = item["payloadType"].ToJsonString(),
|
||||||
|
Sender = item["sender"].GetValue<Guid>(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
_lastReceivedUtc = DateTime.UtcNow.Subtract(TimeSpan.FromSeconds(10));
|
||||||
|
_logger.Debug($"Received {messages.Count} messages and last check timestamp is set to {_lastReceivedUtc.ToString("s")}.");
|
||||||
|
|
||||||
|
return messages.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SendMessage(OutboxMessage outboxMessage)
|
||||||
|
{
|
||||||
|
var body = new JsonObject();
|
||||||
|
|
||||||
|
if(outboxMessage.ToUserId.HasValue)
|
||||||
|
{
|
||||||
|
body.Add("toUserId", JsonValue.Create<Guid>(outboxMessage.ToUserId.Value));
|
||||||
|
}
|
||||||
|
|
||||||
|
if(outboxMessage.Payload != null)
|
||||||
|
{
|
||||||
|
body.Add("payload", JsonValue.Create<string>(outboxMessage.Payload));
|
||||||
|
}
|
||||||
|
|
||||||
|
if(outboxMessage.PayloadType != null)
|
||||||
|
{
|
||||||
|
body.Add("payloadType", JsonValue.Create<string>(outboxMessage.PayloadType));
|
||||||
|
}
|
||||||
|
|
||||||
|
if(outboxMessage.LifespanInSeconds != null)
|
||||||
|
{
|
||||||
|
body.Add("lifespanInSeconds", JsonValue.Create<int>(outboxMessage.LifespanInSeconds.Value));
|
||||||
|
}
|
||||||
|
|
||||||
|
var content = new StringContent(body.ToString(), Encoding.UTF8, "application/json");
|
||||||
|
|
||||||
|
var url = $"{_credentials.ApiUrl}/send";
|
||||||
|
var request = new HttpRequestMessage(HttpMethod.Post, url);
|
||||||
|
request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", _credentials.ApiKey);
|
||||||
|
|
||||||
|
_logger.Debug($"Sending query to {url} with content {body.ToString()} to obtain messages.");
|
||||||
|
|
||||||
|
var response = _httpClient.Send(request);
|
||||||
|
|
||||||
|
if (!response.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
|
_logger.Error(response.ReasonPhrase);
|
||||||
|
throw new HttpRequestException("Can't send.", null, response.StatusCode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Contact[] GetYellowPages()
|
||||||
|
{
|
||||||
|
var url = $"{_credentials.ApiUrl}/yellowpages";
|
||||||
|
var request = new HttpRequestMessage(HttpMethod.Get, url);
|
||||||
|
request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", _credentials.ApiKey);
|
||||||
|
|
||||||
|
_logger.Debug($"Sending query to {url} with content {request.ToString()}.");
|
||||||
|
|
||||||
|
var response = _httpClient.Send(request);
|
||||||
|
|
||||||
|
if (!response.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
|
_logger.Error(response.ReasonPhrase);
|
||||||
|
throw new HttpRequestException("Can't receive.", null, response.StatusCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
var responseContent = response.Content
|
||||||
|
.ReadAsStringAsync()
|
||||||
|
.GetAwaiter()
|
||||||
|
.GetResult();
|
||||||
|
|
||||||
|
var json = JsonNode.Parse(responseContent);
|
||||||
|
|
||||||
|
var contacts = json["users"].AsArray().Select(x => new Contact
|
||||||
|
{
|
||||||
|
Id = x["id"].GetValue<Guid>(),
|
||||||
|
Name = x["name"].GetValue<string>()
|
||||||
|
}).ToArray();
|
||||||
|
|
||||||
|
return contacts;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AckMessage(InboxMessage message)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
9
code/MessengerApi.Contracts/Model/Contact.cs
Normal file
9
code/MessengerApi.Contracts/Model/Contact.cs
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
namespace MessengerApi.Contracts
|
||||||
|
{
|
||||||
|
public class Contact
|
||||||
|
{
|
||||||
|
public Guid Id { get; set; }
|
||||||
|
|
||||||
|
public string Name { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
15
code/MessengerApi.Contracts/Model/Credentials.cs
Normal file
15
code/MessengerApi.Contracts/Model/Credentials.cs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
namespace MessengerApi.Contracts
|
||||||
|
{
|
||||||
|
public class Credentials
|
||||||
|
{
|
||||||
|
public string ApiKey { get; private set; }
|
||||||
|
|
||||||
|
public string ApiUrl { get; private set; }
|
||||||
|
|
||||||
|
public Credentials(string apiKey, string apiUrl)
|
||||||
|
{
|
||||||
|
ApiKey = apiKey;
|
||||||
|
ApiUrl = apiUrl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
16
code/MessengerApi.Contracts/Model/Messages/InboxMessage.cs
Normal file
16
code/MessengerApi.Contracts/Model/Messages/InboxMessage.cs
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
namespace MessengerApi.Contracts
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Message when received is inbox. For server apps, this is request-type of message. For clients, this is a response-type of message.
|
||||||
|
/// </summary>
|
||||||
|
public class InboxMessage
|
||||||
|
{
|
||||||
|
public Guid Id { get; set; }
|
||||||
|
|
||||||
|
public Guid Sender { get; set; }
|
||||||
|
|
||||||
|
public string PayloadType { get; set; }
|
||||||
|
|
||||||
|
public string Payload { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
16
code/MessengerApi.Contracts/Model/Messages/OutboxMessage.cs
Normal file
16
code/MessengerApi.Contracts/Model/Messages/OutboxMessage.cs
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
namespace MessengerApi.Contracts
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Outbox type of message. A server-app will treat this as a response. A client app will treat this as a request.
|
||||||
|
/// </summary>
|
||||||
|
public class OutboxMessage
|
||||||
|
{
|
||||||
|
public Guid? ToUserId { get; set; }
|
||||||
|
|
||||||
|
public string PayloadType { get; set; }
|
||||||
|
|
||||||
|
public string Payload { get; set; }
|
||||||
|
|
||||||
|
public int? LifespanInSeconds { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
50
code/MessengerApi.Tools.sln
Normal file
50
code/MessengerApi.Tools.sln
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio Version 17
|
||||||
|
VisualStudioVersion = 17.11.35312.102
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MessengerApi.Contracts", "MessengerApi.Contracts\MessengerApi.Contracts.csproj", "{833ED77F-A4E9-4FB3-BB84-4E55898B726A}"
|
||||||
|
EndProject
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MessengerApi.SubscriptionClient", "MessengerApi.SubscriptionClient\MessengerApi.SubscriptionClient.csproj", "{127D24B0-47F3-40E9-9136-899AFF206F19}"
|
||||||
|
EndProject
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MessengerApi.QueryClient", "MessengerApi.QueryClient\MessengerApi.QueryClient.csproj", "{6441673B-2621-4E2C-A9A0-971E83C3F80A}"
|
||||||
|
EndProject
|
||||||
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{8EC462FD-D22E-90A8-E5CE-7E832BA40C5D}"
|
||||||
|
EndProject
|
||||||
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{02EA681E-C7D8-13C7-8484-4AC65E1B71E8}"
|
||||||
|
ProjectSection(SolutionItems) = preProject
|
||||||
|
..\.gitea\workflows\publish-nuget.yml = ..\.gitea\workflows\publish-nuget.yml
|
||||||
|
EndProjectSection
|
||||||
|
EndProject
|
||||||
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".gitea", ".gitea", "{C3305381-7A52-4E26-9527-1697692DDD5A}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{833ED77F-A4E9-4FB3-BB84-4E55898B726A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{833ED77F-A4E9-4FB3-BB84-4E55898B726A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{833ED77F-A4E9-4FB3-BB84-4E55898B726A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{833ED77F-A4E9-4FB3-BB84-4E55898B726A}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{127D24B0-47F3-40E9-9136-899AFF206F19}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{127D24B0-47F3-40E9-9136-899AFF206F19}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{127D24B0-47F3-40E9-9136-899AFF206F19}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{127D24B0-47F3-40E9-9136-899AFF206F19}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{6441673B-2621-4E2C-A9A0-971E83C3F80A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{6441673B-2621-4E2C-A9A0-971E83C3F80A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{6441673B-2621-4E2C-A9A0-971E83C3F80A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{6441673B-2621-4E2C-A9A0-971E83C3F80A}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(NestedProjects) = preSolution
|
||||||
|
{02EA681E-C7D8-13C7-8484-4AC65E1B71E8} = {C3305381-7A52-4E26-9527-1697692DDD5A}
|
||||||
|
{C3305381-7A52-4E26-9527-1697692DDD5A} = {8EC462FD-D22E-90A8-E5CE-7E832BA40C5D}
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {61948E36-4C2B-4BC9-80B6-9E155CE9F7DE}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
||||||
Reference in New Issue
Block a user