Commit 90eedfea authored by Andreas Müller's avatar Andreas Müller
Browse files

Initial Commit

# Created by,macos,windows,visualstudio,visualstudiocode
# Edit at,macos,windows,visualstudio,visualstudiocode
### Linux ###
# temporary files which can be created if a process still has a handle open of a deleted file
# KDE directory preferences
# Linux trash folder which might appear on any partition or disk
# .nfs files are created when an open file is removed but is still being accessed
### macOS ###
# General
# Icon must end with two \r
# Thumbnails
# Files that might appear in the root of a volume
# Directories potentially created on remote AFP share
Network Trash Folder
Temporary Items
### VisualStudioCode ###
### VisualStudioCode Patch ###
# Ignore all local history of files
### Windows ###
# Windows thumbnail cache files
# Dump file
# Folder config file
# Recycle Bin used on file shares
# Windows Installer files
# Windows shortcuts
### VisualStudio ###
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
## Get latest from
# User-specific files
# User-specific files (MonoDevelop/Xamarin Studio)
# Build results
# Visual Studio 2015/2017 cache/options directory
# Uncomment if you have tasks that create the project's static files in wwwroot
# Visual Studio 2017 auto generated files
Generated\ Files/
# MSTest test Results
# Build Results of an ATL Project
# Benchmark Results
# .NET Core
# StyleCop
# Files built by Visual Studio
# Chutzpah Test files
# Visual C++ cache files
# Visual Studio profiler
# Visual Studio Trace Files
# TFS 2012 Local Workspace
# Guidance Automation Toolkit
# ReSharper is a .NET coding add-in
# JustCode is a .NET coding add-in
# TeamCity is a build add-in
# DotCover is a Code Coverage Tool
# AxoCover is a Code Coverage Tool
# Visual Studio code coverage results
# NCrunch
# MightyMoose
# Web workbench (sass)
# Installshield output folder
# DocProject is a documentation generator add-in
# Click-Once directory
# Publish Web Output
# Note: Comment the next line if you want to checkin your web deploy settings,
# but database connection strings (with potential passwords) will be unencrypted
# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
# NuGet Packages
# The packages folder can be ignored because of Package Restore
# except build/, which is used as an MSBuild target.
# Uncomment if necessary however generally it will be regenerated when needed
# NuGet v3's project.json files produces more ignorable files
# Microsoft Azure Build Output
# Microsoft Azure Emulator
# Windows Store app package directories and files
# Visual Studio cache files
# files ending in .cache can be ignored
# but keep track of directories ending in .cache
# Others
# Including strong name files can present a security risk
# (
# Since there are multiple workflows, uncomment next line to ignore bower_components
# (
# RIA/Silverlight projects
# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
# SQL Server files
# Business Intelligence projects
# Microsoft Fakes
# GhostDoc plugin setting file
# Node.js Tools for Visual Studio
# Visual Studio 6 build log
# Visual Studio 6 workspace options file
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
# Visual Studio LightSwitch build output
# Paket dependency manager
# FAKE - F# Make
# JetBrains Rider
# CodeRush personal settings
# Python Tools for Visual Studio (PTVS)
# Cake - Uncomment if you are using it
# tools/**
# !tools/packages.config
# Tabs Studio
# Telerik's JustMock configuration file
# BizTalk build output
# OpenCover UI analysis results
# Azure Stream Analytics local run output
# MSBuild Binary and Structured Log
# NVidia Nsight GPU debugger configuration file
# MFractors (Xamarin productivity tool) working folder
# Local History for Visual Studio
# End of,macos,windows,visualstudio,visualstudiocode
\ No newline at end of file
<Project Sdk="Microsoft.NET.Sdk">
<Product>Pushover API</Product>
<Description>Implementation of the API reference</Description>
<Authors>Andreas Müller</Authors>
<Company />
<Copyright>© {copyright:2018-} Andreas Müller</Copyright>
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
<PackageReference Include="Unclassified.NetRevisionTask" Version="0.2.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
namespace AMWD.Net.Push
/// <summary>
/// Implements the API reference of
/// </summary>
public class Pushover : IDisposable
#region Fields
private static readonly string BaseUrl = "";
private static readonly string Version = "1";
private HttpClient client;
private Dictionary<string, string> sounds = new Dictionary<string, string>();
#endregion Fields
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="Pushover"/> class.
/// </summary>
public Pushover()
client = new HttpClient
BaseAddress = new Uri(BaseUrl)
/// <summary>
/// Initializes a new instance of the <see cref="Pushover"/> class.
/// </summary>
/// <param name="appToken">The application token.</param>
/// <param name="userKey">The user key.</param>
public Pushover(string appToken, string userKey)
: this()
AppToken = appToken;
UserKey = userKey;
#endregion Constructors
#region Properties
/// <summary>
/// Gets or sets the application token (Required).
/// </summary>
public string AppToken { get; set; }
/// <summary>
/// Gets or sets the user key (Required).
/// </summary>
public string UserKey { get; set; }
/// <summary>
/// Gets or sets the title of the message (max. 250 chars).
/// </summary>
public string Title { get; set; }
/// <summary>
/// Gets or sets a value that indicates whether the message is HTML encoded.
/// </summary>
public bool IsHtmlMessage { get; set; }
/// <summary>
/// Gets or sets the message (max. 1024 chars).
/// </summary>
public string Message { get; set; }
/// <summary>
/// Gets or sets the retry interval for emergency messages (min. 30 secs).
/// </summary>
public TimeSpan RetryInterval { get; set; } = TimeSpan.FromMinutes(1);
/// <summary>
/// Gets or sets the time unil the emergency message expires (max. 3h).
/// </summary>
public TimeSpan ExpireAfter { get; set; } = TimeSpan.FromMinutes(30);
/// <summary>
/// Gets or sets the callback url.
/// </summary>
/// <remarks>
/// The callback url is triggered by the pushover server if an emergency message is acknoledged.
/// The url has to be available trough the internet.
/// </remarks>
public Uri CallbackUrl { get; set; }
/// <summary>
/// Gets a list of device names to send the message to.
/// </summary>
/// <remarks>
/// It is possible to define the device to which the message should be sent.
/// If the list is empty, all devices are addressed.
/// </remarks>
public IEnumerable<string> DeviceIds { get; set; }
/// <summary>
/// Gets or sets the timestamp of the message (Default: set at <see cref="Send"/> method).
/// </summary>
public DateTime Timestamp { get; set; } = DateTime.UtcNow;
/// <summary>
/// Gets or sets the priority of the message (Default: <see cref="Priorities.Normal"/>).
/// </summary>
public Priorities Priority { get; set; } = Priorities.Normal;
/// <summary>
/// Gets or sets a url sent along with the message (max. 512 chars).
/// </summary>
public string Url { get; set; }
/// <summary>
/// Gets or sets the title of the url sent along with the message (max. 100 chars).
/// </summary>
public string UrlTitle { get; set; }
/// <summary>
/// Gets or sets the sound to notify the user on message arrival.
/// </summary>
public string Sound { get; set; }
/// <summary>
/// Gets or sets an image content.
/// </summary>
public byte[] ImageBytes { get; set; }
/// <summary>
/// Gets or sets the image type, e.g. image/jpeg.
/// </summary>
public string ImageType { get; set; }
/// <summary>
/// Gets a list of all available sounds.
/// </summary>
public Dictionary<string, string> AvailableSounds
if (!sounds.Any())
sounds = GetSounds().Result;
return sounds;
#endregion Properties
#region Public methods
/// <summary>
/// Validates the user's key along with the application's token.
/// </summary>
/// <returns>true if the key is valid, otherwise false.</returns>
public async Task<bool> ValidateKey()
if (isDisposed)
throw new ObjectDisposedException(GetType().FullName);
if (string.IsNullOrWhiteSpace(AppToken))
throw new ArgumentNullException(nameof(AppToken));
if (string.IsNullOrWhiteSpace(UserKey))
throw new ArgumentNullException(nameof(UserKey));
var param = new Dictionary<string, string>
{ "token", AppToken },
{ "user", UserKey }
var response = await Request(RequestMethods.Post, "users/validate.json", param);
return (int)response["status"] == 1;
/// <summary>
/// Sends the message.
/// </summary>
/// <returns>The response parameters.</returns>
public async Task<JObject> Send()
if (isDisposed)
throw new ObjectDisposedException(GetType().FullName);
if (string.IsNullOrWhiteSpace(AppToken))