Skip to content

Commit

Permalink
Merge pull request #18 from jcs/blank_strings
Browse files Browse the repository at this point in the history
Check for empty string values, not just null
  • Loading branch information
indigodomo authored Feb 14, 2018
2 parents d3ac475 + de6c360 commit 8be0436
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Pushover.indigoPlugin/Contents/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<plist version="1.0">
<dict>
<key>PluginVersion</key>
<string>1.2.1</string>
<string>1.2.2</string>
<key>ServerApiVersion</key>
<string>2.0</string>
<key>IwsApiVersion</key>
Expand Down
18 changes: 11 additions & 7 deletions Pushover.indigoPlugin/Contents/Server Plugin/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ def startup(self):
def shutdown(self):
self.debugLog(u"shutdown called")

def present(self, prop):
return (prop and prop.strip() != "")

# helper functions
def prepareTextValue(self, strInput):

Expand Down Expand Up @@ -47,22 +50,22 @@ def send(self, pluginAction):
}

#populate optional parameters
if pluginAction.props['msgDevice'] is not None:
if self.present(pluginAction.props['msgDevice']):
params['device'] = pluginAction.props['msgDevice'].strip()

if pluginAction.props['msgUser'] is not None:
if self.present(pluginAction.props['msgUser']):
params['user'] = pluginAction.props['msgUser'].strip()

if pluginAction.props['msgSound'] is not None:
if self.present(pluginAction.props['msgSound']):
params['sound'] = pluginAction.props["msgSound"].strip()

if pluginAction.props['msgSupLinkTitle'] is not None:
if self.present(pluginAction.props['msgSupLinkTitle']):
params['url_title'] = self.prepareTextValue(pluginAction.props['msgSupLinkTitle'])

if pluginAction.props['msgSupLinkUrl'] is not None:
if self.present(pluginAction.props['msgSupLinkUrl']):
params['url'] = self.prepareTextValue(pluginAction.props['msgSupLinkUrl'])

if pluginAction.props['msgPriority'] is not None:
if self.present(pluginAction.props['msgPriority']):
params['priority'] = pluginAction.props['msgPriority']
if params['priority'] == 2 or params['priority'] == "2":
# Require Confirmation priority requires 2 additional params:
Expand All @@ -72,8 +75,9 @@ def send(self, pluginAction):
conn = httplib.HTTPSConnection("api.pushover.net:443")
conn.request(
"POST",
"/1/messages",
"/1/messages.json",
urllib.urlencode(params),
{"Content-type": "application/x-www-form-urlencoded"}
)
self.debugLog(u"Result: %s" % conn.getresponse().read())
conn.close()

0 comments on commit 8be0436

Please sign in to comment.