SMSWithoutBorders Backend Publisher library
Please make sure you have Python 3.7 or newer (python --version).
$ python3 -m venv venv
$ . venv/bin/activate
$ 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"
$ git clone https://github.com/smswithoutborders/SMSWithoutBorders-BE-Publisher.git
$ cd SMSWithoutBorders-BE-Publisher
$ python3 setup.py install
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": "" }
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": "" }
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": "" }
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": [] }
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": "" }
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
""
PlatformDoesNotExist: Exception raised when Platform is not Found.
return: String
UserDoesNotExist: Exception raised when User is not Found.
return: String
DuplicateUsersExist: Exception raised when Duplicate Users Exist.
return: String
InvalidDataError: Exception raised when data mismatch the required format during decryption.
return: String
This project is licensed under the GNU General Public License v3.0.