Skip to content
This repository has been archived by the owner on Aug 29, 2022. It is now read-only.

Migrate to Asp.Net Core Web Api #16

Merged
merged 1 commit into from
Nov 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,58 +1,50 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Mime;
using System.Threading.Tasks;
using MediaBrowser.Common.Net;
using MediaBrowser.Model.Serialization;
using MediaBrowser.Model.Services;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Pushbullet.Configuration;

namespace Pushbullet.Api
{
/// <summary>
/// API endpoints.
/// Pushbullet notifications controller.
/// </summary>
public class ServerApiEntryPoints : IService
[ApiController]
[Route("Notification/Pushbullet")]
[Produces(MediaTypeNames.Application.Json)]
public class PushbulletNotificationsController : ControllerBase
{
private readonly IHttpClient _httpClient;
private readonly IJsonSerializer _jsonSerializer;

/// <summary>
/// Initializes a new instance of the <see cref="ServerApiEntryPoints"/> class.
/// Initializes a new instance of the <see cref="PushbulletNotificationsController"/> class.
/// </summary>
/// <param name="jsonSerializer">Instance of the <see cref="IJsonSerializer"/> interface.</param>
/// <param name="httpClient">Instance of the <see cref="IHttpClient"/> interface.</param>
public ServerApiEntryPoints(IJsonSerializer jsonSerializer, IHttpClient httpClient)
public PushbulletNotificationsController(IJsonSerializer jsonSerializer, IHttpClient httpClient)
{
_jsonSerializer = jsonSerializer;
_httpClient = httpClient;
}

private static PushbulletOptions GetOptions(string userId)
{
return Plugin.Instance!.Configuration.GetOptions()
.FirstOrDefault(i => string.Equals(i.UserId, userId, StringComparison.OrdinalIgnoreCase));
}

/// <summary>
/// Send test notification.
/// Send Pushbullet test notification.
/// </summary>
/// <param name="request">Request to send.</param>
public void Post(TestNotification request)
/// <param name="userId">The user id of the Jellyfin user.</param>
/// <response code="204">Test notification successfully sent.</response>
/// <returns>A <see cref="NoContentResult"/> indicating success.</returns>
[HttpPost("Test/{userId}")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
public async Task<ActionResult> PostAsync([FromRoute] string userId)
{
PostAsync(request)
.GetAwaiter()
.GetResult();
}

/// <summary>
/// Send test notification.
/// </summary>
/// <param name="request">Request to send.</param>
/// <returns>A <see cref="Task"/>.</returns>
public async Task PostAsync(TestNotification request)
{
var options = GetOptions(request.UserId!);
var options = Plugin.Instance!.Configuration.GetOptions()
.FirstOrDefault(i => string.Equals(i.UserId, userId, StringComparison.OrdinalIgnoreCase));

var parameters = new Dictionary<string, string>
{
Expand All @@ -71,6 +63,8 @@ public async Task PostAsync(TestNotification request)
};

await _httpClient.Post(requestOptions).ConfigureAwait(false);

return NoContent();
}
}
}
23 changes: 0 additions & 23 deletions Pushbullet/Api/TestNotification.cs

This file was deleted.

1 change: 1 addition & 0 deletions Pushbullet/Pushbullet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Jellyfin.Controller" Version="10.*-*" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
</ItemGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
Expand Down