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

Commit

Permalink
Merge pull request #3 from Nickbert7/patch-1
Browse files Browse the repository at this point in the history
Update for 10.3.7 + ChannelSupport
  • Loading branch information
joshuaboniface authored Sep 26, 2019
2 parents 3320b01 + 90caa01 commit 53c01f4
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 32 deletions.
25 changes: 15 additions & 10 deletions Pushbullet/Api/ServerApiEntryPoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Text;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Net;
using MediaBrowser.Model.Serialization;
using Microsoft.Extensions.Logging;
using MediaBrowser.Model.Services;
using Pushbullet.Configuration;
Expand All @@ -24,11 +25,13 @@ public class TestNotification : IReturnVoid
class ServerApiEndpoints : IService
{
private readonly IHttpClient _httpClient;
private readonly IJsonSerializer _jsonSerializer;
private readonly ILogger _logger;

public ServerApiEndpoints(ILogger logger, IHttpClient httpClient)
public ServerApiEndpoints(ILogger logger, IJsonSerializer jsonSerializer, IHttpClient httpClient)
{
_logger = logger;
_jsonSerializer = jsonSerializer;
_httpClient = httpClient;
}
private PushbulletOptions GetOptions(String userID)
Expand Down Expand Up @@ -61,16 +64,18 @@ public async Task PostAsync(TestNotification request)
string authInfo = options.Token;
authInfo = Convert.ToBase64String(Encoding.UTF8.GetBytes(authInfo));

_httpRequest.RequestHeaders["Authorization"] = "Basic " + authInfo;

_httpRequest.Url = "https://api.pushbullet.com/v2/pushes";

_httpRequest.SetPostData(parameters);

using (await _httpClient.Post(_httpRequest).ConfigureAwait(false))
var requestOptions = new HttpRequestOptions
{

}
Url = "https://api.pushbullet.com/v2/pushes",
RequestContent = _jsonSerializer.SerializeToString(parameters),
BufferContent = false,
RequestContentType = "application/json",
LogErrorResponseBody = true,
DecompressionMethod = CompressionMethod.None,
EnableKeepAlive = false
};
requestOptions.RequestHeaders["Authorization"] = "Basic " + authInfo;
await _httpClient.Post(requestOptions).ConfigureAwait(false);
}
}
}
7 changes: 4 additions & 3 deletions Pushbullet/Configuration/PluginConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ public PluginConfiguration()

public class PushbulletOptions
{
public Boolean Enabled { get; set; }
public String Token { get; set; }
public String DeviceId { get; set; }
public bool Enabled { get; set; }
public string Token { get; set; }
public string DeviceId { get; set; }
public string Channel { get; set; }
public string MediaBrowserUserId { get; set; }
}

Expand Down
10 changes: 9 additions & 1 deletion Pushbullet/Configuration/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
<input is="emby-checkbox" type="checkbox" id="chkEnablePushbullet" />
<span>Enabled</span>
</label>
<div class="inputContainer">
<input is="emby-input" type="text" id="txtPushbulletChannel" label="Pushbullet channel:" />
<div class="fieldDescription">
Pushbullet channel
</div>
</div>
<div class="inputContainer">
<input is="emby-input" type="text" id="txtPushbulletAuthKey" required="required" label="Pushbullet auth token:" />
<div class="fieldDescription">
Expand Down Expand Up @@ -56,6 +62,7 @@
})[0] || {};

$('#chkEnablePushbullet', page).checked(PushbulletConfig.Enabled || false).checkboxradio("refresh");
$('#txtPushbulletChannel', page).val(PushbulletConfig.Channel || '');
$('#txtPushbulletAuthKey', page).val(PushbulletConfig.Token || '');
$('#txtPushbulletDeviceId', page).val(PushbulletConfig.DeviceId || '');

Expand Down Expand Up @@ -148,6 +155,7 @@
PushbulletConfig.MediaBrowserUserId = userId;

