Skip to content

Commit

Permalink
Merge pull request #126 from swlodarski-sumoheavy/6.1.x
Browse files Browse the repository at this point in the history
SP-1029 - Add X-BitPay-Platform-Info header
  • Loading branch information
bobbrodie authored Sep 3, 2024
2 parents ef16e8a + 088afef commit 94878a6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
17 changes: 12 additions & 5 deletions src/bitpay/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,13 @@ def __init__(
)

@staticmethod
def create_pos_client(pos_token: str, environment: Environment = Environment.PROD): # type: ignore
def create_pos_client(pos_token: str, environment: Environment = Environment.PROD, platform_info: Optional[str] = None): # type: ignore
token_container = TokenContainer()
token_container.add_pos(pos_token)

bitpay_client = BitPayClient(Client.get_base_url(environment))
bitpay_client = BitPayClient(
Client.get_base_url(environment), None, platform_info
)

return Client(bitpay_client, token_container, GuidGenerator())

Expand All @@ -75,14 +77,15 @@ def create_client( # type: ignore
token_container: TokenContainer,
environment: Environment = Environment.PROD,
proxy: Optional[str] = None,
platform_info: Optional[str] = None,
):
"""
:raises BitPayGenericException
"""
try:
base_url = Client.get_base_url(environment)
ec_key = Client.get_ec_key(private_key_or_private_key_path)
bitpay_client = BitPayClient(base_url, ec_key, proxy)
bitpay_client = BitPayClient(base_url, ec_key, proxy, platform_info)
guid_generator = GuidGenerator()

return Client(bitpay_client, token_container, guid_generator)
Expand All @@ -92,7 +95,7 @@ def create_client( # type: ignore
)

@staticmethod
def create_client_by_config_file_path(config_file_path: str): # type: ignore
def create_client_by_config_file_path(config_file_path: str, platform_info: Optional[str] = None): # type: ignore
"""
:raises BitPayGenericException
"""
Expand Down Expand Up @@ -125,7 +128,11 @@ def create_client_by_config_file_path(config_file_path: str): # type: ignore
environment = Environment.PROD

return Client.create_client(
private_key_or_private_key_path, token_container, environment, proxy
private_key_or_private_key_path,
token_container,
environment,
proxy,
platform_info,
)
except Exception as exe:
BitPayExceptionProvider.throw_generic_exception_with_message(
Expand Down
11 changes: 10 additions & 1 deletion src/bitpay/clients/bitpay_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,19 @@ class BitPayClient:
__base_url: str
__ec_key: Optional[str] = None
__proxy: Optional[str] = None
__platform_info: Optional[str] = None

def __init__(
self, base_url: str, ec_key: Optional[str] = None, proxy: Optional[str] = None
self,
base_url: str,
ec_key: Optional[str] = None,
proxy: Optional[str] = None,
platform_info: Optional[str] = None,
):
self.__base_url = base_url
self.__ec_key = ec_key
self.__proxy = proxy
self.__platform_info = platform_info
self.init()

def init(self) -> None:
Expand All @@ -38,6 +44,9 @@ def init(self) -> None:
if self.__proxy is not None:
self.__headers["proxy"] = self.__proxy

if self.__platform_info is not None:
self.__headers["x-bitpay-platform-info"] = self.__platform_info

def post(
self, uri: str, form_data: Any = {}, signature_required: bool = True
) -> Response:
Expand Down

0 comments on commit 94878a6

Please sign in to comment.