refactored how plugins inheritied properties

This commit is contained in:
Chris Caron 2018-03-30 22:29:36 -04:00
parent b040e232ae
commit 7e38921835
28 changed files with 170 additions and 162 deletions

View File

@ -99,12 +99,22 @@ class NotifyBase(object):
# us a safe play range... # us a safe play range...
throttle_attempt = 5.5 throttle_attempt = 5.5
# Allows the user to specify the NotifyImageSize object
image_size = None
# The maximum allowable characters allowed in the body per message
body_maxlen = 32768
# Defines the maximum allowable characters in the title
title_maxlen = 250
# Default Notify Format
notify_format = NotifyFormat.TEXT
# Logging # Logging
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
def __init__(self, title_maxlen=100, body_maxlen=512, def __init__(self, **kwargs):
notify_format=NotifyFormat.TEXT, image_size=None,
secure=False, throttle=None, **kwargs):
""" """
Initialize some general logging and common server arguments that will Initialize some general logging and common server arguments that will
keep things consistent when working with the notifiers that will keep things consistent when working with the notifiers that will
@ -112,38 +122,15 @@ class NotifyBase(object):
""" """
if notify_format.lower() not in NOTIFY_FORMATS:
self.logger.error(
'Invalid notification format %s' % notify_format,
)
raise TypeError(
'Invalid notification format %s' % notify_format,
)
if image_size and image_size not in NOTIFY_IMAGE_SIZES:
self.logger.error(
'Invalid image size %s' % image_size,
)
raise TypeError(
'Invalid image size %s' % image_size,
)
# Prepare our Assets # Prepare our Assets
self.asset = AppriseAsset() self.asset = AppriseAsset()
self.notify_format = notify_format.lower()
self.title_maxlen = title_maxlen
self.body_maxlen = body_maxlen
self.image_size = image_size
self.secure = secure
if isinstance(throttle, (float, int)):
# Custom throttle override
self.throttle_attempt = throttle
# Certificate Verification (for SSL calls); default to being enabled # Certificate Verification (for SSL calls); default to being enabled
self.verify_certificate = kwargs.get('verify', True) self.verify_certificate = kwargs.get('verify', True)
# Secure Mode
self.secure = kwargs.get('secure', False)
self.host = kwargs.get('host', '') self.host = kwargs.get('host', '')
self.port = kwargs.get('port') self.port = kwargs.get('port')
if self.port: if self.port:
@ -156,6 +143,19 @@ class NotifyBase(object):
self.user = kwargs.get('user') self.user = kwargs.get('user')
self.password = kwargs.get('password') self.password = kwargs.get('password')
if 'notify_format' in kwargs:
# Store the specified notify_format if specified
notify_format = kwargs.get('notify_format')
if notify_format.lower() not in NOTIFY_FORMATS:
self.logger.error(
'Invalid notification format %s' % notify_format,
)
raise TypeError(
'Invalid notification format %s' % notify_format,
)
# Provide override
self.notify_format = notify_format
def throttle(self, throttle_time=None): def throttle(self, throttle_time=None):
""" """
A common throttle control A common throttle control

View File

@ -57,9 +57,6 @@ VALIDATE_SECRET = re.compile(r'[A-Z0-9_-]{64}', re.I)
# into a usable list. # into a usable list.
TAGS_LIST_DELIM = re.compile(r'[ \t\r\n,\\/]+') TAGS_LIST_DELIM = re.compile(r'[ \t\r\n,\\/]+')
# Image Support (72x72)
BOXCAR_IMAGE_XY = NotifyImageSize.XY_72
class NotifyBoxcar(NotifyBase): class NotifyBoxcar(NotifyBase):
""" """
@ -72,13 +69,17 @@ class NotifyBoxcar(NotifyBase):
# Boxcar URL # Boxcar URL
notify_url = 'https://boxcar-api.io/api/push/' notify_url = 'https://boxcar-api.io/api/push/'
# Allows the user to specify the NotifyImageSize object
image_size = NotifyImageSize.XY_72
# The maximum allowable characters allowed in the body per message
body_maxlen = 10000
def __init__(self, access, secret, recipients=None, **kwargs): def __init__(self, access, secret, recipients=None, **kwargs):
""" """
Initialize Boxcar Object Initialize Boxcar Object
""" """
super(NotifyBoxcar, self).__init__( super(NotifyBoxcar, self).__init__(**kwargs)
title_maxlen=250, body_maxlen=10000,
image_size=BOXCAR_IMAGE_XY, **kwargs)
# Initialize tag list # Initialize tag list
self.tags = list() self.tags = list()