PushbulletConfig.Enabled = $('#chkEnablePushbullet', form).checked();
PushbulletConfig.Channel = $('#txtPushbulletChannel', form).val();
PushbulletConfig.Token = $('#txtPushbulletAuthKey', form).val();
PushbulletConfig.DeviceId = $('#txtPushbulletDeviceId', form).val();

Expand All @@ -162,4 +170,4 @@
</script>
</div>
</body>
</html>
</html>
32 changes: 19 additions & 13 deletions Pushbullet/Notifier.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Text;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Notifications;
using Microsoft.Extensions.Logging;
using MediaBrowser.Model.Serialization;
using Pushbullet.Configuration;
using System;
using System.Linq;
Expand All @@ -16,11 +17,13 @@ public class Notifier : INotificationService
{
private readonly ILogger _logger;
private readonly IHttpClient _httpClient;
private readonly IJsonSerializer _jsonSerializer;

public Notifier(ILogger logger, IHttpClient httpClient)
public Notifier(ILogger logger, IHttpClient httpClient, IJsonSerializer jsonSerializer)
{
_logger = logger;
_httpClient = httpClient;
_jsonSerializer = jsonSerializer;
}

public bool IsEnabledForUser(User user)
Expand Down Expand Up @@ -48,26 +51,29 @@ public async Task SendNotification(UserNotification request, CancellationToken c
var parameters = new Dictionary<string, string>
{
// {"device_iden", options.DeviceId},
{"channel_tag", options.Channel},
{"type", "note"},
{"title", request.Name},
{"body", request.Description}
};

_logger.LogDebug("Pushbullet to Token : {0} - {1} - {2}", options.Token, options.DeviceId, request.Description);
var _httpRequest = new HttpRequestOptions();

string authInfo = options.Token;
authInfo = Convert.ToBase64String(Encoding.UTF8.GetBytes(authInfo));

_httpRequest.RequestHeaders["Authorization"] = "Basic " + authInfo;

_httpRequest.Url = "https://api.pushbullet.com/v2/pushes";

_httpRequest.SetPostData(parameters);

using (await _httpClient.Post(_httpRequest).ConfigureAwait(false))
{

}
var requestOptions = new HttpRequestOptions
{
Url = "https://api.pushbullet.com/v2/pushes",
RequestContent = _jsonSerializer.SerializeToString(parameters),
BufferContent = false,
RequestContentType = "application/json",
LogErrorResponseBody = true,
DecompressionMethod = CompressionMethod.None,
EnableKeepAlive = false
};
requestOptions.RequestHeaders["Authorization"] = "Basic " + authInfo;
await _httpClient.Post(requestOptions).ConfigureAwait(false);
}

private bool IsValid(PushbulletOptions options)
Expand Down
6 changes: 3 additions & 3 deletions Pushbullet/Pushbullet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

<PropertyGroup>
<TargetFrameworks>netstandard2.0;</TargetFrameworks>
<AssemblyVersion>1.0.0</AssemblyVersion>
<FileVersion>1.0.0</FileVersion>
<AssemblyVersion>2.0.0</AssemblyVersion>
<FileVersion>2.0.0</FileVersion>
</PropertyGroup>

<ItemGroup>
Expand All @@ -20,4 +20,4 @@
<PackageReference Include="Jellyfin.Controller" Version="10.*" />
</ItemGroup>

</Project>
</Project>
4 changes: 2 additions & 2 deletions build.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
name: "jellyfin-plugin-pushbullet"
guid: "de228f12-e43e-4bd9-9fc0-2830819c3b92"
version: "1" # Please increment with each pull request
jellyfin_version: "10.3.0" # The earliest binary-compatible version
version: "2" # Please increment with each pull request
jellyfin_version: "10.3.7" # The earliest binary-compatible version
nicename: "Pushbullet"
description: "Jellyfin Pushbullet notification plugin"
overview: >
Expand Down

0 comments on commit 53c01f4

Please sign in to comment.