forked from platypush/platypush
Fixes
This commit is contained in:
parent
952a8f2faf
commit
dc2b3689a2
2 changed files with 14 additions and 12 deletions
|
@ -14,8 +14,8 @@ class PingBackend(Backend):
|
||||||
|
|
||||||
Triggers:
|
Triggers:
|
||||||
|
|
||||||
- :class:`platypush.message.ping.HostDownEvent` if a host stops responding ping requests
|
- :class:`platypush.message.event.ping.HostDownEvent` if a host stops responding ping requests
|
||||||
- :class:`platypush.message.ping.HostUpEvent` if a host starts responding ping requests
|
- :class:`platypush.message.event.ping.HostUpEvent` if a host starts responding ping requests
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
from platypush.message import Message
|
|
||||||
from platypush.plugins import Plugin, action
|
from platypush.plugins import Plugin, action
|
||||||
|
|
||||||
|
|
||||||
class IftttPlugin(Plugin):
|
class IftttPlugin(Plugin):
|
||||||
"""
|
"""
|
||||||
This plugin allows you to interact with the IFTTT maker API
|
This plugin allows you to interact with the IFTTT maker API
|
||||||
|
@ -30,16 +30,17 @@ class IftttPlugin(Plugin):
|
||||||
|
|
||||||
_base_url = 'https://maker.ifttt.com/trigger/{event_name}/with/key/{ifttt_key}'
|
_base_url = 'https://maker.ifttt.com/trigger/{event_name}/with/key/{ifttt_key}'
|
||||||
|
|
||||||
def __init__(self, ifttt_key, *args, **kwargs):
|
def __init__(self, ifttt_key, **kwargs):
|
||||||
"""
|
"""
|
||||||
:param ifttt_key: Your IFTTT Maker API key. Log in to IFTTT and get your key from <https://ifttt.com/maker_webhooks>. Once you've got your key, you can start creating IFTTT rules using the Webhooks channel.
|
:param ifttt_key: Your IFTTT Maker API key. Log in to IFTTT and get your key from
|
||||||
|
`here <https://ifttt.com/maker_webhooks>`_. Once you've got your key, you can start creating IFTTT rules
|
||||||
|
using the Webhooks channel.
|
||||||
:type ifttt_key: str
|
:type ifttt_key: str
|
||||||
"""
|
"""
|
||||||
|
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(**kwargs)
|
||||||
self.ifttt_key = ifttt_key
|
self.ifttt_key = ifttt_key
|
||||||
|
|
||||||
|
|
||||||
@action
|
@action
|
||||||
def trigger_event(self, event_name, values=None):
|
def trigger_event(self, event_name, values=None):
|
||||||
"""
|
"""
|
||||||
|
@ -48,7 +49,8 @@ class IftttPlugin(Plugin):
|
||||||
:param event_name: Name of the event
|
:param event_name: Name of the event
|
||||||
:type event_name: str
|
:type event_name: str
|
||||||
|
|
||||||
:param values: Optional list of values to be passed to the event. By convention IFTTT names the values as ``value1,value2,...``.
|
:param values: Optional list of values to be passed to the event. By convention IFTTT names the values as
|
||||||
|
``value1,value2,...``.
|
||||||
:type values: list
|
:type values: list
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -56,12 +58,12 @@ class IftttPlugin(Plugin):
|
||||||
if not values:
|
if not values:
|
||||||
values = []
|
values = []
|
||||||
|
|
||||||
response = requests.post(url, json={'value{}'.format(i+1): v
|
response = requests.post(url, json={'value{}'.format(i + 1): v
|
||||||
for (i,v) in enumerate(values)})
|
for (i, v) in enumerate(values)})
|
||||||
|
|
||||||
if not response.ok:
|
if not response.ok:
|
||||||
raise RuntimeError("IFTTT event '{}' error: {}: {}".format(event_name, r.status_code, r.reason))
|
raise RuntimeError("IFTTT event '{}' error: {}: {}".format(
|
||||||
|
event_name, response.status_code, response.reason))
|
||||||
|
|
||||||
|
|
||||||
# vim:sw=4:ts=4:et:
|
# vim:sw=4:ts=4:et:
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue