Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggested change to add MessageStyle parameter to Push and PushAsync #10

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions MigrationBackup/0f58b976/PushoverClient/PushoverClient.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{16E7D1FF-237A-4E89-94C6-FDDA36FBDDB0}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>PushoverClient</RootNamespace>
<AssemblyName>PushoverClient</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<RestorePackages>true</RestorePackages>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="NotificationSound.cs" />
<Compile Include="Priority.cs" />
<Compile Include="Pushover.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="PushOverRequestArguments.cs" />
<Compile Include="PushResponse.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
76 changes: 76 additions & 0 deletions MigrationBackup/a18c6d13/SendPush/SendPush.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{6DB8F6AB-5003-4E57-80D8-D8A626D525DD}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>SendPush</RootNamespace>
<AssemblyName>SendPush</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<RestorePackages>true</RestorePackages>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Extensions.CommandLineUtils, Version=1.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\..\..\..\..\Packages\Microsoft.Extensions.CommandLineUtils.1.1.1\lib\net451\Microsoft.Extensions.CommandLineUtils.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Options.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config">
<SubType>Designer</SubType>
</None>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\PushoverClient\PushoverClient.csproj">
<Project>{16e7d1ff-237a-4e89-94c6-fdda36fbddb0}</Project>
<Name>PushoverClient</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\nuget.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="CommandLineParser" version="1.9.71" targetFramework="net45" />
<package id="Microsoft.Extensions.CommandLineUtils" version="1.1.1" targetFramework="net472" />
</packages>
64 changes: 64 additions & 0 deletions PushoverClient.Tests/ClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,69 @@ public async Task PushWithSound_ReturnsSuccessful()
Assert.IsNotNull(response);
Assert.AreEqual(1, response.Status);
}

[TestMethod]
public void PushHtmlWithValidParms_ReturnsSuccessful()
{
// Arrange
var title = "Test title";
var message = "This is a <b>bold test</b> with <i>italic</i> push notification message";

// Act
var pclient = new Pushover(TEST_APP_KEY);
var response = pclient.Push(title, message, TEST_USER_KEY, "", Priority.Normal, NotificationSound.Bike, MessageStyle.html);

// Assert
Assert.IsNotNull(response);
Assert.AreEqual(1, response.Status);
}

[TestMethod]
public async Task PushHtmlAsyncWithValidParms_ReturnsSuccessful()
{
// Arrange
var title = "Test title";
var message = "This is an async <b>bold test</b> with <i>italic</i> push notification message";

// Act
var pclient = new Pushover(TEST_APP_KEY);
var response = await pclient.PushAsync(title, message, TEST_USER_KEY, "", Priority.Normal, NotificationSound.Bike, MessageStyle.html);

// Assert
Assert.IsNotNull(response);
Assert.AreEqual(1, response.Status);
}

[TestMethod]
public void PushMonospaceWithValidParms_ReturnsSuccessful()
{
// Arrange
var title = "Test title";
var message = "This is a monospace test push notification message";

// Act
var pclient = new Pushover(TEST_APP_KEY);
var response = pclient.Push(title, message, TEST_USER_KEY, "", Priority.Normal, NotificationSound.Bike, MessageStyle.monospace);

// Assert
Assert.IsNotNull(response);
Assert.AreEqual(1, response.Status);
}

[TestMethod]
public async Task PushMonospaceAsyncWithValidParms_ReturnsSuccessful()
{
// Arrange
var title = "Test title";
var message = "This is an async monospace test push notification message";

// Act
var pclient = new Pushover(TEST_APP_KEY);
var response = await pclient.PushAsync(title, message, TEST_USER_KEY, "", Priority.Normal, NotificationSound.Bike, MessageStyle.monospace);

// Assert
Assert.IsNotNull(response);
Assert.AreEqual(1, response.Status);
}
}
}
13 changes: 13 additions & 0 deletions PushoverClient/MessageStyle.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace PushoverClient
{
//Detail at https://pushover.net/api#html
public enum MessageStyle
{
NotSet, //Default = will leave empty on sending
html,
monospace
}
}
2 changes: 2 additions & 0 deletions PushoverClient/PushOverRequestArguments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ public class PushoverRequestArguments
public string message { get; set; }
public int priority { get; set; }
public string sound { get; set; }
public string html { get; set; }
public string monospace { get; set; }
}
}
23 changes: 17 additions & 6 deletions PushoverClient/Pushover.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using ServiceStack;
using System;
using System.Globalization;
using System.Net;
using System.Threading.Tasks;

Expand Down Expand Up @@ -63,10 +64,11 @@ public Pushover(string appKey, string defaultSendKey) : this(appKey)
/// <param name="device">Send to a specific device</param>
/// <param name="priority">Priority of the message (optional) default value set to Normal</param>
/// <param name="notificationSound">If set sends the notification sound</param>
/// <param name="messageStyle">Sets the message text style</param>
/// <returns></returns>
public PushResponse Push(string title, string message, string userKey = "", string device = "", Priority priority = Priority.Normal, NotificationSound notificationSound = NotificationSound.NotSet)
public PushResponse Push(string title, string message, string userKey = "", string device = "", Priority priority = Priority.Normal, NotificationSound notificationSound = NotificationSound.NotSet, MessageStyle messageStyle = MessageStyle.NotSet)
{
var args = CreateArgs(title, message, userKey, device, priority, notificationSound);
var args = CreateArgs(title, message, userKey, device, priority, notificationSound, messageStyle);
try
{
return BASE_API_URL.PostToUrl(args).FromJson<PushResponse>();
Expand All @@ -86,10 +88,11 @@ public PushResponse Push(string title, string message, string userKey = "", stri
/// <param name="device">Send to a specific device</param>
/// <param name="priority">Priority of the message (optional) default value set to Normal</param>
/// <param name="notificationSound">If set sends the notification sound</param>
/// <param name="messageStyle">Sets the message text style</param>
/// <returns></returns>
public async Task<PushResponse> PushAsync(string title, string message, string userKey = "", string device = "", Priority priority = Priority.Normal, NotificationSound notificationSound = NotificationSound.NotSet)
public async Task<PushResponse> PushAsync(string title, string message, string userKey = "", string device = "", Priority priority = Priority.Normal, NotificationSound notificationSound = NotificationSound.NotSet, MessageStyle messageStyle = MessageStyle.NotSet)
{
var args = CreateArgs(title, message, userKey, device, priority, notificationSound);
var args = CreateArgs(title, message, userKey, device, priority, notificationSound, messageStyle);
try
{
return (await BASE_API_URL.PostToUrlAsync(args)).FromJson<PushResponse>();
Expand All @@ -101,8 +104,7 @@ public async Task<PushResponse> PushAsync(string title, string message, string u
}



private object CreateArgs(string title, string message, string userKey, string device, Priority priority, NotificationSound notificationSound)
private object CreateArgs(string title, string message, string userKey, string device, Priority priority, NotificationSound notificationSound, MessageStyle messageStyle)
{
// Try the passed user key or fall back to default
var userGroupKey = string.IsNullOrEmpty(userKey) ? DefaultUserGroupSendKey : userKey;
Expand All @@ -127,6 +129,15 @@ private object CreateArgs(string title, string message, string userKey, string d
args.sound = notificationSound.ToString().ToLower();
}

if (messageStyle == MessageStyle.html)
{
args.html = "1";
}
if (messageStyle == MessageStyle.monospace)
{
args.monospace = "1";
}

return args;
}

Expand Down
8 changes: 4 additions & 4 deletions PushoverClient/PushoverClient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="ServiceStack.Text, Version=5.0.0.0, Culture=neutral, PublicKeyToken=02c12cbda47e6587, processorArchitecture=MSIL">
<HintPath>..\packages\ServiceStack.Text.5.0.2\lib\net45\ServiceStack.Text.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Runtime.Serialization" />
Expand All @@ -48,6 +45,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="MessageStyle.cs" />
<Compile Include="NotificationSound.cs" />
<Compile Include="Priority.cs" />
<Compile Include="Pushover.cs" />
Expand All @@ -56,7 +54,9 @@
<Compile Include="PushResponse.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
<PackageReference Include="ServiceStack.Text">
<Version>5.0.2</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
Expand Down
12 changes: 8 additions & 4 deletions SendPush/SendPush.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="CommandLine">
<HintPath>..\packages\CommandLineParser.1.9.71\lib\net45\CommandLine.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
Expand All @@ -56,14 +53,21 @@
<None Include="App.config">
<SubType>Designer</SubType>
</None>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\PushoverClient\PushoverClient.csproj">
<Project>{16e7d1ff-237a-4e89-94c6-fdda36fbddb0}</Project>
<Name>PushoverClient</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<PackageReference Include="CommandLineParser">
<Version>1.9.71</Version>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.CommandLineUtils">
<Version>1.1.1</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\nuget.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down