Django Spread Integration
Project description
django-spread
Starting
These instructions will allow you to install the library in your python project.
Current features
- Get default payload.
- Create shipping.
- Get events.
- Get status.
Pre-requisitos
- Python >= 3.7
- Django >= 3
- requests >= 2
Installation
- To get the latest stable release from PyPi:
pip install django-spread
or
- From a build
git clone https://gitlab.com/linets/ecommerce/oms/integrations/django-spread
cd {{project}}
python setup.py sdist
and, install in your project django
pip install {{path}}/django-spread/dist/{{tar.gz file}}
- Settings in django project
DJANGO_SPREAD = {
'SPREAD': {
'BASE_URL': '<SPREAD_BASE_URL>',
'ID': '<SPREAD_ID>',
'SECRET': '<SPREAD_SECRET>',
}
}
Usage
-
Create instance to be sent
import json from types import SimpleNamespace dict_ = { 'reference': '99999', 'created_at': '12/12/21', 'shipping_date': '12/12/21', 'expiration_date': '26/12/21', 'tracking_code': '6075620-1', 'transport_guide_number': '1121632479536-01-1', 'purchase_number': 'CLV0048146676851-1', 'customer': { 'first_name': 'Marcos', 'last_name': 'Sac', 'full_name': 'Marcos Sac', 'phone': '932932932', 'email': 'test@gmail.com', 'rut': '16936195-9' }, 'address': { 'street': 'ALEJANDRO VENEGAS CADIZ', 'number': '513', 'unit': 'DEPTO 6A', 'full_address': 'ALEJANDRO VENEGAS CADIZ 513 DEPTO 6A' }, 'commune': { 'name': 'Aisen', 'code': '', 'zone_code': '11201', 'zone_post': 'WPA', }, 'location': { 'code': 'MONTANDON', 'name': 'MNN', }, 'region': { 'name': 'Aysén del General Carlos Ibáñez del Campo', 'code': '11', 'iso_code': 'CL-XI', } } instance = json.loads(json.dumps(dict_), object_hook=lambda attr: SimpleNamespace(**attr))
-
Get default payload:
from spread.handler import SpreadHandler
handler = SpreadHandler()
default_data = handler.get_default_payload(<instance>)
- Create shipping:
from spread.handler import SpreadHandler
handler = SpreadHandler()
default_data = handler.create_shipping(<default_data>)
- Get events:
from spread.handler import SpreadHandler
handler = SpreadHandler()
raw_data = {
'tracking_number': 999999,
'status': 'entregado',
'events': [{
'city': 'Santiago'
'state': 'RM',
'description': 'Llego al almacén',
'date': '12/12/2021'
}]
}
response = handler.get_events(raw_data)
Output:
[{
'city': 'Santiago'
'state': 'RM',
'description': 'Llego al almacén',
'date': '12/12/2021'
}]
- Get status and if "is_delivered":
from spread.handler import SpreadHandler
handler = SpreadHandler()
raw_data = {
'tracking_number': 999999,
'status': 'entregado',
'events': [{
'city': 'Santiago'
'state': 'RM',
'description': 'Llego al almacén',
'date': '12/12/2021'
}]
}
response = handler.get_status(raw_data)
Output:
('entregado', True)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
django-spread-1.0.0.tar.gz
(5.8 kB
view details)
File details
Details for the file django-spread-1.0.0.tar.gz
.
File metadata
- Download URL: django-spread-1.0.0.tar.gz
- Upload date:
- Size: 5.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.4.2 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 48f6b7a678cdc3f62581a21801bac402bfac43655d7be2985f4ee6fc3ec75dd9 |
|
MD5 | 246bb4f64963b2436ba7ef974fbbe056 |
|
BLAKE2b-256 | 05209ee2762e27ff98c94b1223021dd2b683d43bf40f9cc73ad492d06e117e0f |