smswithoutborders / SMSWithoutBorders-BE-Publisher

GNU General Public License v3.0
4 stars 0 forks source link

SMSWithoutBorders-BE-Publisher

SMSWithoutBorders Backend Publisher library

Installation

Please make sure you have Python 3.7 or newer (python --version).

Create a Virtual Environments

$ python3 -m venv venv
$ . venv/bin/activate

PyPI

$ pip install --upgrade pip wheel
$ pip install "git+https://github.com/smswithoutborders/SMSWithoutBorders-BE-Publisher.git@main#egg=SwobBackendPublisher"

Install upgrades

$ pip install --force-reinstall "git+https://github.com/smswithoutborders/SMSWithoutBorders-BE-Publisher.git@main#egg=SwobBackendPublisher"

From source

$ git clone https://github.com/smswithoutborders/SMSWithoutBorders-BE-Publisher.git
$ cd SMSWithoutBorders-BE-Publisher
$ python3 setup.py install

Usage

Table of Content


  1. get_grant_from_platform_name
  2. get_userid_from_phonenumber
  3. get_platform_name_from_letter
  4. get_user_platforms_from_id
  5. get_phone_number_hash_from_id
  6. hasher

get_grant_from_platform_name

from SwobBackendPublisher import MySQL, Lib
from SwobBackendPublisher.exceptions import (
    UserDoesNotExist,
    DuplicateUsersExist,
    InvalidDataError
)

MYSQL_HOST="my-host"
MYSQL_USER="my-username"
MYSQL_PASSWORD="my-root-password"
MYSQL_DATABASE="my-database"

try:
    # Connect to a MySQL database
    db = MySQL.connector(
            database=MYSQL_DATABASE,
            user=MYSQL_USER,
            password=MYSQL_PASSWORD,
            host=MYSQL_HOST
        )

    # Initialize SwobBackendPublisher Lib
    SBPLib = Lib(db=db)

    result = SBPLib.get_grant_from_platform_name(phone_number="+xxxxxxxxxxxx", platform_name="gmail")

    print(result)

except (UserDoesNotExist, DuplicateUsersExist, InvalidDataError) as error:
    # Handle exception ...

except Exception as error:
    # Handle exception here ...

result

{ "username": "", "token": {}, "uniqueId": "", "phoneNumber_hash": "" }

get_userid_from_phonenumber

from SwobBackendPublisher import MySQL, Lib
from SwobBackendPublisher.exceptions import UserDoesNotExist, DuplicateUsersExist

MYSQL_HOST="my-host"
MYSQL_USER="my-username"
MYSQL_PASSWORD="my-root-password"
MYSQL_DATABASE="my-database"

try:
    # Connect to a MySQL database
    db = MySQL.connector(
            database=MYSQL_DATABASE,
            user=MYSQL_USER,
            password=MYSQL_PASSWORD,
            host=MYSQL_HOST
        )

    # Initialize SwobBackendPublisher Lib
    SBPLib = Lib(db=db)

    result = SBPLib.get_userid_from_phonenumber(phone_number="+xxxxxxxxxxxx")

    print(result)

except (UserDoesNotExist, DuplicateUsersExist) as error:
    # Handle exception ...

except Exception as error:
    # Handle exception here ...

result

{ "user_id": "", "alias": "" }

get_platform_name_from_letter

from SwobBackendPublisher import MySQL, Lib
from SwobBackendPublisher.exceptions import PlatformDoesNotExist

MYSQL_HOST="my-host"
MYSQL_USER="my-username"
MYSQL_PASSWORD="my-root-password"
MYSQL_DATABASE="my-database"

try:
    # Connect to a MySQL database
    db = MySQL.connector(
            database=MYSQL_DATABASE,
            user=MYSQL_USER,
            password=MYSQL_PASSWORD,
            host=MYSQL_HOST
        )

    # Initialize SwobBackendPublisher Lib
    SBPLib = Lib(db=db)

    result = SBPLib.get_platform_name_from_letter(platform_letter="x")

    print(result)

except PlatformDoesNotExist as error:
    # Handle exception ...

except Exception as error:
    # Handle exception here ...

result

{ "platform_name": "" }

get_user_platforms_from_id

from SwobBackendPublisher import MySQL, Lib

MYSQL_HOST="my-host"
MYSQL_USER="my-username"
MYSQL_PASSWORD="my-root-password"
MYSQL_DATABASE="my-database"

try:
    # Connect to a MySQL database
    db = MySQL.connector(
            database=MYSQL_DATABASE,
            user=MYSQL_USER,
            password=MYSQL_PASSWORD,
            host=MYSQL_HOST
        )

    # Initialize SwobBackendPublisher Lib
    SBPLib = Lib(db=db)

    result = SBPLib.get_user_platforms_from_id(user_id="xxxxxxxxxxxxxx")

    print(result)

except Exception as error:
    # Handle exception here ...

result

{ "unsaved_platforms": [], "saved_platforms": [] }

get_phone_number_hash_from_id

from SwobBackendPublisher import MySQL, Lib
from SwobBackendPublisher.exceptions import UserDoesNotExist, DuplicateUsersExist

MYSQL_HOST="my-host"
MYSQL_USER="my-username"
MYSQL_PASSWORD="my-root-password"
MYSQL_DATABASE="my-database"

try:
    # Connect to a MySQL database
    db = MySQL.connector(
            database=MYSQL_DATABASE,
            user=MYSQL_USER,
            password=MYSQL_PASSWORD,
            host=MYSQL_HOST
        )

    # Initialize SwobBackendPublisher Lib
    SBPLib = Lib(db=db)

    result = SBPLib.get_phone_number_hash_from_id(user_id="xxxxxxxxxxxxxx", password="password")

    print(result)

except (UserDoesNotExist, DuplicateUsersExist) as error:
    # Handle exception ...

except Exception as error:
    # Handle exception here ...

result

{ "phoneNumber_hash": "" }

hasher

from SwobBackendPublisher import Lib

try:
    SBPLib = Lib()

    result = SBPLib.hasher(
        data="",
        salt="" #Optional (if empty use default from configurations)
    )

    print(result) #string

except Exception as error:
    # Handle exception here ...

result

""

Exceptions

Licensing

This project is licensed under the GNU General Public License v3.0.