From 30dc291bc899fd1bae1d42cfd395bf669c7842b1 Mon Sep 17 00:00:00 2001 From: Walison Filipe Date: Tue, 25 Feb 2025 10:25:40 -0300 Subject: [PATCH 1/2] Add User-Agent header with sdk version --- barte/__init__.py | 7 +++---- barte/__version__.py | 7 +++++++ barte/client.py | 27 +++++++++++++++++---------- 3 files changed, 27 insertions(+), 14 deletions(-) create mode 100644 barte/__version__.py diff --git a/barte/__init__.py b/barte/__init__.py index e7f61d4..ca2bfe7 100644 --- a/barte/__init__.py +++ b/barte/__init__.py @@ -1,14 +1,13 @@ from .client import BarteClient from .models import ( - Charge, CardToken, - Refund, - PixCharge, + Charge, Customer, + PixCharge, PixQRCode, + Refund, ) -__version__ = "0.1.0" __all__ = [ "BarteClient", diff --git a/barte/__version__.py b/barte/__version__.py new file mode 100644 index 0000000..a7e2ff5 --- /dev/null +++ b/barte/__version__.py @@ -0,0 +1,7 @@ +from importlib.metadata import PackageNotFoundError, version + + +try: + __version__ = version("barte-python-sdk") +except PackageNotFoundError: + __version__ = "0.0.0-dev" diff --git a/barte/client.py b/barte/client.py index f4a38ec..8e1ea59 100644 --- a/barte/client.py +++ b/barte/client.py @@ -1,20 +1,24 @@ -from decimal import Decimal -from typing import Dict, Any, Optional, Union, List from dataclasses import asdict +from decimal import Decimal +from typing import Any, Dict, List, Optional, Union + import requests from dacite import from_dict + +from barte.__version__ import __version__ + from .models import ( - Charge, - CardToken, - Refund, - PixCharge, DACITE_CONFIG, Buyer, BuyerList, - Order, + CardToken, + Charge, ChargeList, - OrderPayload, InstallmentOption, + Order, + OrderPayload, + PixCharge, + Refund, ) @@ -44,9 +48,12 @@ def __init__(self, api_key: str, environment: str = "production"): if environment == "production" else "https://sandbox-api.barte.com" ) - self.headers = {"X-Token-Api": api_key, "Content-Type": "application/json"} self.session = requests.Session() - self.session.headers.update(self.headers) + self.session.headers.update({ + "X-Token-Api": api_key, + "Content-Type": "application/json", + "User-Agent": f"barte-client/python version={__version__}" + }) BarteClient._instance = self @classmethod From c8b9f43b87a23ef78effb750b4b517af6ef12c27 Mon Sep 17 00:00:00 2001 From: Walison Filipe Date: Tue, 25 Feb 2025 10:26:47 -0300 Subject: [PATCH 2/2] Format --- barte/client.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/barte/client.py b/barte/client.py index 8e1ea59..f8e6cc0 100644 --- a/barte/client.py +++ b/barte/client.py @@ -49,11 +49,13 @@ def __init__(self, api_key: str, environment: str = "production"): else "https://sandbox-api.barte.com" ) self.session = requests.Session() - self.session.headers.update({ - "X-Token-Api": api_key, - "Content-Type": "application/json", - "User-Agent": f"barte-client/python version={__version__}" - }) + self.session.headers.update( + { + "X-Token-Api": api_key, + "Content-Type": "application/json", + "User-Agent": f"barte-client/python version={__version__}", + } + ) BarteClient._instance = self @classmethod