Skip to content

Commit 5bea694

Browse files
SP-685 Python - Implement Pydantic
1 parent c3d51a4 commit 5bea694

File tree

89 files changed

+1412
-9734
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+1412
-9734
lines changed

Pipfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ name = "pypi"
66
[packages]
77
ecdsa = "==0.18.0"
88
requests = "==2.31.0"
9+
pydantic = "==2.3.0"
910

1011
[dev-packages]
1112
black = "==23.7.0"

Pipfile.lock

Lines changed: 138 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/bitpay/clients/bill_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def create(
3636
:raises BillCreationException
3737
"""
3838
try:
39-
bill.set_token(self.__token_container.get_access_token(facade))
39+
bill.token = self.__token_container.get_access_token(facade)
4040
response_json = self.__bitpay_client.post(
4141
"bills", bill.to_json(), sign_request
4242
)
@@ -129,7 +129,7 @@ def update(self, bill: Bill, bill_id: str) -> Bill:
129129
:raises BillUpdateException
130130
"""
131131
try:
132-
if bill.get_token() is None:
132+
if bill.token is None:
133133
raise BillUpdateException("missing Bill token")
134134

135135
response_json = self.__bitpay_client.update(

src/bitpay/clients/currency_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def get_currencies(self) -> Dict[str, Currency]:
3333
currencies = {}
3434
for currency in response_json:
3535
currency_obj = Currency(**currency)
36-
currencies[currency_obj.get_code()] = currency_obj
36+
currencies[currency_obj.code] = currency_obj
3737
except Exception as exe:
3838
raise CurrencyQueryException(
3939
"failed to deserialize BitPay server response "

src/bitpay/clients/invoice_client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ def create(
5252
:raises InvoiceCreationException
5353
"""
5454
try:
55-
if invoice.get_guid() is None:
56-
invoice.set_guid(self.__guid_generator.execute())
55+
if invoice.guid is None:
56+
invoice.guid = self.__guid_generator.execute()
5757

58-
invoice.set_token(self.__token_container.get_access_token(facade))
58+
invoice.token = self.__token_container.get_access_token(facade)
5959
invoice_json = invoice.to_json()
6060
response_json = self.__bitpay_client.post(
6161
"invoices", invoice_json, sign_request

src/bitpay/clients/payout_client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def submit(self, payout: Payout) -> Payout:
3333
:raises PayoutCreationException
3434
"""
3535
try:
36-
payout.set_token(self.__token_container.get_access_token(Facade.PAYOUT))
36+
payout.token = self.__token_container.get_access_token(Facade.PAYOUT)
3737
response_json = self.__bitpay_client.post("payouts", payout.to_json(), True)
3838
except BitPayException as exe:
3939
raise PayoutCreationException(
@@ -206,8 +206,8 @@ def get_payout_group_response(
206206
for fail in response_json["failed"]:
207207
failed.append(PayoutGroupFailed(**fail))
208208

209-
return PayoutGroup(payouts, failed)
210-
except:
209+
return PayoutGroup(payouts=payouts, failed=failed)
210+
except Exception:
211211
raise PayoutException("Unable to parse payouts")
212212

213213
def create_group(self, payouts: List[Payout]) -> PayoutGroup:

src/bitpay/clients/payout_recipient_client.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ def submit(self, recipients: PayoutRecipients) -> List[PayoutRecipient]:
5050
:raises PayoutRecipientCreationException
5151
"""
5252
try:
53-
if recipients.get_guid() is None:
54-
recipients.set_guid(self.__guid_generator.execute())
53+
if recipients.guid is None:
54+
recipients.guid = self.__guid_generator.execute()
5555

56-
recipients.set_token(self.__token_container.get_access_token(Facade.PAYOUT))
56+
recipients.token = self.__token_container.get_access_token(Facade.PAYOUT)
5757

5858
response_json = self.__bitpay_client.post(
5959
"recipients", recipients.to_json(), True
@@ -158,8 +158,8 @@ def update(self, recipient_id: str, recipient: PayoutRecipient) -> PayoutRecipie
158158
:raises PayoutRecipientUpdateException
159159
"""
160160
try:
161-
recipient.set_token(self.__token_container.get_access_token(Facade.PAYOUT))
162-
recipient.set_guid(self.__guid_generator.execute())
161+
recipient.token = self.__token_container.get_access_token(Facade.PAYOUT)
162+
recipient.guid = self.__guid_generator.execute()
163163
response_json = self.__bitpay_client.update(
164164
"recipients/%s" % recipient_id, recipient.to_json()
165165
)

src/bitpay/clients/rate_client.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from typing import List
2-
31
from bitpay.clients.bitpay_client import BitPayClient
42
from bitpay.exceptions.bitpay_exception import BitPayException
53
from bitpay.exceptions.rate_query_exception import RateQueryException
@@ -34,7 +32,7 @@ def get_rates(self) -> Rates:
3432
rates = []
3533
for rate in response_json:
3634
rates.append(Rate(**rate))
37-
return Rates(rates)
35+
return Rates(rates=rates)
3836
except Exception as exe:
3937
raise RateQueryException(
4038
"failed to deserialize BitPay server response "
@@ -69,7 +67,7 @@ def get_currency_rates(self, base_currency: str) -> Rates:
6967
rates = []
7068
for rate in response_json:
7169
rates.append(Rate(**rate))
72-
return Rates(rates)
70+
return Rates(rates=rates)
7371
except Exception as exe:
7472
raise RateQueryException(
7573
"failed to deserialize BitPay server response "

0 commit comments

Comments
 (0)