mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-16 02:02:55 -07:00
!wip
This commit is contained in:
parent
b0d229975b
commit
c370909619
13 changed files with 338 additions and 3 deletions
11
src/Ombi.Api.Notifications/IOneSignalApi.cs
Normal file
11
src/Ombi.Api.Notifications/IOneSignalApi.cs
Normal file
|
@ -0,0 +1,11 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Ombi.Api.Notifications.Models;
|
||||
|
||||
namespace Ombi.Api.Notifications
|
||||
{
|
||||
public interface IOneSignalApi
|
||||
{
|
||||
Task<OneSignalNotificationResponse> PushNotification(List<string> playerIds, string message);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
namespace Ombi.Api.Notifications.Models
|
||||
{
|
||||
public class OneSignalNotificationBody
|
||||
{
|
||||
public string app_id { get; set; }
|
||||
public string[] include_player_ids { get; set; }
|
||||
public Data data { get; set; }
|
||||
public Contents contents { get; set; }
|
||||
}
|
||||
|
||||
public class Data
|
||||
{
|
||||
public string foo { get; set; }
|
||||
}
|
||||
|
||||
public class Contents
|
||||
{
|
||||
public string en { get; set; }
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
namespace Ombi.Api.Notifications.Models
|
||||
{
|
||||
public class OneSignalNotificationResponse
|
||||
{
|
||||
public string id { get; set; }
|
||||
public int recipients { get; set; }
|
||||
}
|
||||
|
||||
}
|
11
src/Ombi.Api.Notifications/Ombi.Api.Notifications.csproj
Normal file
11
src/Ombi.Api.Notifications/Ombi.Api.Notifications.csproj
Normal file
|
@ -0,0 +1,11 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Ombi.Api\Ombi.Api.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
48
src/Ombi.Api.Notifications/OneSignalApi.cs
Normal file
48
src/Ombi.Api.Notifications/OneSignalApi.cs
Normal file
|
@ -0,0 +1,48 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using Ombi.Api.Notifications.Models;
|
||||
using Ombi.Store.Entities;
|
||||
using Ombi.Store.Repository;
|
||||
|
||||
namespace Ombi.Api.Notifications
|
||||
{
|
||||
public class OneSignalApi : IOneSignalApi
|
||||
{
|
||||
public OneSignalApi(IApi api, IApplicationConfigRepository repo)
|
||||
{
|
||||
_api = api;
|
||||
_appConfig = repo;
|
||||
}
|
||||
|
||||
private readonly IApi _api;
|
||||
private readonly IApplicationConfigRepository _appConfig;
|
||||
private const string ApiUrl = "https://onesignal.com/api/v1/notifications";
|
||||
|
||||
public async Task<OneSignalNotificationResponse> PushNotification(List<string> playerIds, string message)
|
||||
{
|
||||
if (!playerIds.Any())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var id = await _appConfig.Get(ConfigurationTypes.Notification);
|
||||
var request = new Request(string.Empty, ApiUrl, HttpMethod.Post);
|
||||
|
||||
var body = new OneSignalNotificationBody
|
||||
{
|
||||
app_id = id.Value,
|
||||
contents = new Contents
|
||||
{
|
||||
en = message
|
||||
},
|
||||
include_player_ids = playerIds.ToArray()
|
||||
};
|
||||
|
||||
request.AddJsonBody(body);
|
||||
|
||||
var result = await _api.Request<OneSignalNotificationResponse>(request);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue