Skip to content

Commit f1ff024

Browse files
committed
SP-1029 - Add X-BitPay-Platform-Info header
1 parent ef16e8a commit f1ff024

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/bitpay/client.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ def __init__(
6161
)
6262

6363
@staticmethod
64-
def create_pos_client(pos_token: str, environment: Environment = Environment.PROD): # type: ignore
64+
def create_pos_client(pos_token: str, environment: Environment = Environment.PROD, platform_info: Optional[str] = None): # type: ignore
6565
token_container = TokenContainer()
6666
token_container.add_pos(pos_token)
6767

68-
bitpay_client = BitPayClient(Client.get_base_url(environment))
68+
bitpay_client = BitPayClient(Client.get_base_url(environment), None, platform_info)
6969

7070
return Client(bitpay_client, token_container, GuidGenerator())
7171

@@ -75,14 +75,15 @@ def create_client( # type: ignore
7575
token_container: TokenContainer,
7676
environment: Environment = Environment.PROD,
7777
proxy: Optional[str] = None,
78+
platform_info: Optional[str] = None
7879
):
7980
"""
8081
:raises BitPayGenericException
8182
"""
8283
try:
8384
base_url = Client.get_base_url(environment)
8485
ec_key = Client.get_ec_key(private_key_or_private_key_path)
85-
bitpay_client = BitPayClient(base_url, ec_key, proxy)
86+
bitpay_client = BitPayClient(base_url, ec_key, proxy, platform_info)
8687
guid_generator = GuidGenerator()
8788

8889
return Client(bitpay_client, token_container, guid_generator)
@@ -92,7 +93,7 @@ def create_client( # type: ignore
9293
)
9394

9495
@staticmethod
95-
def create_client_by_config_file_path(config_file_path: str): # type: ignore
96+
def create_client_by_config_file_path(config_file_path: str, platform_info: Optional[str] = None): # type: ignore
9697
"""
9798
:raises BitPayGenericException
9899
"""
@@ -125,7 +126,7 @@ def create_client_by_config_file_path(config_file_path: str): # type: ignore
125126
environment = Environment.PROD
126127

127128
return Client.create_client(
128-
private_key_or_private_key_path, token_container, environment, proxy
129+
private_key_or_private_key_path, token_container, environment, proxy, platform_info
129130
)
130131
except Exception as exe:
131132
BitPayExceptionProvider.throw_generic_exception_with_message(

src/bitpay/clients/bitpay_client.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@ class BitPayClient:
1717
__base_url: str
1818
__ec_key: Optional[str] = None
1919
__proxy: Optional[str] = None
20+
__platform_info: Optional[str] = None
2021

2122
def __init__(
22-
self, base_url: str, ec_key: Optional[str] = None, proxy: Optional[str] = None
23+
self, base_url: str, ec_key: Optional[str] = None, proxy: Optional[str] = None, platform_info: Optional[str] = None
2324
):
2425
self.__base_url = base_url
2526
self.__ec_key = ec_key
2627
self.__proxy = proxy
28+
self.__platform_info = platform_info
2729
self.init()
2830

2931
def init(self) -> None:
@@ -38,6 +40,9 @@ def init(self) -> None:
3840
if self.__proxy is not None:
3941
self.__headers["proxy"] = self.__proxy
4042

43+
if self.__platform_info is not None:
44+
self.__headers["x-bitpay-platform-info"] = self.__platform_info
45+
4146
def post(
4247
self, uri: str, form_data: Any = {}, signature_required: bool = True
4348
) -> Response:

0 commit comments

Comments
 (0)