-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
azat.zakirov
committed
Feb 7, 2020
0 parents
commit cce3650
Showing
8 changed files
with
817 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
pip-wheel-metadata/ | ||
share/python-wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
MANIFEST | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.nox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
*.py,cover | ||
.hypothesis/ | ||
.pytest_cache/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
local_settings.py | ||
db.sqlite3 | ||
db.sqlite3-journal | ||
|
||
# Flask stuff: | ||
instance/ | ||
.webassets-cache | ||
|
||
# Scrapy stuff: | ||
.scrapy | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
target/ | ||
|
||
# Jupyter Notebook | ||
.ipynb_checkpoints | ||
|
||
# IPython | ||
profile_default/ | ||
ipython_config.py | ||
|
||
# pyenv | ||
.python-version | ||
|
||
# pipenv | ||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. | ||
# However, in case of collaboration, if having platform-specific dependencies or dependencies | ||
# having no cross-platform support, pipenv may install dependencies that don't work, or not | ||
# install all needed dependencies. | ||
#Pipfile.lock | ||
|
||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow | ||
__pypackages__/ | ||
|
||
# Celery stuff | ||
celerybeat-schedule | ||
celerybeat.pid | ||
|
||
# SageMath parsed files | ||
*.sage.py | ||
|
||
# Environments | ||
.env | ||
.venv | ||
env/ | ||
venv/ | ||
ENV/ | ||
env.bak/ | ||
venv.bak/ | ||
|
||
# Spyder project settings | ||
.spyderproject | ||
.spyproject | ||
|
||
# Rope project settings | ||
.ropeproject | ||
|
||
# mkdocs documentation | ||
/site | ||
|
||
# mypy | ||
.mypy_cache/ | ||
.dmypy.json | ||
dmypy.json | ||
|
||
# Pyre type checker | ||
.pyre/ | ||
.idea/* | ||
Pipfile* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2020 Azat Zakirov | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
# UniSender Python client | ||
|
||
|
||
Python open source client for [UniSender API](https://www.unisender.com/ru/support/api/api/) | ||
|
||
### Features | ||
- Client for low-level access. | ||
- SimpleClient to quickly start mailing | ||
|
||
### Requirements | ||
- Python >= 3.6 | ||
- requests | ||
|
||
### Installation | ||
|
||
pip install git+git://github.com/antidasoftware/unisender-python-client.git | ||
|
||
|
||
### Basic usage | ||
|
||
Create an account in the [service](https://www.unisender.com) and get the API key in your account settings. | ||
|
||
|
||
```python | ||
from unisender import Client | ||
|
||
cl = Client( | ||
api_key="your_api_key", | ||
platform="example", | ||
lang="ru" | ||
) | ||
``` | ||
##### Client configuration | ||
|
||
- **base_url** [str] - API URL (default: "https://api.unisender.com") | ||
- **lang** [str] - API messages language, available: "ru", "en", "it" (default: "en") | ||
- **format** [str] - API response format, only "json" (default: "json") | ||
- **api_key*** [str] - Unisender account api key, | ||
- **platform*** [str] - API tracking marker | ||
|
||
##### API Methods call example | ||
|
||
See details about called methods in the [API docs](https://www.unisender.com/ru/support/api/api) | ||
|
||
```python | ||
# create contacts fields | ||
cl.create_field(name='username', type='string') | ||
|
||
# import contacts to API | ||
response = cl.import_contacts( | ||
field_names=['email', 'name'], | ||
data=[ | ||
['example1@gmail.com', 'John Lennon'], | ||
['example2@gmail.com', 'Paul McCartney'] | ||
] | ||
) | ||
``` | ||
|
||
### Advanced usage | ||
|
||
For fast mailing start your need use SimpleClient. | ||
|
||
```python | ||
from datetime import datetime, timedelta | ||
|
||
recipients = [ | ||
{'email': 'example_3@gmail.com', 'name': 'Dave Guard'}, | ||
{'email': 'example_4@mail.ru', 'name': 'Bon Shane'}, | ||
{'email': 'example_5@yandex.ru', 'name': 'Nick Reynolds'}, | ||
] | ||
``` | ||
SimpleClient provide **create_email_campaign** method for quick start mailing. | ||
|
||
There are three mailing modes: | ||
|
||
1. Send custom email message with body as HTML | ||
```python | ||
time_now = datetime.now() + timedelta(hours=2) | ||
|
||
create_email_campaign( | ||
email_type='html', | ||
email_data={ | ||
"subject": 'Mail subject', | ||
"sender_name": 'John Lenon', | ||
"sender_email": 'example_1@gmail.com', | ||
"body": '<html>...</html>', | ||
"categories": ['First', 'Second'] | ||
}, | ||
recipients=recipients, | ||
start_time=time_now, | ||
) | ||
|
||
``` | ||
2. Send email message from UniSender custom template: | ||
|
||
```python | ||
time_delay = datetime.now() + timedelta(hours=2) | ||
|
||
create_email_campaign( | ||
email_type='template', | ||
email_data={ | ||
"sender_name": 'John Lenon', | ||
"sender_email": 'example_1@gmail.com', | ||
"template_id": 4185485 | ||
}, | ||
recipients=recipients, | ||
start_time=time_delay, | ||
) | ||
``` | ||
3. Send email message from UniSender system template: | ||
|
||
``` python | ||
fixed_time = datetime.strptime('2020-02-07 17:00', '%Y-%m-%d %H:%M') | ||
|
||
create_email_campaign( | ||
email_type='system_template', | ||
email_data={ | ||
"sender_name": 'John Lenon', | ||
"sender_email": 'example_1@gmail.com', | ||
"system_template_id": 54485 | ||
}, | ||
recipients=recipients, | ||
start_time=fixed_time, | ||
timezone='UTC' | ||
) | ||
``` | ||
- **email_type** [str] - one of "html", "template", "system_template" | ||
- **email_data*** [dict] - email message data. Fields description see in ["createEmailMessage" docs](https://www.unisender.com/ru/support/api/messages/createemailmessage/) | ||
- **recipints*** [list] - recipient list, will be imported into the API as contacts | ||
- **start_time** [datetime] - mailing start time | ||
- **timezone** [str] - time zone that indicates propagation time. Available only "UTC" (default: time zone from your account settings) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import setuptools | ||
|
||
with open("README.md", "r") as fh: | ||
long_description = fh.read() | ||
|
||
setuptools.setup( | ||
name="python-unisender", | ||
version="0.0.1", | ||
author="Azat Zakirov", | ||
author_email="zakirmalay@gmail.com", | ||
description="python client for unisender API", | ||
long_description=long_description, | ||
long_description_content_type="text/markdown", | ||
url="https://github.com/pypa/python-unisender", | ||
packages=setuptools.find_packages(), | ||
classifiers=[ | ||
"Programming Language :: Python :: 3", | ||
"License :: OSI Approved :: MIT License", | ||
"Operating System :: OS Independent", | ||
], | ||
python_requires='>=3.6', | ||
install_requires=[ | ||
'requests' | ||
], | ||
|
||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from unisender.client import Client | ||
from unisender.simple_client import SimpleClient |
Oops, something went wrong.