Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add User-Agent header with sdk version #27

Merged
merged 2 commits into from
Feb 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions barte/__init__.py
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
7 changes: 7 additions & 0 deletions barte/__version__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from importlib.metadata import PackageNotFoundError, version


try:
__version__ = version("barte-python-sdk")
except PackageNotFoundError:
__version__ = "0.0.0-dev"
29 changes: 19 additions & 10 deletions barte/client.py
Original file line number Diff line number Diff line change
@@ -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,
)


Expand Down Expand Up @@ -44,9 +48,14 @@ 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
Expand Down