View File

@ -43,9 +43,6 @@ from ..common import NotifyImageSize
from ..common import NotifyFormat from ..common import NotifyFormat
from ..utils import parse_bool from ..utils import parse_bool
# Image Support (256x256)
DISCORD_IMAGE_XY = NotifyImageSize.XY_256
class NotifyDiscord(NotifyBase): class NotifyDiscord(NotifyBase):
""" """
@ -59,17 +56,22 @@ class NotifyDiscord(NotifyBase):
# Discord Webhook # Discord Webhook
notify_url = 'https://discordapp.com/api/webhooks' notify_url = 'https://discordapp.com/api/webhooks'
# Allows the user to specify the NotifyImageSize object
image_size = NotifyImageSize.XY_256
# The maximum allowable characters allowed in the body per message
body_maxlen = 2000
# Default Notify Format
notify_format = NotifyFormat.MARKDOWN
def __init__(self, webhook_id, webhook_token, tts=False, avatar=True, def __init__(self, webhook_id, webhook_token, tts=False, avatar=True,
footer=False, thumbnail=True, footer=False, thumbnail=True, **kwargs):
notify_format=NotifyFormat.MARKDOWN, **kwargs):
""" """
Initialize Discord Object Initialize Discord Object
""" """
super(NotifyDiscord, self).__init__( super(NotifyDiscord, self).__init__(**kwargs)
title_maxlen=250, body_maxlen=2000,
notify_format=notify_format,
image_size=DISCORD_IMAGE_XY, **kwargs)
if not webhook_id: if not webhook_id:
raise TypeError( raise TypeError(

View File

@ -128,14 +128,11 @@ class NotifyEmail(NotifyBase):
# Default SMTP Timeout (in seconds) # Default SMTP Timeout (in seconds)
connect_timeout = 15 connect_timeout = 15
def __init__(self, to, notify_format, **kwargs): def __init__(self, to, **kwargs):
""" """
Initialize Email Object Initialize Email Object
""" """
super(NotifyEmail, self).__init__( super(NotifyEmail, self).__init__(**kwargs)
title_maxlen=250, body_maxlen=32768,
notify_format=notify_format,
**kwargs)
# Store To Addr # Store To Addr
self.to_addr = to self.to_addr = to

View File

@ -62,8 +62,7 @@ class NotifyEmby(NotifyBase):
Initialize Emby Object Initialize Emby Object
""" """
super(NotifyEmby, self).__init__( super(NotifyEmby, self).__init__(**kwargs)
title_maxlen=250, body_maxlen=32768, **kwargs)
if self.secure: if self.secure:
self.schema = 'https' self.schema = 'https'

View File

@ -2,7 +2,7 @@
# #
# Faast Notify Wrapper # Faast Notify Wrapper
# #
# Copyright (C) 2017 Chris Caron <lead2gold@gmail.com> # Copyright (C) 2017-2018 Chris Caron <lead2gold@gmail.com>
# #
# This file is part of apprise. # This file is part of apprise.
# #
@ -22,9 +22,6 @@ from .NotifyBase import NotifyBase
from .NotifyBase import HTTP_ERROR_MAP from .NotifyBase import HTTP_ERROR_MAP
from ..common import NotifyImageSize from ..common import NotifyImageSize
# Image Support (72x72)
FAAST_IMAGE_XY = NotifyImageSize.XY_72
class NotifyFaast(NotifyBase): class NotifyFaast(NotifyBase):
""" """
@ -37,13 +34,14 @@ class NotifyFaast(NotifyBase):
# Faast uses the http protocol with JSON requests # Faast uses the http protocol with JSON requests
notify_url = 'https://www.appnotifications.com/account/notifications.json' notify_url = 'https://www.appnotifications.com/account/notifications.json'
# Allows the user to specify the NotifyImageSize object
image_size = NotifyImageSize.XY_72
def __init__(self, authtoken, **kwargs): def __init__(self, authtoken, **kwargs):
""" """
Initialize Faast Object Initialize Faast Object
""" """
super(NotifyFaast, self).__init__( super(NotifyFaast, self).__init__(**kwargs)
title_maxlen=250, body_maxlen=32768, image_size=FAAST_IMAGE_XY,
**kwargs)
self.authtoken = authtoken self.authtoken = authtoken

View File

@ -23,9 +23,6 @@ from .gntp import errors
from ..NotifyBase import NotifyBase from ..NotifyBase import NotifyBase
from ...common import NotifyImageSize from ...common import NotifyImageSize
# Image Support (72x72)
GROWL_IMAGE_XY = NotifyImageSize.XY_72
# Priorities # Priorities
class GrowlPriority(object): class GrowlPriority(object):
@ -59,13 +56,14 @@ class NotifyGrowl(NotifyBase):
# Default Growl Port # Default Growl Port
default_port = 23053 default_port = 23053
# Allows the user to specify the NotifyImageSize object
image_size = NotifyImageSize.XY_72
def __init__(self, priority=None, version=2, **kwargs): def __init__(self, priority=None, version=2, **kwargs):
""" """
Initialize Growl Object Initialize Growl Object
""" """
super(NotifyGrowl, self).__init__( super(NotifyGrowl, self).__init__(**kwargs)
title_maxlen=250, body_maxlen=32768,
image_size=GROWL_IMAGE_XY, **kwargs)
if not self.port: if not self.port:
self.port = self.default_port self.port = self.default_port

View File

@ -76,8 +76,7 @@ class NotifyIFTTT(NotifyBase):
Initialize IFTTT Object Initialize IFTTT Object
""" """
super(NotifyIFTTT, self).__init__( super(NotifyIFTTT, self).__init__(**kwargs)
title_maxlen=250, body_maxlen=32768, **kwargs)
if not apikey: if not apikey:
raise TypeError('You must specify the Webhooks apikey.') raise TypeError('You must specify the Webhooks apikey.')

View File

@ -24,9 +24,6 @@ from .NotifyBase import HTTP_ERROR_MAP
from ..common import NotifyImageSize from ..common import NotifyImageSize
from ..utils import compat_is_basestring from ..utils import compat_is_basestring
# Image Support (128x128)
JSON_IMAGE_XY = NotifyImageSize.XY_128
class NotifyJSON(NotifyBase): class NotifyJSON(NotifyBase):
""" """
@ -39,13 +36,14 @@ class NotifyJSON(NotifyBase):
# The default secure protocol # The default secure protocol
secure_protocol = 'jsons' secure_protocol = 'jsons'
# Allows the user to specify the NotifyImageSize object
image_size = NotifyImageSize.XY_128
def __init__(self, **kwargs): def __init__(self, **kwargs):
""" """
Initialize JSON Object Initialize JSON Object
""" """
super(NotifyJSON, self).__init__( super(NotifyJSON, self).__init__(**kwargs)
title_maxlen=250, body_maxlen=32768, image_size=JSON_IMAGE_XY,
**kwargs)
if self.secure: if self.secure:
self.schema = 'https' self.schema = 'https'

View File

@ -71,13 +71,17 @@ class NotifyJoin(NotifyBase):
notify_url = \ notify_url = \
'https://joinjoaomgcd.appspot.com/_ah/api/messaging/v1/sendPush' 'https://joinjoaomgcd.appspot.com/_ah/api/messaging/v1/sendPush'
# Allows the user to specify the NotifyImageSize object
image_size = NotifyImageSize.XY_72
# The maximum allowable characters allowed in the body per message
body_maxlen = 1000
def __init__(self, apikey, devices, **kwargs): def __init__(self, apikey, devices, **kwargs):
""" """
Initialize Join Object Initialize Join Object
""" """
super(NotifyJoin, self).__init__( super(NotifyJoin, self).__init__(**kwargs)
title_maxlen=250, body_maxlen=1000, image_size=JOIN_IMAGE_XY,
**kwargs)
if not VALIDATE_APIKEY.match(apikey.strip()): if not VALIDATE_APIKEY.match(apikey.strip()):
self.logger.warning( self.logger.warning(

View File

@ -2,7 +2,7 @@
# #
# MatterMost Notify Wrapper # MatterMost Notify Wrapper
# #
# Copyright (C) 2017 Chris Caron <lead2gold@gmail.com> # Copyright (C) 2017-2018 Chris Caron <lead2gold@gmail.com>
# #
# This file is part of apprise. # This file is part of apprise.
# #
@ -31,9 +31,6 @@ from ..common import NotifyImageSize
# Used to validate Authorization Token # Used to validate Authorization Token
VALIDATE_AUTHTOKEN = re.compile(r'[A-Za-z0-9]{24,32}') VALIDATE_AUTHTOKEN = re.compile(r'[A-Za-z0-9]{24,32}')
# Image Support (72x72)
MATTERMOST_IMAGE_XY = NotifyImageSize.XY_72
class NotifyMatterMost(NotifyBase): class NotifyMatterMost(NotifyBase):
""" """
@ -49,13 +46,17 @@ class NotifyMatterMost(NotifyBase):
# The default Mattermost port # The default Mattermost port
default_port = 8065 default_port = 8065
# Allows the user to specify the NotifyImageSize object
image_size = NotifyImageSize.XY_72
# The maximum allowable characters allowed in the body per message
body_maxlen = 4000
def __init__(self, authtoken, channel=None, **kwargs): def __init__(self, authtoken, channel=None, **kwargs):
""" """
Initialize MatterMost Object Initialize MatterMost Object
""" """
super(NotifyMatterMost, self).__init__( super(NotifyMatterMost, self).__init__(**kwargs)
title_maxlen=250, body_maxlen=4000, image_size=MATTERMOST_IMAGE_XY,
**kwargs)
if self.secure: if self.secure:
self.schema = 'https' self.schema = 'https'

View File

@ -2,7 +2,7 @@
# #
# Notify My Android (NMA) Notify Wrapper # Notify My Android (NMA) Notify Wrapper
# #
# Copyright (C) 2017 Chris Caron <lead2gold@gmail.com> # Copyright (C) 2017-2018 Chris Caron <lead2gold@gmail.com>
# #
# This file is part of apprise. # This file is part of apprise.
# #
@ -64,12 +64,17 @@ class NotifyMyAndroid(NotifyBase):
# Notify My Android uses the http protocol with JSON requests # Notify My Android uses the http protocol with JSON requests
notify_url = 'https://www.notifymyandroid.com/publicapi/notify' notify_url = 'https://www.notifymyandroid.com/publicapi/notify'
# The maximum allowable characters allowed in the body per message
body_maxlen = 10000
# Defines the maximum allowable characters in the title
title_maxlen = 1000
def __init__(self, apikey, priority=None, devapikey=None, **kwargs): def __init__(self, apikey, priority=None, devapikey=None, **kwargs):
""" """
Initialize Notify My Android Object Initialize Notify My Android Object
""" """
super(NotifyMyAndroid, self).__init__( super(NotifyMyAndroid, self).__init__(**kwargs)
title_maxlen=1000, body_maxlen=10000, **kwargs)
# The Priority of the message # The Priority of the message
if priority not in NMA_PRIORITIES: if priority not in NMA_PRIORITIES:

View File

@ -2,7 +2,7 @@
# #
# Prowl Notify Wrapper # Prowl Notify Wrapper
# #
# Copyright (C) 2017 Chris Caron <lead2gold@gmail.com> # Copyright (C) 2017-2018 Chris Caron <lead2gold@gmail.com>
# #
# This file is part of apprise. # This file is part of apprise.
# #
@ -65,12 +65,17 @@ class NotifyProwl(NotifyBase):
# Prowl uses the http protocol with JSON requests # Prowl uses the http protocol with JSON requests
notify_url = 'https://api.prowlapp.com/publicapi/add' notify_url = 'https://api.prowlapp.com/publicapi/add'
# The maximum allowable characters allowed in the body per message
body_maxlen = 10000
# Defines the maximum allowable characters in the title
title_maxlen = 1024
def __init__(self, apikey, providerkey=None, priority=None, **kwargs): def __init__(self, apikey, providerkey=None, priority=None, **kwargs):
""" """
Initialize Prowl Object Initialize Prowl Object
""" """
super(NotifyProwl, self).__init__( super(NotifyProwl, self).__init__(**kwargs)
title_maxlen=1024, body_maxlen=10000, **kwargs)
if priority not in PROWL_PRIORITIES: if priority not in PROWL_PRIORITIES:
self.priority = ProwlPriority.NORMAL self.priority = ProwlPriority.NORMAL

View File

@ -2,7 +2,7 @@
# #
# PushBullet Notify Wrapper # PushBullet Notify Wrapper
# #
# Copyright (C) 2017 Chris Caron <lead2gold@gmail.com> # Copyright (C) 2017-2018 Chris Caron <lead2gold@gmail.com>
# #
# This file is part of apprise. # This file is part of apprise.
# #
@ -55,8 +55,7 @@ class NotifyPushBullet(NotifyBase):
""" """
Initialize PushBullet Object Initialize PushBullet Object
""" """
super(NotifyPushBullet, self).__init__( super(NotifyPushBullet, self).__init__(**kwargs)
title_maxlen=250, body_maxlen=32768, **kwargs)
self.accesstoken = accesstoken self.accesstoken = accesstoken
if compat_is_basestring(recipients): if compat_is_basestring(recipients):

View File

@ -2,7 +2,7 @@
# #
# Pushalot Notify Wrapper # Pushalot Notify Wrapper
# #
# Copyright (C) 2017 Chris Caron <lead2gold@gmail.com> # Copyright (C) 2017-2018 Chris Caron <lead2gold@gmail.com>
# #
# This file is part of apprise. # This file is part of apprise.
# #
@ -24,9 +24,6 @@ from .NotifyBase import NotifyBase
from .NotifyBase import HTTP_ERROR_MAP from .NotifyBase import HTTP_ERROR_MAP
from ..common import NotifyImageSize from ..common import NotifyImageSize
# Image Support (72x72)
PUSHALOT_IMAGE_XY = NotifyImageSize.XY_72
# Extend HTTP Error Messages # Extend HTTP Error Messages
PUSHALOT_HTTP_ERROR_MAP = HTTP_ERROR_MAP.copy() PUSHALOT_HTTP_ERROR_MAP = HTTP_ERROR_MAP.copy()
PUSHALOT_HTTP_ERROR_MAP.update({ PUSHALOT_HTTP_ERROR_MAP.update({
@ -49,13 +46,14 @@ class NotifyPushalot(NotifyBase):
# Pushalot uses the http protocol with JSON requests # Pushalot uses the http protocol with JSON requests
notify_url = 'https://pushalot.com/api/sendmessage' notify_url = 'https://pushalot.com/api/sendmessage'
# Allows the user to specify the NotifyImageSize object
image_size = NotifyImageSize.XY_72
def __init__(self, authtoken, is_important=False, **kwargs): def __init__(self, authtoken, is_important=False, **kwargs):
""" """
Initialize Pushalot Object Initialize Pushalot Object
""" """
super(NotifyPushalot, self).__init__( super(NotifyPushalot, self).__init__(**kwargs)
title_maxlen=250, body_maxlen=32768,
image_size=PUSHALOT_IMAGE_XY, **kwargs)
# Is Important Flag # Is Important Flag
self.is_important = is_important self.is_important = is_important

View File

@ -42,8 +42,7 @@ class NotifyPushjet(NotifyBase):
""" """
Initialize Pushjet Object Initialize Pushjet Object
""" """
super(NotifyPushjet, self).__init__( super(NotifyPushjet, self).__init__(**kwargs)
title_maxlen=250, body_maxlen=32768, **kwargs)
def notify(self, title, body, notify_type): def notify(self, title, body, notify_type):
""" """

View File

@ -74,12 +74,14 @@ class NotifyPushover(NotifyBase):
# Pushover uses the http protocol with JSON requests # Pushover uses the http protocol with JSON requests
notify_url = 'https://api.pushover.net/1/messages.json' notify_url = 'https://api.pushover.net/1/messages.json'
# The maximum allowable characters allowed in the body per message
body_maxlen = 512
def __init__(self, token, devices=None, priority=None, **kwargs): def __init__(self, token, devices=None, priority=None, **kwargs):
""" """
Initialize Pushover Object Initialize Pushover Object
""" """
super(NotifyPushover, self).__init__( super(NotifyPushover, self).__init__(**kwargs)
title_maxlen=250, body_maxlen=512, **kwargs)
try: try:
# The token associated with the account # The token associated with the account

View File

@ -2,7 +2,7 @@
# #
# Notify Rocket.Chat Notify Wrapper # Notify Rocket.Chat Notify Wrapper
# #
# Copyright (C) 2017 Chris Caron <lead2gold@gmail.com> # Copyright (C) 2017-2018 Chris Caron <lead2gold@gmail.com>
# #
# This file is part of apprise. # This file is part of apprise.
# #
@ -50,12 +50,14 @@ class NotifyRocketChat(NotifyBase):
# The default secure protocol # The default secure protocol
secure_protocol = 'rockets' secure_protocol = 'rockets'
# Defines the maximum allowable characters in the title
title_maxlen = 200
def __init__(self, recipients=None, **kwargs): def __init__(self, recipients=None, **kwargs):
""" """
Initialize Notify Rocket.Chat Object Initialize Notify Rocket.Chat Object
""" """
super(NotifyRocketChat, self).__init__( super(NotifyRocketChat, self).__init__(**kwargs)
title_maxlen=200, body_maxlen=32768, **kwargs)
if self.secure: if self.secure:
self.schema = 'https' self.schema = 'https'

View File

@ -65,9 +65,6 @@ CHANNEL_LIST_DELIM = re.compile(r'[ \t\r\n,#\\/]+')
# Used to detect a channel # Used to detect a channel
IS_CHANNEL_RE = re.compile(r'[+#@]?([A-Z0-9_]{1,32})', re.I) IS_CHANNEL_RE = re.compile(r'[+#@]?([A-Z0-9_]{1,32})', re.I)
# Image Support (72x72)
SLACK_IMAGE_XY = NotifyImageSize.XY_72
class NotifySlack(NotifyBase): class NotifySlack(NotifyBase):
""" """
@ -80,13 +77,17 @@ class NotifySlack(NotifyBase):
# Slack uses the http protocol with JSON requests # Slack uses the http protocol with JSON requests
notify_url = 'https://hooks.slack.com/services' notify_url = 'https://hooks.slack.com/services'
# Allows the user to specify the NotifyImageSize object
image_size = NotifyImageSize.XY_72
# The maximum allowable characters allowed in the body per message
body_maxlen = 1000
def __init__(self, token_a, token_b, token_c, channels, **kwargs): def __init__(self, token_a, token_b, token_c, channels, **kwargs):
""" """
Initialize Slack Object Initialize Slack Object
""" """
super(NotifySlack, self).__init__( super(NotifySlack, self).__init__(**kwargs)
title_maxlen=250, body_maxlen=1000,
image_size=SLACK_IMAGE_XY, **kwargs)
if not VALIDATE_TOKEN_A.match(token_a.strip()): if not VALIDATE_TOKEN_A.match(token_a.strip()):
self.logger.warning( self.logger.warning(

View File

@ -50,9 +50,6 @@ from .NotifyBase import NotifyBase
from .NotifyBase import HTTP_ERROR_MAP from .NotifyBase import HTTP_ERROR_MAP
from ..common import NotifyImageSize from ..common import NotifyImageSize
# Image Support (256x256)
STRIDE_IMAGE_XY = NotifyImageSize.XY_256
# A Simple UUID4 checker # A Simple UUID4 checker
IS_VALID_TOKEN = re.compile( IS_VALID_TOKEN = re.compile(
r'([0-9a-f]{8})-*([0-9a-f]{4})-*(4[0-9a-f]{3})-*' r'([0-9a-f]{8})-*([0-9a-f]{4})-*(4[0-9a-f]{3})-*'
@ -72,14 +69,18 @@ class NotifyStride(NotifyBase):
notify_url = 'https://api.atlassian.com/site/{cloud_id}/' \ notify_url = 'https://api.atlassian.com/site/{cloud_id}/' \
'conversation/{convo_id}/message' 'conversation/{convo_id}/message'
# Allows the user to specify the NotifyImageSize object
image_size = NotifyImageSize.XY_256
# The maximum allowable characters allowed in the body per message
body_maxlen = 2000
def __init__(self, auth_token, cloud_id, convo_id, **kwargs): def __init__(self, auth_token, cloud_id, convo_id, **kwargs):
""" """
Initialize Stride Object Initialize Stride Object
""" """
super(NotifyStride, self).__init__( super(NotifyStride, self).__init__(**kwargs)
title_maxlen=250, body_maxlen=2000,
image_size=STRIDE_IMAGE_XY, **kwargs)
if not auth_token: if not auth_token:
raise TypeError( raise TypeError(

View File

@ -53,7 +53,6 @@ from json import dumps
from .NotifyBase import NotifyBase from .NotifyBase import NotifyBase
from .NotifyBase import HTTP_ERROR_MAP from .NotifyBase import HTTP_ERROR_MAP
from ..common import NotifyImageSize from ..common import NotifyImageSize
from ..common import NotifyFormat
from ..utils import compat_is_basestring from ..utils import compat_is_basestring
from ..utils import parse_bool from ..utils import parse_bool
@ -89,15 +88,18 @@ class NotifyTelegram(NotifyBase):
# Telegram uses the http protocol with JSON requests # Telegram uses the http protocol with JSON requests
notify_url = 'https://api.telegram.org/bot' notify_url = 'https://api.telegram.org/bot'
def __init__(self, bot_token, chat_ids, notify_format=NotifyFormat.TEXT, # Allows the user to specify the NotifyImageSize object
detect_bot_owner=True, include_image=True, **kwargs): image_size = NotifyImageSize.XY_256
# The maximum allowable characters allowed in the body per message
body_maxlen = 4096
def __init__(self, bot_token, chat_ids, detect_bot_owner=True,
include_image=True, **kwargs):
""" """
Initialize Telegram Object Initialize Telegram Object
""" """
super(NotifyTelegram, self).__init__( super(NotifyTelegram, self).__init__(**kwargs)
title_maxlen=250, body_maxlen=4096,
notify_format=notify_format,
image_size=TELEGRAM_IMAGE_XY, **kwargs)
try: try:
self.bot_token = bot_token.strip() self.bot_token = bot_token.strip()

View File

@ -24,9 +24,6 @@ from .NotifyBase import HTTP_ERROR_MAP
from ..common import NotifyImageSize from ..common import NotifyImageSize
from ..utils import compat_is_basestring from ..utils import compat_is_basestring
# Image Support (128x128)
TOASTY_IMAGE_XY = NotifyImageSize.XY_128
# Used to break apart list of potential devices by their delimiter # Used to break apart list of potential devices by their delimiter
# into a usable list. # into a usable list.
DEVICES_LIST_DELIM = re.compile(r'[ \t\r\n,\\/]+') DEVICES_LIST_DELIM = re.compile(r'[ \t\r\n,\\/]+')
@ -43,13 +40,14 @@ class NotifyToasty(NotifyBase):
# Toasty uses the http protocol with JSON requests # Toasty uses the http protocol with JSON requests
notify_url = 'http://api.supertoasty.com/notify/' notify_url = 'http://api.supertoasty.com/notify/'
# Allows the user to specify the NotifyImageSize object
image_size = NotifyImageSize.XY_128
def __init__(self, devices, **kwargs): def __init__(self, devices, **kwargs):
""" """
Initialize Toasty Object Initialize Toasty Object
""" """
super(NotifyToasty, self).__init__( super(NotifyToasty, self).__init__(**kwargs)
title_maxlen=250, body_maxlen=32768, image_size=TOASTY_IMAGE_XY,
**kwargs)
if compat_is_basestring(devices): if compat_is_basestring(devices):
self.devices = [x for x in filter(bool, DEVICES_LIST_DELIM.split( self.devices = [x for x in filter(bool, DEVICES_LIST_DELIM.split(

View File

@ -19,9 +19,6 @@
from . import tweepy from . import tweepy
from ..NotifyBase import NotifyBase from ..NotifyBase import NotifyBase
# Direct Messages have not image support
TWITTER_IMAGE_XY = None
class NotifyTwitter(NotifyBase): class NotifyTwitter(NotifyBase):
""" """
@ -32,16 +29,17 @@ class NotifyTwitter(NotifyBase):
# The default secure protocol # The default secure protocol
secure_protocol = 'tweet' secure_protocol = 'tweet'
# The maximum allowable characters allowed in the body per message
# This is used during a Private DM Message Size (not Public Tweets
# which are limited to 240 characters)
body_maxlen = 4096
def __init__(self, ckey, csecret, akey, asecret, **kwargs): def __init__(self, ckey, csecret, akey, asecret, **kwargs):
""" """
Initialize Twitter Object Initialize Twitter Object
Tweets are restriced to 140 (soon to be 240), but DM messages
do not have any restriction on them
""" """
super(NotifyTwitter, self).__init__( super(NotifyTwitter, self).__init__(**kwargs)
title_maxlen=250, body_maxlen=4096,
image_size=TWITTER_IMAGE_XY, **kwargs)
if not ckey: if not ckey:
raise TypeError( raise TypeError(

View File

@ -25,9 +25,6 @@ from .NotifyBase import HTTP_ERROR_MAP
from ..common import NotifyType from ..common import NotifyType
from ..common import NotifyImageSize from ..common import NotifyImageSize
# Image Support (128x128)
XBMC_IMAGE_XY = NotifyImageSize.XY_128
class NotifyXBMC(NotifyBase): class NotifyXBMC(NotifyBase):
""" """
@ -43,6 +40,9 @@ class NotifyXBMC(NotifyBase):
# XBMC uses the http protocol with JSON requests # XBMC uses the http protocol with JSON requests
xbmc_default_port = 8080 xbmc_default_port = 8080
# Allows the user to specify the NotifyImageSize object
image_size = NotifyImageSize.XY_128
# XBMC default protocol version (v2) # XBMC default protocol version (v2)
xbmc_remote_protocol = 2 xbmc_remote_protocol = 2
@ -53,9 +53,7 @@ class NotifyXBMC(NotifyBase):
""" """
Initialize XBMC/KODI Object Initialize XBMC/KODI Object
""" """
super(NotifyXBMC, self).__init__( super(NotifyXBMC, self).__init__(**kwargs)
title_maxlen=250, body_maxlen=32768,
image_size=XBMC_IMAGE_XY, **kwargs)
if self.secure: if self.secure:
self.schema = 'https' self.schema = 'https'

View File

@ -24,9 +24,6 @@ from .NotifyBase import HTTP_ERROR_MAP
from ..common import NotifyImageSize from ..common import NotifyImageSize
from ..utils import compat_is_basestring from ..utils import compat_is_basestring
# Image Support (128x128)
XML_IMAGE_XY = NotifyImageSize.XY_128
class NotifyXML(NotifyBase): class NotifyXML(NotifyBase):
""" """
@ -39,13 +36,14 @@ class NotifyXML(NotifyBase):
# The default secure protocol # The default secure protocol
secure_protocol = 'xmls' secure_protocol = 'xmls'
# Allows the user to specify the NotifyImageSize object
image_size = NotifyImageSize.XY_128
def __init__(self, **kwargs): def __init__(self, **kwargs):
""" """
Initialize XML Object Initialize XML Object
""" """
super(NotifyXML, self).__init__( super(NotifyXML, self).__init__(**kwargs)
title_maxlen=250, body_maxlen=32768,
image_size=XML_IMAGE_XY, **kwargs)
self.payload = """<?xml version='1.0' encoding='utf-8'?> self.payload = """<?xml version='1.0' encoding='utf-8'?>
<soapenv:Envelope <soapenv:Envelope

View File

@ -423,6 +423,7 @@ def test_apprise_asset(tmpdir):
# Disable all image references # Disable all image references
a = AppriseAsset(image_path_mask=False, image_url_mask=False) a = AppriseAsset(image_path_mask=False, image_url_mask=False)
# We always return none in these calls now # We always return none in these calls now
assert(a.image_raw(NotifyType.INFO, NotifyImageSize.XY_256) is None) assert(a.image_raw(NotifyType.INFO, NotifyImageSize.XY_256) is None)
assert(a.image_url(NotifyType.INFO, NotifyImageSize.XY_256) is None) assert(a.image_url(NotifyType.INFO, NotifyImageSize.XY_256) is None)

View File

@ -2,7 +2,7 @@
# #
# NotifyBase Unit Tests # NotifyBase Unit Tests
# #
# Copyright (C) 2017 Chris Caron <lead2gold@gmail.com> # Copyright (C) 2017-2018 Chris Caron <lead2gold@gmail.com>
# #
# This file is part of apprise. # This file is part of apprise.
# #
@ -38,14 +38,6 @@ def test_notify_base():
except TypeError: except TypeError:
assert(True) assert(True)
try:
nb = NotifyBase(image_size='invalid')
# We should never reach here as an exception should be thrown
assert(False)
except TypeError:
assert(True)
# Bad port information # Bad port information
nb = NotifyBase(port='invalid') nb = NotifyBase(port='invalid')
assert nb.port is None assert nb.port is None
@ -54,7 +46,8 @@ def test_notify_base():
assert nb.port == 10 assert nb.port == 10
# Throttle overrides.. # Throttle overrides..
nb = NotifyBase(throttle=0) nb = NotifyBase()
nb.throttle_attempt = 0.0
start_time = default_timer() start_time = default_timer()
nb.throttle() nb.throttle()
elapsed = default_timer() - start_time elapsed = default_timer() - start_time
@ -85,8 +78,10 @@ def test_notify_base():
assert isinstance( assert isinstance(
nb.color(notify_type=NotifyType.INFO, color_type=tuple), tuple) nb.color(notify_type=NotifyType.INFO, color_type=tuple), tuple)
# Create an object with an ImageSize loaded into it # Create an object
nb = NotifyBase(image_size=NotifyImageSize.XY_256) nb = NotifyBase()
# Force an image size since the default doesn't have one
nb.image_size = NotifyImageSize.XY_256
# We'll get an object this time around # We'll get an object this time around
assert nb.image_url(notify_type=NotifyType.INFO) is not None assert nb.image_url(notify_type=NotifyType.INFO) is not None

View File

@ -2594,6 +2594,15 @@ def test_notify_telegram_plugin(mock_post, mock_get):
nimg_obj.throttle_attempt = 0 nimg_obj.throttle_attempt = 0
obj.throttle_attempt = 0 obj.throttle_attempt = 0
# Test that our default settings over-ride base settings since they are
# not the same as the one specified in the base; this check merely
# ensures our plugin inheritance is working properly
assert obj.body_maxlen == plugins.NotifyTelegram.body_maxlen
# We don't override the title maxlen so we should be set to the same
# as our parent class in this case
assert obj.title_maxlen == plugins.NotifyBase.NotifyBase.title_maxlen
# This tests erroneous messages involving multiple chat ids # This tests erroneous messages involving multiple chat ids
assert obj.notify( assert obj.notify(
title='title', body='body', notify_type=NotifyType.INFO) is False title='title', body='body', notify_type=NotifyType.INFO) is False