1 #include "stdafx.h"
2 #include "NotificationPushalot.h"
3 #include "../httpclient/HTTPClient.h"
4 #include "../main/Logger.h"
5
CNotificationPushalot()6 CNotificationPushalot::CNotificationPushalot() : CNotificationBase(std::string("pushalot"), OPTIONS_URL_SUBJECT | OPTIONS_URL_BODY | OPTIONS_URL_PARAMS)
7 {
8 SetupConfig(std::string("PushALotEnabled"), &m_IsEnabled);
9 SetupConfig(std::string("PushALotAPI"), _apikey);
10 }
11
~CNotificationPushalot()12 CNotificationPushalot::~CNotificationPushalot()
13 {
14 }
15
SendMessageImplementation(const uint64_t Idx,const std::string & Name,const std::string & Subject,const std::string & Text,const std::string & ExtraData,const int Priority,const std::string & Sound,const bool bFromNotification)16 bool CNotificationPushalot::SendMessageImplementation(
17 const uint64_t Idx,
18 const std::string &Name,
19 const std::string &Subject,
20 const std::string &Text,
21 const std::string &ExtraData,
22 const int Priority,
23 const std::string &Sound,
24 const bool bFromNotification)
25 {
26 //send message to PushAlot
27
28 std::string cSubject = (Subject == Text) ? "Domoticz" : Subject;
29
30 bool bRet;
31 std::stringstream sPostData;
32 std::string IsImportant;
33 std::string IsSilent;
34 std::string sResult;
35
36 // map priority to PushAlot 'IsSilent' & 'IsImportant'
37 switch (Priority) {
38 case -2: // Fall through to -1
39 case -1:
40 IsImportant = "False";
41 IsSilent = "True";
42 break;
43 case 2: // Fall through to 1
44 case 1:
45 IsImportant = "True";
46 IsSilent = "False";
47 break;
48 default:
49 IsImportant = "False";
50 IsSilent = "False";
51 break;
52 }
53
54 sPostData << "AuthorizationToken=" << _apikey << "&IsImportant=" << IsImportant << "&IsSilent=" << IsSilent << "&Source=Domoticz&Title=" << cSubject << "&Body=" << Text;
55 std::vector<std::string> ExtraHeaders;
56 bRet = HTTPClient::POST("https://pushalot.com/api/sendmessage", sPostData.str(), ExtraHeaders, sResult);
57 if (!bRet)
58 _log.Log(LOG_ERROR, "Pushalot: %s", sResult.c_str());
59 return bRet;
60 }
61
IsConfigured()62 bool CNotificationPushalot::IsConfigured()
63 {
64 return _apikey != "";
65 }
66