From b7804ade9cc181e6351a81f842b64bb0119ecf18 Mon Sep 17 00:00:00 2001 From: Rohan Dhruva Date: Wed, 22 Jan 2014 00:35:44 -0800 Subject: [PATCH] Add support for PushBullet device_iden in addition to device_id --- README.md | 2 +- push.cpp | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 987ee81..2dfe5e6 100644 --- a/README.md +++ b/README.md @@ -233,7 +233,7 @@ to something similar to "http://domain/#channel/2011-03-09 14:25:09", or When using Pushover, this option allows you to specify a single device name to send notifications to; if blank or unset, notifications will be sent to all devices. - This option must be set when using PushBullet. + This option must be set when using PushBullet. This module supports both `device_id` (older, numeric id) and the newer `device_iden` (newer, alphanumeric id) used by PushBullet. You can find your `device_iden` by navigating to a device page and noting the last part of the URL. ### Notifications diff --git a/push.cpp b/push.cpp index 582fb2e..277ebc7 100644 --- a/push.cpp +++ b/push.cpp @@ -196,6 +196,18 @@ class CPushMod : public CModule return result; } + /** + * Verifies whether a given string contains only numbers. + * + * @param content String to verify + */ + bool is_number(const CString& content) + { + CString::const_iterator it = content.begin(); + while(it != content.end() && std::isdigit(*it)) ++it; + return !content.empty() && it == content.end(); + } + /** * Send a message to the currently-configured push service. * Requires (and assumes) that the user has already configured their @@ -267,7 +279,14 @@ class CPushMod : public CModule service_auth = options["secret"] + CString(":"); service_auth.Base64Encode(); - params["device_id"] = options["target"]; + // Pushbullet uses number device_id but they + // are transitioning to an alphanumeric device_iden + if (is_number(options["target"])) + { + params["device_id"] = options["target"]; + } else { + params["device_iden"] = options["target"]; + } params["type"] = "note"; params["title"] = message_title; params["body"] = message_content;