alegrapy 0.0.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- alegra/__init__.py +6 -0
- alegra/actions.py +63 -0
- alegra/contacts.py +9 -0
- alegra/invoices.py +9 -0
- alegra/items.py +9 -0
- alegra/payments.py +9 -0
- alegra/session.py +60 -0
- alegrapy-0.0.2.dist-info/METADATA +88 -0
- alegrapy-0.0.2.dist-info/RECORD +12 -0
- alegrapy-0.0.2.dist-info/WHEEL +5 -0
- alegrapy-0.0.2.dist-info/licenses/LICENSE.txt +17 -0
- alegrapy-0.0.2.dist-info/top_level.txt +1 -0
alegra/__init__.py
ADDED
alegra/actions.py
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
from alegra.session import session
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class actions:
|
|
5
|
+
|
|
6
|
+
endpoint = ""
|
|
7
|
+
|
|
8
|
+
def __init__(self) -> None:
|
|
9
|
+
pass
|
|
10
|
+
|
|
11
|
+
def read(self, id, **kwargs):
|
|
12
|
+
"""search by id
|
|
13
|
+
|
|
14
|
+
Args:
|
|
15
|
+
id (int): query id
|
|
16
|
+
"""
|
|
17
|
+
params = {}
|
|
18
|
+
|
|
19
|
+
if kwargs:
|
|
20
|
+
params = kwargs
|
|
21
|
+
|
|
22
|
+
endpoint = f"{session.url}{self.endpoint}/{id}"
|
|
23
|
+
session.query('get', endpoint, params=params)
|
|
24
|
+
|
|
25
|
+
def list(self, start, limit, **kwargs):
|
|
26
|
+
"""search multiples results and returns a list
|
|
27
|
+
|
|
28
|
+
Args:
|
|
29
|
+
start (int): initial position
|
|
30
|
+
limit (int): list length (max 30)
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
endpoint = f"{session.url}{self.endpoint}"
|
|
34
|
+
params = {'start': start,
|
|
35
|
+
'limit': limit,
|
|
36
|
+
'order_direction': 'ASC',
|
|
37
|
+
'order_field': 'id'
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if kwargs:
|
|
41
|
+
params.update(kwargs)
|
|
42
|
+
|
|
43
|
+
session.query('get', endpoint, params=params)
|
|
44
|
+
|
|
45
|
+
def create(self, params):
|
|
46
|
+
"""send information to create in alegra
|
|
47
|
+
|
|
48
|
+
Args:
|
|
49
|
+
params (dict): data to create
|
|
50
|
+
"""
|
|
51
|
+
|
|
52
|
+
endpoint = f"{session.url}{self.endpoint}"
|
|
53
|
+
session.query('post', endpoint, params=params)
|
|
54
|
+
|
|
55
|
+
def delete(self, id):
|
|
56
|
+
"""delete by id
|
|
57
|
+
|
|
58
|
+
Args:
|
|
59
|
+
id (int): query id
|
|
60
|
+
"""
|
|
61
|
+
|
|
62
|
+
endpoint = f"{session.url}{self.endpoint}/{id}"
|
|
63
|
+
session.query('get', endpoint)
|
alegra/contacts.py
ADDED
alegra/invoices.py
ADDED
alegra/items.py
ADDED
alegra/payments.py
ADDED
alegra/session.py
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
from requests import request
|
|
2
|
+
import logging
|
|
3
|
+
import base64
|
|
4
|
+
import json
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
logging.basicConfig(level=logging.INFO,
|
|
8
|
+
format="%(asctime)s - %(levelname)s - %(message)s",
|
|
9
|
+
filename="alegra.log",
|
|
10
|
+
filemode="a")
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class session():
|
|
14
|
+
|
|
15
|
+
user = None
|
|
16
|
+
token = None
|
|
17
|
+
url = "https://api.alegra.com/api/v1/"
|
|
18
|
+
headers = {'Accept': 'application/json',
|
|
19
|
+
'Content-type': 'application/json'}
|
|
20
|
+
|
|
21
|
+
@classmethod
|
|
22
|
+
def create_auth(self) -> None:
|
|
23
|
+
"""return authorization"""
|
|
24
|
+
|
|
25
|
+
api_key = base64.b64encode(
|
|
26
|
+
f"{self.user}:{self.token}".encode()).decode()
|
|
27
|
+
self.headers['Authorization'] = f"Basic {api_key}"
|
|
28
|
+
|
|
29
|
+
@classmethod
|
|
30
|
+
def query(self, method, url, data={}, params={}) -> dict:
|
|
31
|
+
"""quey method
|
|
32
|
+
|
|
33
|
+
Args:
|
|
34
|
+
method (str): send query method (get,post,delete)
|
|
35
|
+
url (str): endpoint
|
|
36
|
+
data (dict, optional): query data. Defaults to {}.
|
|
37
|
+
params (dict, optional): query params. Defaults to {}.
|
|
38
|
+
|
|
39
|
+
Returns:
|
|
40
|
+
(dict, None): if it's correct returns sever answer, for other hand
|
|
41
|
+
returns None
|
|
42
|
+
"""
|
|
43
|
+
|
|
44
|
+
self.create_auth()
|
|
45
|
+
|
|
46
|
+
response = request(method,
|
|
47
|
+
url,
|
|
48
|
+
params=params,
|
|
49
|
+
headers=self.headers)
|
|
50
|
+
|
|
51
|
+
short_url = url.replace("https://api.alegra.com/api/v1", "")
|
|
52
|
+
|
|
53
|
+
if response.status_code == 200:
|
|
54
|
+
|
|
55
|
+
logging.info(f"{method} - {short_url} - Successful!")
|
|
56
|
+
return json.loads(response.text)
|
|
57
|
+
|
|
58
|
+
logging.warning(
|
|
59
|
+
f"{method} - {short_url} - {response.json()['message']}")
|
|
60
|
+
return None
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: AlegraPy
|
|
3
|
+
Version: 0.0.2
|
|
4
|
+
Summary: Este paquete nos permite consumir el API de Alegra
|
|
5
|
+
Home-page: https://github.com/andresroh/alegrapy_package
|
|
6
|
+
Author: Camilo Andrés Rodríguez Higuera
|
|
7
|
+
Author-email: andres.roh@gmail.com
|
|
8
|
+
License: MIT
|
|
9
|
+
Keywords: python,alegra,alegra.com
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Topic :: Software Development :: Build Tools
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
License-File: LICENSE.txt
|
|
17
|
+
Requires-Dist: requests
|
|
18
|
+
Dynamic: author
|
|
19
|
+
Dynamic: author-email
|
|
20
|
+
Dynamic: classifier
|
|
21
|
+
Dynamic: description
|
|
22
|
+
Dynamic: description-content-type
|
|
23
|
+
Dynamic: home-page
|
|
24
|
+
Dynamic: keywords
|
|
25
|
+
Dynamic: license
|
|
26
|
+
Dynamic: license-file
|
|
27
|
+
Dynamic: requires-dist
|
|
28
|
+
Dynamic: summary
|
|
29
|
+
|
|
30
|
+
# AlegraPy
|
|
31
|
+
|
|
32
|
+
Este paquete nos permite consumir el API del la plataforma de facturacion Alegra mediante python 🐍
|
|
33
|
+
|
|
34
|
+
## Características
|
|
35
|
+
|
|
36
|
+
- Permite leer facturas, pagos, productos, contactos
|
|
37
|
+
- Permite crear facturas, pagos, productos, contactos
|
|
38
|
+
- Permite borrar facturas, pagos, productos, contactos
|
|
39
|
+
|
|
40
|
+
## Instalación y uso
|
|
41
|
+
|
|
42
|
+
### 1. Obtener token de acceso
|
|
43
|
+
Debes seguir los siguientes pasos para obtener el token de acceso:
|
|
44
|
+
|
|
45
|
+
- Ingresar a la aplicación de [Alegra](https://www.alegra.com/).
|
|
46
|
+
- Haz clic sobre el vínculo "Configuración" en la parte superior derecha de la pantalla de Alegra y haz clic en la sección "API - Integraciones con otros sistemas"
|
|
47
|
+
- En la nueva pantalla puedes encontrar el correo con el cual debes acceder al API y el token. Si aún no cuentas con un token puedes generarlo también.
|
|
48
|
+
|
|
49
|
+
### 2. Instalación
|
|
50
|
+
|
|
51
|
+
En construcción...
|
|
52
|
+
|
|
53
|
+
### 3. Uso
|
|
54
|
+
|
|
55
|
+
Un ejemplo para usar este paquete
|
|
56
|
+
|
|
57
|
+
```py
|
|
58
|
+
from alegra import invoices,contacts, session
|
|
59
|
+
|
|
60
|
+
session.user = "your_email@domnain.com"
|
|
61
|
+
session.token = "your_token"
|
|
62
|
+
|
|
63
|
+
invoice = invoices()
|
|
64
|
+
invoice.read(1,fields='pdf')
|
|
65
|
+
invoice.list(0,3)
|
|
66
|
+
|
|
67
|
+
contact = contacts()
|
|
68
|
+
contact.read(12)
|
|
69
|
+
contact.list(0,2)
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Créditos
|
|
73
|
+
|
|
74
|
+
- Camilo Andrés Rodriguez
|
|
75
|
+
|
|
76
|
+
## referencias
|
|
77
|
+
|
|
78
|
+
- https://developer.alegra.com/
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
## Licencia
|
|
82
|
+
|
|
83
|
+
Este proyecto está bajo la Licencia [MIT].
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
¡Puedes personalizarlo según las necesidades específicas de tu proyecto!
|
|
88
|
+
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
alegra/__init__.py,sha256=ZNmGQkGaMXxq_0OwfgOfjIrBH1aoZdJZWsasVBgZulE,212
|
|
2
|
+
alegra/actions.py,sha256=7C0vyZlNwNTh3blODaTnmUhVh4TlAGoi1WcHJBeaJZA,1419
|
|
3
|
+
alegra/contacts.py,sha256=q4_c4S4Edg1H_od2o19PENp3YkHG_0erHUP8uLrFOgs,135
|
|
4
|
+
alegra/invoices.py,sha256=vHX8fazWVlzvTXaULlKuQZuZCqLHnRIDhVznc-S_lLE,135
|
|
5
|
+
alegra/items.py,sha256=p6XrQTREQGBXVVgVNRWLUeikzoGaLhJp_Du54aOr_a4,129
|
|
6
|
+
alegra/payments.py,sha256=nWhEuEnvpN7PQ98oQnTl5hAOxlJ90YfMtOwsjI9Eovk,135
|
|
7
|
+
alegra/session.py,sha256=agEie78O6kYpPR4TCm4ElaKE6d0Pk0ZMDbBXtHNH-_g,1706
|
|
8
|
+
alegrapy-0.0.2.dist-info/licenses/LICENSE.txt,sha256=fSCsNmX_pZQVlBLk2vaRzGewh15Mbn49u6XFBeR_EQQ,1084
|
|
9
|
+
alegrapy-0.0.2.dist-info/METADATA,sha256=QPwhmwAtqP_uKCPM3cV3jMQ5jwrt-_cKk4iae7P99So,2241
|
|
10
|
+
alegrapy-0.0.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
11
|
+
alegrapy-0.0.2.dist-info/top_level.txt,sha256=NcYktmnWNtk9MEfrDm6zdm260Udm6SmW6gEczIgEefw,7
|
|
12
|
+
alegrapy-0.0.2.dist-info/RECORD,,
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
Copyright (c) 2023 Camilo Andrés Rodriguez Higuera
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
The above copyright notice and this permission notice shall be included in all
|
|
10
|
+
copies or substantial portions of the Software.
|
|
11
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
12
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
13
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
14
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
15
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
16
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
17
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
alegra
|