Skip to content

Commit

Permalink
Merge pull request #209 from websideproject/dev
Browse files Browse the repository at this point in the history
Exclude None from data and query models
  • Loading branch information
bgervan authored Jan 14, 2024
2 parents 3b5831f + 6b1ed4a commit c3a5833
Showing 1 changed file with 68 additions and 40 deletions.
108 changes: 68 additions & 40 deletions paddle_billing_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ def __init__(

def create_product(self, data: ProductRequest) -> ProductResponse:
"""Create a product"""
return self.post(self.endpoints.create_product, dict(data))
return self.post(
self.endpoints.create_product, data.model_dump(exclude_none=True)
)

def get_product(self, product_id: str) -> ProductResponse:
"""Get a product"""
Expand All @@ -114,13 +116,14 @@ def list_products(
"""List all products"""
return self.get(
dict(paginate)["next"] if paginate else self.endpoints.list_products,
params=dict(query_params),
params=query_params.model_dump(exclude_none=True),
)

def update_product(self, product_id: str, data: ProductRequest) -> ProductResponse:
"""Update a product"""
return self.patch(
self.endpoints.update_product.format(product_id=product_id), dict(data)
self.endpoints.update_product.format(product_id=product_id),
data.model_dump(exclude_none=True),
)

"""
Expand All @@ -129,7 +132,10 @@ def update_product(self, product_id: str, data: ProductRequest) -> ProductRespon

def create_price(self, data: PriceRequest) -> PriceResponse:
"""Create a price"""
return self.post(self.endpoints.create_price, dict(data))
return self.post(
self.endpoints.create_price,
data.model_dump(exclude_none=True),
)

def get_price(self, price_id: str) -> PriceResponse:
"""Get a price"""
Expand All @@ -143,13 +149,14 @@ def list_prices(
"""List all prices"""
return self.get(
dict(paginate)["next"] if paginate else self.endpoints.list_prices,
params=dict(query_params),
params=query_params.model_dump(exclude_none=True),
)

def update_price(self, price_id: str, data: PriceRequest) -> PriceResponse:
"""Update a price"""
return self.patch(
self.endpoints.update_price.format(price_id=price_id), dict(data)
self.endpoints.update_price.format(price_id=price_id),
data.model_dump(exclude_none=True),
)

"""
Expand All @@ -158,7 +165,10 @@ def update_price(self, price_id: str, data: PriceRequest) -> PriceResponse:

def create_discount(self, data: DiscountRequest) -> DiscountResponse:
"""Create a discount"""
return self.post(self.endpoints.create_discount, dict(data))
return self.post(
self.endpoints.create_discount,
data.model_dump(exclude_none=True),
)

def get_discount(self, discount_id: str) -> DiscountResponse:
"""Get a discount"""
Expand All @@ -172,15 +182,16 @@ def list_discounts(
"""List all discounts"""
return self.get(
dict(paginate)["next"] if paginate else self.endpoints.list_discounts,
params=dict(query_params),
params=query_params.model_dump(exclude_none=True),
)

def update_discount(
self, discount_id: str, data: DiscountRequest
) -> DiscountResponse:
"""Update a discount"""
return self.patch(
self.endpoints.update_discount.format(discount_id=discount_id), dict(data)
self.endpoints.update_discount.format(discount_id=discount_id),
data.model_dump(exclude_none=True),
)

"""
Expand All @@ -189,7 +200,10 @@ def update_discount(

def create_customer(self, data: CustomerRequest) -> CustomerResponse:
"""Create a customer"""
return self.post(self.endpoints.create_customer, dict(data))
return self.post(
self.endpoints.create_customer,
data.model_dump(exclude_none=True),
)

def get_customer(self, customer_id: str) -> CustomerResponse:
"""Get a customer"""
Expand All @@ -203,23 +217,25 @@ def list_customers(
"""List all customers"""
return self.get(
dict(paginate)["next"] if paginate else self.endpoints.list_customers,
params=dict(query_params),
params=query_params.model_dump(exclude_none=True),
)

def update_customer(
self, customer_id: str, data: CustomerRequest
) -> CustomerResponse:
"""Update a customer"""
return self.patch(
self.endpoints.update_customer.format(customer_id=customer_id), dict(data)
self.endpoints.update_customer.format(customer_id=customer_id),
data.model_dump(exclude_none=True),
)

def list_customer_credit_balances(
self, query_params: CustomerBalancesQueryParams = CustomerBalancesQueryParams()
) -> CustomerBalancesResponse:
"""List credit balances for a customer"""
return self.get(
self.endpoints.list_customer_credit_balances, params=dict(query_params)
self.endpoints.list_customer_credit_balances,
params=query_params.model_dump(exclude_none=True),
)

"""
Expand All @@ -232,7 +248,7 @@ def create_address_for_customer(
"""Create an address for a customer"""
return self.post(
self.endpoints.create_address_for_customer.format(customer_id=customer_id),
dict(data),
data.model_dump(exclude_none=True),
)

def get_address_for_customer(
Expand All @@ -258,7 +274,7 @@ def list_addresses_for_customer(
else self.endpoints.list_addresses_for_customer.format(
customer_id=customer_id
),
params=dict(query_params),
params=query_params.model_dump(exclude_none=True),
)

def update_address_for_customer(
Expand All @@ -269,7 +285,7 @@ def update_address_for_customer(
self.endpoints.update_address_for_customer.format(
customer_id=customer_id, address_id=address_id
),
dict(data),
data.model_dump(exclude_none=True),
)

"""
Expand All @@ -282,7 +298,7 @@ def create_business_for_customer(
"""Create a business for a customer"""
return self.post(
self.endpoints.create_business_for_customer.format(customer_id=customer_id),
dict(data),
data.model_dump(exclude_none=True),
)

def get_business_for_customer(
Expand All @@ -308,7 +324,7 @@ def list_businesses_for_customer(
else self.endpoints.list_businesses_for_customer.format(
customer_id=customer_id
),
params=dict(query_params),
params=query_params.model_dump(exclude_none=True),
)

def update_business_for_customer(
Expand All @@ -319,7 +335,7 @@ def update_business_for_customer(
self.endpoints.update_business_for_customer.format(
customer_id=customer_id, business_id=business_id
),
dict(data),
data.model_dump(exclude_none=True),
)

"""
Expand All @@ -333,7 +349,9 @@ def create_transaction(
) -> TransactionResponse:
"""Create a transaction"""
return self.post(
self.endpoints.create_transaction, dict(data), params=dict(query_params)
self.endpoints.create_transaction,
data.model_dump(exclude_none=True),
params=query_params.model_dump(exclude_none=True),
)

def get_transaction(
Expand All @@ -344,7 +362,7 @@ def get_transaction(
"""Get a transaction"""
return self.get(
self.endpoints.get_transaction.format(transaction_id=transaction_id),
params=dict(query_params),
params=query_params.model_dump(exclude_none=True),
)

def list_transactions(
Expand All @@ -355,7 +373,7 @@ def list_transactions(
"""List all transactions"""
return self.get(
dict(paginate)["next"] if paginate else self.endpoints.list_transactions,
params=dict(query_params),
params=query_params.model_dump(exclude_none=True),
)

def update_transaction(
Expand All @@ -367,8 +385,8 @@ def update_transaction(
"""Update a transaction"""
return self.patch(
self.endpoints.update_transaction.format(transaction_id=transaction_id),
dict(data),
params=dict(query_params),
data.model_dump(exclude_none=True),
params=query_params.model_dump(exclude_none=True),
)

def preview_transaction(
Expand All @@ -378,12 +396,17 @@ def preview_transaction(
) -> TransactionPreviewResponse:
"""Preview a transaction"""
return self.post(
self.endpoints.preview_transaction, dict(data), params=dict(query_params)
self.endpoints.preview_transaction,
data.model_dump(exclude_none=True),
params=query_params.model_dump(exclude_none=True),
)

def preview_prices(self, data: TransactionRequest) -> TransactionResponse:
"""Preview prices"""
return self.post(self.endpoints.preview_prices, dict(data))
return self.post(
self.endpoints.preview_prices,
data.model_dump(exclude_none=True),
)

def get_pdf_for_transaction(self, transaction_id: str) -> TransactionPdfResponse:
"""Get a PDF for a transaction"""
Expand All @@ -409,7 +432,7 @@ def list_subscriptions(
"""List all subscriptions"""
return self.get(
dict(paginate)["next"] if paginate else self.endpoints.list_subscriptions,
params=dict(query_params),
params=query_params.model_dump(exclude_none=True),
)

def preview_update_subscription(
Expand All @@ -420,7 +443,7 @@ def preview_update_subscription(
self.endpoints.preview_update_subscription.format(
subscription_id=subscription_id
),
dict(data),
data.model_dump(exclude_none=True),
)

def update_subscription(
Expand All @@ -429,7 +452,7 @@ def update_subscription(
"""Update a subscription"""
return self.patch(
self.endpoints.update_subscription.format(subscription_id=subscription_id),
dict(data),
data.model_dump(exclude_none=True),
)

def unschedule_pause_from_subscription(
Expand Down Expand Up @@ -459,7 +482,7 @@ def preview_one_time_charge(
self.endpoints.preview_one_time_charge.format(
subscription_id=subscription_id
),
dict(data),
data.model_dump(exclude_none=True),
)

def create_one_time_charge(
Expand All @@ -470,7 +493,7 @@ def create_one_time_charge(
self.endpoints.create_one_time_charge.format(
subscription_id=subscription_id
),
dict(data),
data.model_dump(exclude_none=True),
)

def activate_trialing_subscription(
Expand All @@ -481,7 +504,7 @@ def activate_trialing_subscription(
self.endpoints.activate_trialing_subscription.format(
subscription_id=subscription_id
),
dict(data),
data.model_dump(exclude_none=True),
)

def pause_subscription(
Expand All @@ -490,7 +513,7 @@ def pause_subscription(
"""Pause a subscription"""
return self.post(
self.endpoints.pause_subscription.format(subscription_id=subscription_id),
dict(data),
data.model_dump(),
)

def resume_subscription(
Expand All @@ -499,7 +522,7 @@ def resume_subscription(
"""Resume a subscription"""
return self.post(
self.endpoints.resume_subscription.format(subscription_id=subscription_id),
dict(data),
data.model_dump(exclude_none=True),
)

def cancel_subscription(
Expand All @@ -508,7 +531,7 @@ def cancel_subscription(
"""Cancel a subscription"""
return self.post(
self.endpoints.cancel_subscription.format(subscription_id=subscription_id),
dict(data),
data.model_dump(exclude_none=True),
)

"""
Expand All @@ -517,7 +540,9 @@ def cancel_subscription(

def create_adjustment(self, data: AdjustmentRequest) -> AdjustmentResponse:
"""Create a customer"""
return self.post(self.endpoints.create_adjustment, dict(data))
return self.post(
self.endpoints.create_adjustment, data.model_dump(exclude_none=True)
)

def list_adjustments(
self,
Expand All @@ -527,7 +552,7 @@ def list_adjustments(
"""List all customers"""
return self.get(
dict(paginate)["next"] if paginate else self.endpoints.list_adjustments,
params=dict(query_params),
params=query_params.model_dump(exclude_none=True),
)

"""
Expand All @@ -552,7 +577,10 @@ def create_notification_setting(
self, data: NotificationSettingRequest
) -> NotificationSettingResponse:
"""Create notification settings"""
return self.post(self.endpoints.create_notification_setting, dict(data))
return self.post(
self.endpoints.create_notification_setting,
data.model_dump(exclude_none=True),
)

def get_notification_setting(
self, notification_setting_id: str
Expand All @@ -576,7 +604,7 @@ def update_notification_setting(
self.endpoints.update_notification_setting.format(
notification_setting_id=notification_setting_id
),
dict(data),
data.model_dump(exclude_none=True),
)

def delete_notification_setting(
Expand Down Expand Up @@ -607,7 +635,7 @@ def list_notifications(
"""List all notifications"""
return self.get(
dict(paginate)["next"] if paginate else self.endpoints.list_notifications,
params=dict(query_params),
params=query_params.model_dump(exclude_none=True),
)

def replay_notification(self, notification_id: str) -> NotificationReplayResponse:
Expand Down

0 comments on commit c3a5833

Please sign in to comment.