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

Commit

Permalink
Update PB api, switch from channel tag to target device ID
Browse files Browse the repository at this point in the history
  • Loading branch information
kekonn committed Aug 15, 2019
1 parent 881bd30 commit aefcd40
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
26 changes: 12 additions & 14 deletions Configuration/Configuration.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.IO;
using Microsoft.Extensions.Configuration;
using System.Linq;
using PushbulletSharp;
using PushbulletSharp.Models.Responses;

Expand Down Expand Up @@ -31,15 +30,14 @@ public PushbulletClient PBClient
return _pbClient;
}
}

public Subscription PBChannelSubscription { get; private set; }
public string PBTargetDeviceId { get; private set; }

private const string ApiEnvironmentKey = EnvironmentConfigPrefix + "PBAPI";
private const string ChannelEnvironmentKey = EnvironmentConfigPrefix + "CHANNEL";
private const string DeviceEnvironmentKey = EnvironmentConfigPrefix + "PBDEVICE";

private const string PBSectionKey = "Pushbullet";
private const string ApiKeyConfigKey = "Pushbullet API key";
private const string ChannelConfigKey = "Channel tag";
private const string DeviceConfigKey = "Target device";

private IConfigurationSection PushbulletConfigSection
{
Expand All @@ -54,6 +52,7 @@ private IConfigurationSection PushbulletConfigSection
return pbConfigSection;
}
}

#endregion

#region Transmission Settings
Expand Down Expand Up @@ -99,8 +98,7 @@ private void PushbulletSetup()
var apiKey = GetPBApiKey();

_pbClient = new PushbulletClient(apiKey, TimeZoneInfo.Local);

PBChannelSubscription = PBClient.SubscribeToChannel(GetChannelTag());
PBTargetDeviceId = GetDeviceId();
}


Expand All @@ -120,21 +118,21 @@ private string GetPBApiKey()
return apiKey;
}

private string GetChannelTag()
private string GetDeviceId()
{
var channelTag = ApplicationConfig[ChannelEnvironmentKey];
var deviceId = ApplicationConfig[DeviceEnvironmentKey];

if (string.IsNullOrWhiteSpace(channelTag))
if (string.IsNullOrWhiteSpace(deviceId))
{
channelTag = PushbulletConfigSection[ChannelConfigKey];
deviceId = PushbulletConfigSection[DeviceConfigKey];
}

if (string.IsNullOrEmpty(channelTag))
if (string.IsNullOrEmpty(deviceId))
{
throw new ApplicationException("Please specify a Pushbullet channel tag");
throw new ApplicationException("Please specify a Pushbullet target device id");
}

return channelTag;
return deviceId;
}
#endregion

Expand Down
4 changes: 2 additions & 2 deletions configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ This file is to be placed in the applications main directory.

### Section "Pushbullet"
* "Pushbullet API key": String containing the Pushbullet API key created for the app.
* "Channel tag": String containing the channel tag where PB should listen
* "Target Device": String containing the device id that PB should target when sending messages

## Section "Transmission"
* "Host": String containing the hostname of the transmission server
Expand All @@ -15,5 +15,5 @@ This file is to be placed in the applications main directory.
All Environment Variables pertaining to the importer have to be prefixed with "TPI_".

* TPI_PBAPI: Pusbhullet API key
* TPI_CHANNEL: Pushbullet channel tag
* TPI_PBDEVICE: Pushbullet target device
* TPI_THOST: Transmission Hostname

0 comments on commit aefcd40

Please sign in to comment.