def send(token, title, **kwargs):
    """
    Site: https://boxcar.io/
    API: http://help.boxcar.io/knowledgebase/topics/48115-boxcar-api
    Desc: Best app for system administrators
    """
    headers = {
        "Content-type": "application/x-www-form-urlencoded",
        "User-Agent": "DBMail/%s" % get_version(),
    }

    data = {
        "user_credentials": token,
        "notification[title]": from_unicode(title),
        "notification[sound]": "notifier-2"
    }

    for k, v in kwargs.items():
        data['notification[%s]' % k] = from_unicode(v)

    http = HTTPSConnection(kwargs.pop("api_url", "new.boxcar.io"))
    http.request(
        "POST", "/api/notifications",
        headers=headers,
        body=urlencode(data))
    response = http.getresponse()

    if response.status != 201:
        raise BoxcarError(response.reason)
    return True
Exemple #2
0
def send(sms_to, sms_body, **kwargs):
    """
    Site: http://iqsms.ru/
    API: http://iqsms.ru/api/
    """
    headers = {
        "User-Agent": "DBMail/%s" % get_version(),
        'Authorization': 'Basic %s' % b64encode(
            "%s:%s" % (
                settings.IQSMS_API_LOGIN, settings.IQSMS_API_PASSWORD
            )).decode("ascii")
    }

    kwargs.update({
        'phone': sms_to,
        'text': from_unicode(sms_body),
        'sender': kwargs.pop('sms_from', settings.IQSMS_FROM)
    })

    http = HTTPConnection(kwargs.pop("api_url", "gate.iqsms.ru"))
    http.request("GET", "/send/?" + urlencode(kwargs), headers=headers)
    response = http.getresponse()

    if response.status != 200:
        raise IQSMSError(response.reason)

    body = response.read().strip()
    if '=accepted' not in body:
        raise IQSMSError(body)

    return int(body.split('=')[0])
def send(sms_to, sms_body, **kwargs):
    """
    Site: https://www.twilio.com/
    API: https://www.twilio.com/docs/api/rest/sending-messages
    """
    headers = {
        "Content-type":
        "application/x-www-form-urlencoded",
        "User-Agent":
        "DBMail/%s" % get_version(),
        'Authorization':
        'Basic %s' % b64encode("%s:%s" %
                               (settings.TWILIO_ACCOUNT_SID,
                                settings.TWILIO_AUTH_TOKEN)).decode("ascii")
    }

    kwargs.update({
        'From': kwargs.pop('sms_from', settings.TWILIO_FROM),
        'To': sms_to,
        'Body': from_unicode(sms_body)
    })

    http = HTTPSConnection(kwargs.pop("api_url", "api.twilio.com"))
    http.request("POST",
                 "/2010-04-01/Accounts/%s/Messages.json" %
                 settings.TWILIO_ACCOUNT_SID,
                 headers=headers,
                 body=urlencode(kwargs))

    response = http.getresponse()
    if response.status != 201:
        raise TwilioSmsError(response.reason)

    return loads(response.read()).get('sid')
def send(sms_to, sms_body, **kwargs):
    """
    Site: http://iqsms.ru/
    API: http://iqsms.ru/api/
    """
    headers = {
        "User-Agent":
        "DBMail/%s" % get_version(),
        'Authorization':
        'Basic %s' % b64encode("%s:%s" %
                               (settings.IQSMS_API_LOGIN,
                                settings.IQSMS_API_PASSWORD)).decode("ascii")
    }

    kwargs.update({
        'phone': sms_to,
        'text': from_unicode(sms_body),
        'sender': kwargs.pop('sms_from', settings.IQSMS_FROM)
    })

    http = HTTPConnection(kwargs.pop("api_url", "gate.iqsms.ru"))
    http.request("GET", "/send/?" + urlencode(kwargs), headers=headers)
    response = http.getresponse()

    if response.status != 200:
        raise IQSMSError(response.reason)

    body = response.read().strip()
    if '=accepted' not in body:
        raise IQSMSError(body)

    return int(body.split('=')[0])
Exemple #5
0
def send(sms_to, sms_body, **kwargs):
    """
    Site: https://www.twilio.com/
    API: https://www.twilio.com/docs/api/rest/sending-messages
    """
    headers = {
        "Content-type": "application/x-www-form-urlencoded",
        "User-Agent": "DBMail/%s" % get_version(),
        'Authorization': 'Basic %s' % b64encode(
            "%s:%s" % (
                settings.TWILIO_ACCOUNT_SID, settings.TWILIO_AUTH_TOKEN
            )).decode("ascii")

    }

    kwargs.update({
        'From': kwargs.pop('sms_from', settings.TWILIO_FROM),
        'To': sms_to,
        'Body': from_unicode(sms_body)
    })

    http = HTTPSConnection(kwargs.pop("api_url", "api.twilio.com"))
    http.request(
        "POST",
        "/2010-04-01/Accounts/%s/Messages.json" % settings.TWILIO_ACCOUNT_SID,
        headers=headers,
        body=urlencode(kwargs))

    response = http.getresponse()
    if response.status != 201:
        raise TwilioSmsError(response.reason)

    return loads(response.read()).get('sid')
Exemple #6
0
def send(sms_to, sms_body, **kwargs):
    """
    Site: http://smsaero.ru/
    API: http://smsaero.ru/api/
    """
    headers = {
        "User-Agent": "DBMail/%s" % get_version(),
    }

    kwargs.update({
        'user': settings.SMSAERO_LOGIN,
        'password': settings.SMSAERO_MD5_PASSWORD,
        'from': kwargs.pop('sms_from', settings.SMSAERO_FROM),
        'to': sms_to.replace('+', ''),
        'text': from_unicode(sms_body)
    })

    http = HTTPConnection(kwargs.pop("api_url", "gate.smsaero.ru"))
    http.request("GET", "/send/?" + urlencode(kwargs), headers=headers)
    response = http.getresponse()

    if response.status != 200:
        raise AeroSmsError(response.reason)

    body = response.read().strip()
    if '=accepted' not in body:
        raise AeroSmsError(body)

    return int(body.split('=')[0])
def send(channel, message, **kwargs):
    """
    Site: https://slack.com
    API: https://api.slack.com
    Desc: real-time messaging
    """
    headers = {
        "Content-type": "application/x-www-form-urlencoded",
        "User-Agent": "DBMail/%s" % get_version(),
    }

    username = from_unicode(kwargs.pop("username", settings.SLACK_USERNAME))
    hook_url = from_unicode(kwargs.pop("hook_url", settings.SLACK_HOOCK_URL))
    channel = from_unicode(channel or settings.SLACK_CHANNEL)
    emoji = from_unicode(kwargs.pop("emoji", ""))
    message = from_unicode(message)

    data = {
        "channel": channel,
        "username": username,
        "text": message,
        "icon_emoji": emoji,
    }

    _data = kwargs.pop('data', None)
    if _data is not None:
        data.update(_data)

    up = urlparse(hook_url)
    http = HTTPSConnection(up.netloc)
    http.request("POST",
                 up.path,
                 headers=headers,
                 body=urlencode({"payload": dumps(data)}))
    response = http.getresponse()

    if response.status != 200:
        raise SlackError(response.reason)

    body = response.read()
    if body != "ok":
        raise SlackError(repr(body))
    return True
Exemple #8
0
def send(channel, message, **kwargs):
    """
    Site: https://slack.com
    API: https://api.slack.com
    Desc: real-time messaging
    """
    headers = {
        "Content-type": "application/x-www-form-urlencoded",
        "User-Agent": "DBMail/%s" % get_version(),
    }

    username = from_unicode(kwargs.pop("username", settings.SLACK_USERNAME))
    hook_url = from_unicode(kwargs.pop("hook_url", settings.SLACK_HOOCK_URL))
    channel = from_unicode(channel or settings.SLACK_CHANNEL)
    emoji = from_unicode(kwargs.pop("emoji", ""))
    message = from_unicode(message)

    data = {
        "channel": channel,
        "username": username,
        "text": message,
        "icon_emoji": emoji,
    }

    _data = kwargs.pop('data', None)
    if _data is not None:
        data.update(_data)

    up = urlparse(hook_url)
    http = HTTPSConnection(up.netloc)
    http.request(
        "POST", up.path,
        headers=headers,
        body=urlencode({"payload": dumps(data)}))
    response = http.getresponse()

    if response.status != 200:
        raise SlackError(response.reason)

    body = response.read()
    if body != "ok":
        raise SlackError(repr(body))
    return True
Exemple #9
0
 def send_message(self, sms_to, message, **kwargs):
     kwargs.update({
         'messages': [{
             'clientId': 1,
             'phone': sms_to,
             'text': from_unicode(message),
             'sender': self._from_msg
         }],
         'showBillingDetails': True
     })
     return self._send_request(kwargs)
Exemple #10
0
def send(user, message, **kwargs):
    """
    Site: https://pushover.net/
    API: https://pushover.net/api
    Desc: real-time notifications
    """
    headers = {
        "Content-type": "application/x-www-form-urlencoded",
        "User-Agent": "DBMail/%s" % get_version(),
    }

    title = from_unicode(kwargs.pop("title", settings.PUSHOVER_APP))
    message = from_unicode(message)

    data = {
        "token": settings.PUSHOVER_TOKEN,
        "user": user,
        "message": message,
        "title": title,
        "priority": kwargs.pop("priority", 0)
    }

    _data = kwargs.pop('data', None)
    if _data is not None:
        data.update(_data)

    http = HTTPSConnection(kwargs.pop("api_url", "api.pushover.net"))
    http.request(
        "POST", "/1/messages.json",
        headers=headers,
        body=urlencode(data))
    response = http.getresponse()

    if response.status != 200:
        raise PushOverError(response.reason)

    body = loads(response.read())
    if body.get('status') != 1:
        raise PushOverError(repr(body))
    return True
Exemple #11
0
def send(user, message, **kwargs):
    """
    Site: https://pushover.net/
    API: https://pushover.net/api
    Desc: real-time notifications
    """
    headers = {
        "Content-type": "application/x-www-form-urlencoded",
        "User-Agent": "DBMail/%s" % get_version(),
    }

    title = from_unicode(kwargs.pop("title", settings.PUSHOVER_APP))
    message = from_unicode(message)

    data = {
        "token": settings.PUSHOVER_TOKEN,
        "user": user,
        "message": message,
        "title": title,
        "priority": kwargs.pop("priority", 0)
    }

    _data = kwargs.pop('data', None)
    if _data is not None:
        data.update(_data)

    http = HTTPSConnection(kwargs.pop("api_url", "api.pushover.net"))
    http.request(
        "POST", "/1/messages.json",
        headers=headers,
        body=urlencode(data))
    response = http.getresponse()

    if response.status != 200:
        raise PushOverError(response.reason)

    body = loads(response.read())
    if body.get('status') != 1:
        raise PushOverError(repr(body))
    return True
Exemple #12
0
def send(sms_to, sms_body, **kwargs):
    """
    Site: http://smsaero.ru/
    API: http://smsaero.ru/api/
    """
    headers = {
        "User-Agent": "DBMail/%s" % get_version(),
    }

    kwargs.update({
        'user': settings.SMSAERO_LOGIN,
        'password': settings.SMSAERO_MD5_PASSWORD,
        'from': kwargs.pop('sms_from', settings.SMSAERO_FROM),
        'to': sms_to.replace('+', ''),
        'text': from_unicode(sms_body),
        'answer': 'json',
    })

    http = HTTPConnection(kwargs.pop("api_url", "gate.smsaero.ru"))
    http.request("GET", "/send/?" + urlencode(kwargs), headers=headers)
    response = http.getresponse()

    if response.status != 200:
        raise AeroSmsError(response.reason)

    read = response.read().decode(response.headers.get_content_charset())
    data = json.loads(read)

    status = None
    if 'result' in data:
        status = data['result']

    sms_id = None
    if 'id' in data:
        sms_id = data['id']

    if sms_id and status == 'accepted':
        return True
    return False
def send(sms_to, sms_body, **kwargs):
    api_url = kwargs.pop('api_url', 'https://rest.nexmo.com/sms/json')
    params = {
        'api_key': settings.NEXMO_USERNAME,
        'api_secret': settings.NEXMO_PASSWORD,
        'from': kwargs.pop('sms_from', settings.NEXMO_FROM),
        'to': sms_to.replace('+', ''),
        'type': 'unicode',
        'lg': settings.NEXMO_LANG,
        'text': from_unicode(sms_body)
    }
    if kwargs:
        params.update(**kwargs)

    url = urlopen('%s?%s' % (api_url, urlencode(params)))
    messages = loads(url.read())

    response = messages.get('messages')
    if response and response[0].get('error-text'):
        raise NexmoSmsError(messages['messages'][0]['error-text'])
    elif 'status' in messages and messages.get('status') != '0':
        raise NexmoSmsError(messages.get('error-text'))
    return messages
Exemple #14
0
def send(sms_to, sms_body, **kwargs):
    api_url = kwargs.pop("api_url", "https://rest.nexmo.com/sms/json")
    params = {
        "api_key": settings.NEXMO_USERNAME,
        "api_secret": settings.NEXMO_PASSWORD,
        "from": kwargs.pop("sms_from", settings.NEXMO_FROM),
        "to": sms_to.replace("+", ""),
        "type": "unicode",
        "lg": settings.NEXMO_LANG,
        "text": from_unicode(sms_body),
    }
    if kwargs:
        params.update(**kwargs)

    url = urlopen("%s?%s" % (api_url, urlencode(params)))
    messages = loads(url.read())

    response = messages.get("messages")
    if response and response[0].get("error-text"):
        raise NexmoSmsError(messages["messages"][0]["error-text"])
    elif "status" in messages and messages.get("status") != "0":
        raise NexmoSmsError(messages.get("error-text"))
    return messages
Exemple #15
0
def send(sms_to, sms_body, **kwargs):
    api_url = kwargs.pop('api_url', 'https://rest.nexmo.com/sms/json')
    params = {
        'api_key': settings.NEXMO_USERNAME,
        'api_secret': settings.NEXMO_PASSWORD,
        'from': kwargs.pop('sms_from', settings.NEXMO_FROM),
        'to': sms_to.replace('+', ''),
        'type': 'unicode',
        'lg': settings.NEXMO_LANG,
        'text': from_unicode(sms_body)
    }
    if kwargs:
        params.update(**kwargs)

    url = urlopen('%s?%s' % (api_url, urlencode(params)))
    messages = loads(url.read())

    response = messages.get('messages')
    if response and response[0].get('error-text'):
        raise NexmoSmsError(messages['messages'][0]['error-text'])
    elif 'status' in messages and messages.get('status') != '0':
        raise NexmoSmsError(messages.get('error-text'))
    return messages