diff --git a/apprise/plugins/NotifyBase.py b/apprise/plugins/NotifyBase.py index 8c9116ec..bcf811a9 100644 --- a/apprise/plugins/NotifyBase.py +++ b/apprise/plugins/NotifyBase.py @@ -99,12 +99,22 @@ class NotifyBase(object): # us a safe play range... 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 logger = logging.getLogger(__name__) - def __init__(self, title_maxlen=100, body_maxlen=512, - notify_format=NotifyFormat.TEXT, image_size=None, - secure=False, throttle=None, **kwargs): + def __init__(self, **kwargs): """ Initialize some general logging and common server arguments 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 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 self.verify_certificate = kwargs.get('verify', True) + # Secure Mode + self.secure = kwargs.get('secure', False) + self.host = kwargs.get('host', '') self.port = kwargs.get('port') if self.port: @@ -156,6 +143,19 @@ class NotifyBase(object): self.user = kwargs.get('user') 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): """ A common throttle control diff --git a/apprise/plugins/NotifyBoxcar.py b/apprise/plugins/NotifyBoxcar.py index 1cc4435c..2d35d119 100644 --- a/apprise/plugins/NotifyBoxcar.py +++ b/apprise/plugins/NotifyBoxcar.py @@ -57,9 +57,6 @@ VALIDATE_SECRET = re.compile(r'[A-Z0-9_-]{64}', re.I) # into a usable list. TAGS_LIST_DELIM = re.compile(r'[ \t\r\n,\\/]+') -# Image Support (72x72) -BOXCAR_IMAGE_XY = NotifyImageSize.XY_72 - class NotifyBoxcar(NotifyBase): """ @@ -72,13 +69,17 @@ class NotifyBoxcar(NotifyBase): # Boxcar URL 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): """ Initialize Boxcar Object """ - super(NotifyBoxcar, self).__init__( - title_maxlen=250, body_maxlen=10000, - image_size=BOXCAR_IMAGE_XY, **kwargs) + super(NotifyBoxcar, self).__init__(**kwargs) # Initialize tag list self.tags = list() diff --git a/apprise/plugins/NotifyDiscord.py b/apprise/plugins/NotifyDiscord.py index e500d930..b97e6ff6 100644 --- a/apprise/plugins/NotifyDiscord.py +++ b/apprise/plugins/NotifyDiscord.py @@ -43,9 +43,6 @@ from ..common import NotifyImageSize from ..common import NotifyFormat from ..utils import parse_bool -# Image Support (256x256) -DISCORD_IMAGE_XY = NotifyImageSize.XY_256 - class NotifyDiscord(NotifyBase): """ @@ -59,17 +56,22 @@ class NotifyDiscord(NotifyBase): # Discord Webhook 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, - footer=False, thumbnail=True, - notify_format=NotifyFormat.MARKDOWN, **kwargs): + footer=False, thumbnail=True, **kwargs): """ Initialize Discord Object """ - super(NotifyDiscord, self).__init__( - title_maxlen=250, body_maxlen=2000, - notify_format=notify_format, - image_size=DISCORD_IMAGE_XY, **kwargs) + super(NotifyDiscord, self).__init__(**kwargs) if not webhook_id: raise TypeError( diff --git a/apprise/plugins/NotifyEmail.py b/apprise/plugins/NotifyEmail.py index e267ff39..c124a14d 100644 --- a/apprise/plugins/NotifyEmail.py +++ b/apprise/plugins/NotifyEmail.py @@ -128,14 +128,11 @@ class NotifyEmail(NotifyBase): # Default SMTP Timeout (in seconds) connect_timeout = 15 - def __init__(self, to, notify_format, **kwargs): + def __init__(self, to, **kwargs): """ Initialize Email Object """ - super(NotifyEmail, self).__init__( - title_maxlen=250, body_maxlen=32768, - notify_format=notify_format, - **kwargs) + super(NotifyEmail, self).__init__(**kwargs) # Store To Addr self.to_addr = to diff --git a/apprise/plugins/NotifyEmby.py b/apprise/plugins/NotifyEmby.py index 074e67f0..8c56272f 100644 --- a/apprise/plugins/NotifyEmby.py +++ b/apprise/plugins/NotifyEmby.py @@ -62,8 +62,7 @@ class NotifyEmby(NotifyBase): Initialize Emby Object """ - super(NotifyEmby, self).__init__( - title_maxlen=250, body_maxlen=32768, **kwargs) + super(NotifyEmby, self).__init__(**kwargs) if self.secure: self.schema = 'https' diff --git a/apprise/plugins/NotifyFaast.py b/apprise/plugins/NotifyFaast.py index 8a3959c3..eb02bc2c 100644 --- a/apprise/plugins/NotifyFaast.py +++ b/apprise/plugins/NotifyFaast.py @@ -2,7 +2,7 @@ # # Faast Notify Wrapper # -# Copyright (C) 2017 Chris Caron +# Copyright (C) 2017-2018 Chris Caron # # This file is part of apprise. # @@ -22,9 +22,6 @@ from .NotifyBase import NotifyBase from .NotifyBase import HTTP_ERROR_MAP from ..common import NotifyImageSize -# Image Support (72x72) -FAAST_IMAGE_XY = NotifyImageSize.XY_72 - class NotifyFaast(NotifyBase): """ @@ -37,13 +34,14 @@ class NotifyFaast(NotifyBase): # Faast uses the http protocol with JSON requests 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): """ Initialize Faast Object """ - super(NotifyFaast, self).__init__( - title_maxlen=250, body_maxlen=32768, image_size=FAAST_IMAGE_XY, - **kwargs) + super(NotifyFaast, self).__init__(**kwargs) self.authtoken = authtoken diff --git a/apprise/plugins/NotifyGrowl/NotifyGrowl.py b/apprise/plugins/NotifyGrowl/NotifyGrowl.py index 8632f525..32934b3e 100644 --- a/apprise/plugins/NotifyGrowl/NotifyGrowl.py +++ b/apprise/plugins/NotifyGrowl/NotifyGrowl.py @@ -23,9 +23,6 @@ from .gntp import errors from ..NotifyBase import NotifyBase from ...common import NotifyImageSize -# Image Support (72x72) -GROWL_IMAGE_XY = NotifyImageSize.XY_72 - # Priorities class GrowlPriority(object): @@ -59,13 +56,14 @@ class NotifyGrowl(NotifyBase): # Default Growl Port default_port = 23053 + # Allows the user to specify the NotifyImageSize object + image_size = NotifyImageSize.XY_72 + def __init__(self, priority=None, version=2, **kwargs): """ Initialize Growl Object """ - super(NotifyGrowl, self).__init__( - title_maxlen=250, body_maxlen=32768, - image_size=GROWL_IMAGE_XY, **kwargs) + super(NotifyGrowl, self).__init__(**kwargs) if not self.port: self.port = self.default_port diff --git a/apprise/plugins/NotifyIFTTT.py b/apprise/plugins/NotifyIFTTT.py index 02c941dc..1569df44 100644 --- a/apprise/plugins/NotifyIFTTT.py +++ b/apprise/plugins/NotifyIFTTT.py @@ -76,8 +76,7 @@ class NotifyIFTTT(NotifyBase): Initialize IFTTT Object """ - super(NotifyIFTTT, self).__init__( - title_maxlen=250, body_maxlen=32768, **kwargs) + super(NotifyIFTTT, self).__init__(**kwargs) if not apikey: raise TypeError('You must specify the Webhooks apikey.') diff --git a/apprise/plugins/NotifyJSON.py b/apprise/plugins/NotifyJSON.py index 4ba71ca4..8375610b 100644 --- a/apprise/plugins/NotifyJSON.py +++ b/apprise/plugins/NotifyJSON.py @@ -24,9 +24,6 @@ from .NotifyBase import HTTP_ERROR_MAP from ..common import NotifyImageSize from ..utils import compat_is_basestring -# Image Support (128x128) -JSON_IMAGE_XY = NotifyImageSize.XY_128 - class NotifyJSON(NotifyBase): """ @@ -39,13 +36,14 @@ class NotifyJSON(NotifyBase): # The default secure protocol secure_protocol = 'jsons' + # Allows the user to specify the NotifyImageSize object + image_size = NotifyImageSize.XY_128 + def __init__(self, **kwargs): """ Initialize JSON Object """ - super(NotifyJSON, self).__init__( - title_maxlen=250, body_maxlen=32768, image_size=JSON_IMAGE_XY, - **kwargs) + super(NotifyJSON, self).__init__(**kwargs) if self.secure: self.schema = 'https' diff --git a/apprise/plugins/NotifyJoin.py b/apprise/plugins/NotifyJoin.py index 20348c4d..37fbb8cf 100644 --- a/apprise/plugins/NotifyJoin.py +++ b/apprise/plugins/NotifyJoin.py @@ -71,13 +71,17 @@ class NotifyJoin(NotifyBase): notify_url = \ '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): """ Initialize Join Object """ - super(NotifyJoin, self).__init__( - title_maxlen=250, body_maxlen=1000, image_size=JOIN_IMAGE_XY, - **kwargs) + super(NotifyJoin, self).__init__(**kwargs) if not VALIDATE_APIKEY.match(apikey.strip()): self.logger.warning( diff --git a/apprise/plugins/NotifyMatterMost.py b/apprise/plugins/NotifyMatterMost.py index dbc2a7d8..9f7ac06b 100644 --- a/apprise/plugins/NotifyMatterMost.py +++ b/apprise/plugins/NotifyMatterMost.py @@ -2,7 +2,7 @@ # # MatterMost Notify Wrapper # -# Copyright (C) 2017 Chris Caron +# Copyright (C) 2017-2018 Chris Caron # # This file is part of apprise. # @@ -31,9 +31,6 @@ from ..common import NotifyImageSize # Used to validate Authorization Token VALIDATE_AUTHTOKEN = re.compile(r'[A-Za-z0-9]{24,32}') -# Image Support (72x72) -MATTERMOST_IMAGE_XY = NotifyImageSize.XY_72 - class NotifyMatterMost(NotifyBase): """ @@ -49,13 +46,17 @@ class NotifyMatterMost(NotifyBase): # The default Mattermost port 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): """ Initialize MatterMost Object """ - super(NotifyMatterMost, self).__init__( - title_maxlen=250, body_maxlen=4000, image_size=MATTERMOST_IMAGE_XY, - **kwargs) + super(NotifyMatterMost, self).__init__(**kwargs) if self.secure: self.schema = 'https' diff --git a/apprise/plugins/NotifyMyAndroid.py b/apprise/plugins/NotifyMyAndroid.py index ff725f33..2312fd95 100644 --- a/apprise/plugins/NotifyMyAndroid.py +++ b/apprise/plugins/NotifyMyAndroid.py @@ -2,7 +2,7 @@ # # Notify My Android (NMA) Notify Wrapper # -# Copyright (C) 2017 Chris Caron +# Copyright (C) 2017-2018 Chris Caron # # This file is part of apprise. # @@ -64,12 +64,17 @@ class NotifyMyAndroid(NotifyBase): # Notify My Android uses the http protocol with JSON requests 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): """ Initialize Notify My Android Object """ - super(NotifyMyAndroid, self).__init__( - title_maxlen=1000, body_maxlen=10000, **kwargs) + super(NotifyMyAndroid, self).__init__(**kwargs) # The Priority of the message if priority not in NMA_PRIORITIES: diff --git a/apprise/plugins/NotifyProwl.py b/apprise/plugins/NotifyProwl.py index e28a06e2..309182d1 100644 --- a/apprise/plugins/NotifyProwl.py +++ b/apprise/plugins/NotifyProwl.py @@ -2,7 +2,7 @@ # # Prowl Notify Wrapper # -# Copyright (C) 2017 Chris Caron +# Copyright (C) 2017-2018 Chris Caron # # This file is part of apprise. # @@ -65,12 +65,17 @@ class NotifyProwl(NotifyBase): # Prowl uses the http protocol with JSON requests 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): """ Initialize Prowl Object """ - super(NotifyProwl, self).__init__( - title_maxlen=1024, body_maxlen=10000, **kwargs) + super(NotifyProwl, self).__init__(**kwargs) if priority not in PROWL_PRIORITIES: self.priority = ProwlPriority.NORMAL diff --git a/apprise/plugins/NotifyPushBullet.py b/apprise/plugins/NotifyPushBullet.py index 0f655df5..fc73b7fe 100644 --- a/apprise/plugins/NotifyPushBullet.py +++ b/apprise/plugins/NotifyPushBullet.py @@ -2,7 +2,7 @@ # # PushBullet Notify Wrapper # -# Copyright (C) 2017 Chris Caron +# Copyright (C) 2017-2018 Chris Caron # # This file is part of apprise. # @@ -55,8 +55,7 @@ class NotifyPushBullet(NotifyBase): """ Initialize PushBullet Object """ - super(NotifyPushBullet, self).__init__( - title_maxlen=250, body_maxlen=32768, **kwargs) + super(NotifyPushBullet, self).__init__(**kwargs) self.accesstoken = accesstoken if compat_is_basestring(recipients): diff --git a/apprise/plugins/NotifyPushalot.py b/apprise/plugins/NotifyPushalot.py index 250a6e46..b3f1dcdf 100644 --- a/apprise/plugins/NotifyPushalot.py +++ b/apprise/plugins/NotifyPushalot.py @@ -2,7 +2,7 @@ # # Pushalot Notify Wrapper # -# Copyright (C) 2017 Chris Caron +# Copyright (C) 2017-2018 Chris Caron # # This file is part of apprise. # @@ -24,9 +24,6 @@ from .NotifyBase import NotifyBase from .NotifyBase import HTTP_ERROR_MAP from ..common import NotifyImageSize -# Image Support (72x72) -PUSHALOT_IMAGE_XY = NotifyImageSize.XY_72 - # Extend HTTP Error Messages PUSHALOT_HTTP_ERROR_MAP = HTTP_ERROR_MAP.copy() PUSHALOT_HTTP_ERROR_MAP.update({ @@ -49,13 +46,14 @@ class NotifyPushalot(NotifyBase): # Pushalot uses the http protocol with JSON requests 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): """ Initialize Pushalot Object """ - super(NotifyPushalot, self).__init__( - title_maxlen=250, body_maxlen=32768, - image_size=PUSHALOT_IMAGE_XY, **kwargs) + super(NotifyPushalot, self).__init__(**kwargs) # Is Important Flag self.is_important = is_important diff --git a/apprise/plugins/NotifyPushjet/NotifyPushjet.py b/apprise/plugins/NotifyPushjet/NotifyPushjet.py index 09baf668..bea2a2c3 100644 --- a/apprise/plugins/NotifyPushjet/NotifyPushjet.py +++ b/apprise/plugins/NotifyPushjet/NotifyPushjet.py @@ -42,8 +42,7 @@ class NotifyPushjet(NotifyBase): """ Initialize Pushjet Object """ - super(NotifyPushjet, self).__init__( - title_maxlen=250, body_maxlen=32768, **kwargs) + super(NotifyPushjet, self).__init__(**kwargs) def notify(self, title, body, notify_type): """ diff --git a/apprise/plugins/NotifyPushover.py b/apprise/plugins/NotifyPushover.py index f5ac59e9..a259de03 100644 --- a/apprise/plugins/NotifyPushover.py +++ b/apprise/plugins/NotifyPushover.py @@ -74,12 +74,14 @@ class NotifyPushover(NotifyBase): # Pushover uses the http protocol with JSON requests 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): """ Initialize Pushover Object """ - super(NotifyPushover, self).__init__( - title_maxlen=250, body_maxlen=512, **kwargs) + super(NotifyPushover, self).__init__(**kwargs) try: # The token associated with the account diff --git a/apprise/plugins/NotifyRocketChat.py b/apprise/plugins/NotifyRocketChat.py index c8813998..4e9102aa 100644 --- a/apprise/plugins/NotifyRocketChat.py +++ b/apprise/plugins/NotifyRocketChat.py @@ -2,7 +2,7 @@ # # Notify Rocket.Chat Notify Wrapper # -# Copyright (C) 2017 Chris Caron +# Copyright (C) 2017-2018 Chris Caron # # This file is part of apprise. # @@ -50,12 +50,14 @@ class NotifyRocketChat(NotifyBase): # The default secure protocol secure_protocol = 'rockets' + # Defines the maximum allowable characters in the title + title_maxlen = 200 + def __init__(self, recipients=None, **kwargs): """ Initialize Notify Rocket.Chat Object """ - super(NotifyRocketChat, self).__init__( - title_maxlen=200, body_maxlen=32768, **kwargs) + super(NotifyRocketChat, self).__init__(**kwargs) if self.secure: self.schema = 'https' diff --git a/apprise/plugins/NotifySlack.py b/apprise/plugins/NotifySlack.py index d5543d81..a44c7119 100644 --- a/apprise/plugins/NotifySlack.py +++ b/apprise/plugins/NotifySlack.py @@ -65,9 +65,6 @@ CHANNEL_LIST_DELIM = re.compile(r'[ \t\r\n,#\\/]+') # Used to detect a channel 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): """ @@ -80,13 +77,17 @@ class NotifySlack(NotifyBase): # Slack uses the http protocol with JSON requests 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): """ Initialize Slack Object """ - super(NotifySlack, self).__init__( - title_maxlen=250, body_maxlen=1000, - image_size=SLACK_IMAGE_XY, **kwargs) + super(NotifySlack, self).__init__(**kwargs) if not VALIDATE_TOKEN_A.match(token_a.strip()): self.logger.warning( diff --git a/apprise/plugins/NotifyStride.py b/apprise/plugins/NotifyStride.py index 5053579d..2525c3fe 100644 --- a/apprise/plugins/NotifyStride.py +++ b/apprise/plugins/NotifyStride.py @@ -50,9 +50,6 @@ from .NotifyBase import NotifyBase from .NotifyBase import HTTP_ERROR_MAP from ..common import NotifyImageSize -# Image Support (256x256) -STRIDE_IMAGE_XY = NotifyImageSize.XY_256 - # A Simple UUID4 checker IS_VALID_TOKEN = re.compile( 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}/' \ '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): """ Initialize Stride Object """ - super(NotifyStride, self).__init__( - title_maxlen=250, body_maxlen=2000, - image_size=STRIDE_IMAGE_XY, **kwargs) + super(NotifyStride, self).__init__(**kwargs) if not auth_token: raise TypeError( diff --git a/apprise/plugins/NotifyTelegram.py b/apprise/plugins/NotifyTelegram.py index 3b859f8f..210ea9a4 100644 --- a/apprise/plugins/NotifyTelegram.py +++ b/apprise/plugins/NotifyTelegram.py @@ -53,7 +53,6 @@ from json import dumps from .NotifyBase import NotifyBase from .NotifyBase import HTTP_ERROR_MAP from ..common import NotifyImageSize -from ..common import NotifyFormat from ..utils import compat_is_basestring from ..utils import parse_bool @@ -89,15 +88,18 @@ class NotifyTelegram(NotifyBase): # Telegram uses the http protocol with JSON requests notify_url = 'https://api.telegram.org/bot' - def __init__(self, bot_token, chat_ids, notify_format=NotifyFormat.TEXT, - detect_bot_owner=True, include_image=True, **kwargs): + # 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 = 4096 + + def __init__(self, bot_token, chat_ids, detect_bot_owner=True, + include_image=True, **kwargs): """ Initialize Telegram Object """ - super(NotifyTelegram, self).__init__( - title_maxlen=250, body_maxlen=4096, - notify_format=notify_format, - image_size=TELEGRAM_IMAGE_XY, **kwargs) + super(NotifyTelegram, self).__init__(**kwargs) try: self.bot_token = bot_token.strip() diff --git a/apprise/plugins/NotifyToasty.py b/apprise/plugins/NotifyToasty.py index 1aae6de1..603e5dbb 100644 --- a/apprise/plugins/NotifyToasty.py +++ b/apprise/plugins/NotifyToasty.py @@ -24,9 +24,6 @@ from .NotifyBase import HTTP_ERROR_MAP from ..common import NotifyImageSize 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 # into a usable list. DEVICES_LIST_DELIM = re.compile(r'[ \t\r\n,\\/]+') @@ -43,13 +40,14 @@ class NotifyToasty(NotifyBase): # Toasty uses the http protocol with JSON requests 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): """ Initialize Toasty Object """ - super(NotifyToasty, self).__init__( - title_maxlen=250, body_maxlen=32768, image_size=TOASTY_IMAGE_XY, - **kwargs) + super(NotifyToasty, self).__init__(**kwargs) if compat_is_basestring(devices): self.devices = [x for x in filter(bool, DEVICES_LIST_DELIM.split( diff --git a/apprise/plugins/NotifyTwitter/NotifyTwitter.py b/apprise/plugins/NotifyTwitter/NotifyTwitter.py index aaf01638..db4783d2 100644 --- a/apprise/plugins/NotifyTwitter/NotifyTwitter.py +++ b/apprise/plugins/NotifyTwitter/NotifyTwitter.py @@ -19,9 +19,6 @@ from . import tweepy from ..NotifyBase import NotifyBase -# Direct Messages have not image support -TWITTER_IMAGE_XY = None - class NotifyTwitter(NotifyBase): """ @@ -32,16 +29,17 @@ class NotifyTwitter(NotifyBase): # The default secure protocol 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): """ 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__( - title_maxlen=250, body_maxlen=4096, - image_size=TWITTER_IMAGE_XY, **kwargs) + super(NotifyTwitter, self).__init__(**kwargs) if not ckey: raise TypeError( diff --git a/apprise/plugins/NotifyXBMC.py b/apprise/plugins/NotifyXBMC.py index fc7ae9bd..18b986c5 100644 --- a/apprise/plugins/NotifyXBMC.py +++ b/apprise/plugins/NotifyXBMC.py @@ -25,9 +25,6 @@ from .NotifyBase import HTTP_ERROR_MAP from ..common import NotifyType from ..common import NotifyImageSize -# Image Support (128x128) -XBMC_IMAGE_XY = NotifyImageSize.XY_128 - class NotifyXBMC(NotifyBase): """ @@ -43,6 +40,9 @@ class NotifyXBMC(NotifyBase): # XBMC uses the http protocol with JSON requests xbmc_default_port = 8080 + # Allows the user to specify the NotifyImageSize object + image_size = NotifyImageSize.XY_128 + # XBMC default protocol version (v2) xbmc_remote_protocol = 2 @@ -53,9 +53,7 @@ class NotifyXBMC(NotifyBase): """ Initialize XBMC/KODI Object """ - super(NotifyXBMC, self).__init__( - title_maxlen=250, body_maxlen=32768, - image_size=XBMC_IMAGE_XY, **kwargs) + super(NotifyXBMC, self).__init__(**kwargs) if self.secure: self.schema = 'https' diff --git a/apprise/plugins/NotifyXML.py b/apprise/plugins/NotifyXML.py index c056ab89..9a7df319 100644 --- a/apprise/plugins/NotifyXML.py +++ b/apprise/plugins/NotifyXML.py @@ -24,9 +24,6 @@ from .NotifyBase import HTTP_ERROR_MAP from ..common import NotifyImageSize from ..utils import compat_is_basestring -# Image Support (128x128) -XML_IMAGE_XY = NotifyImageSize.XY_128 - class NotifyXML(NotifyBase): """ @@ -39,13 +36,14 @@ class NotifyXML(NotifyBase): # The default secure protocol secure_protocol = 'xmls' + # Allows the user to specify the NotifyImageSize object + image_size = NotifyImageSize.XY_128 + def __init__(self, **kwargs): """ Initialize XML Object """ - super(NotifyXML, self).__init__( - title_maxlen=250, body_maxlen=32768, - image_size=XML_IMAGE_XY, **kwargs) + super(NotifyXML, self).__init__(**kwargs) self.payload = """ +# Copyright (C) 2017-2018 Chris Caron # # This file is part of apprise. # @@ -38,14 +38,6 @@ def test_notify_base(): except TypeError: 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 nb = NotifyBase(port='invalid') assert nb.port is None @@ -54,7 +46,8 @@ def test_notify_base(): assert nb.port == 10 # Throttle overrides.. - nb = NotifyBase(throttle=0) + nb = NotifyBase() + nb.throttle_attempt = 0.0 start_time = default_timer() nb.throttle() elapsed = default_timer() - start_time @@ -85,8 +78,10 @@ def test_notify_base(): assert isinstance( nb.color(notify_type=NotifyType.INFO, color_type=tuple), tuple) - # Create an object with an ImageSize loaded into it - nb = NotifyBase(image_size=NotifyImageSize.XY_256) + # Create an object + 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 assert nb.image_url(notify_type=NotifyType.INFO) is not None diff --git a/test/test_rest_plugins.py b/test/test_rest_plugins.py index ad85df95..fb067f38 100644 --- a/test/test_rest_plugins.py +++ b/test/test_rest_plugins.py @@ -2594,6 +2594,15 @@ def test_notify_telegram_plugin(mock_post, mock_get): nimg_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 assert obj.notify( title='title', body='body', notify_type=NotifyType.INFO) is False