This repository has been archived by the owner on May 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prices.get shall be our first victim
- Loading branch information
1 parent
e388876
commit f53430e
Showing
6 changed files
with
197 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
|
||
setup( | ||
name='paddle-billing-python-sdk', | ||
version='0.0.1a20', | ||
version='0.0.1a21', | ||
author='Corey Regan', | ||
author_email='[email protected]', | ||
description='A Python wrapper for the Paddle Billing API', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import logging | ||
|
||
|
||
class NullHandler(logging.Handler): | ||
def emit(self, record): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from enum import StrEnum | ||
|
||
|
||
class Includes(StrEnum): | ||
Product = 'product' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from src.Entities.Shared.CatalogType import CatalogType | ||
from src.Entities.Shared.Status import Status | ||
|
||
from src.Exceptions.SdkExceptions.InvalidArgumentException import InvalidArgumentException | ||
|
||
from src.Resources.Prices.Operations.List.Includes import Includes | ||
|
||
|
||
class ListPrices: | ||
def __init__(self, pager=None, includes=None, ids=None, types=None, product_ids=None, statuses=None, recurring=None): | ||
self.pager = pager | ||
self.includes = includes if includes is not None else [] | ||
self.ids = ids if ids is not None else [] | ||
self.types = types if types is not None else [] | ||
self.product_ids = product_ids if product_ids is not None else [] | ||
self.statuses = statuses if statuses is not None else [] | ||
self.recurring = recurring | ||
|
||
# Validation | ||
if any(not isinstance(include, Includes) for include in self.includes): | ||
raise InvalidArgumentException('includes', Includes.__name__) | ||
if any(not isinstance(i, str) for i in self.ids): | ||
raise InvalidArgumentException('ids', 'string') | ||
if any(not isinstance(t, CatalogType) for t in self.types): | ||
raise InvalidArgumentException('types', CatalogType.__name__) | ||
if any(not isinstance(pid, str) for pid in self.product_ids): | ||
raise InvalidArgumentException('productIds', 'string') | ||
if any(not isinstance(status, Status) for status in self.statuses): | ||
raise InvalidArgumentException('statuses', Status.__name__) | ||
|
||
|
||
def get_parameters(self): | ||
enum_stringify = lambda enum: enum.value # noqa E731 | ||
|
||
parameters = {} | ||
if self.pager: | ||
parameters.update(self.pager.get_parameters()) | ||
if self.includes: | ||
parameters['include'] = ','.join(map(enum_stringify, self.includes)) | ||
if self.ids: | ||
parameters['id'] = ','.join(self.ids) | ||
if self.types: | ||
parameters['type'] = ','.join(map(enum_stringify, self.types)) | ||
if self.product_ids: | ||
parameters['product_id'] = ','.join(self.product_ids) | ||
if self.statuses: | ||
parameters['status'] = ','.join(map(enum_stringify, self.statuses)) | ||
if self.recurring is not None: | ||
parameters['recurring'] = 'true' if self.recurring else 'false' | ||
|
||
return parameters |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
from src.ResponseParser import ResponseParser | ||
|
||
from src.Entities.PriceWithIncludes import PriceWithIncludes | ||
|
||
from src.Entities.Collections.Paginator import Paginator | ||
from src.Entities.Collections.PriceWithIncludesCollection import PriceWithIncludesCollection | ||
|
||
from src.Entities.Shared.Status import Status | ||
|
||
# from src.Resources.Prices.Operations.CreatePrice import CreatePrice | ||
from src.Resources.Prices.Operations.ListPrices import ListPrices | ||
# from src.Resources.Prices.Operations.UpdatePrice import UpdatePrice | ||
|
||
|
||
class PricesClient: | ||
def __init__(self, client): | ||
self.client = client | ||
|
||
|
||
def list(self, list_operation: ListPrices = None): | ||
if list_operation is None: | ||
list_operation = ListPrices() | ||
|
||
response = self.client.get_raw('/prices', list_operation.get_parameters()) | ||
parser = ResponseParser(response) | ||
return PriceWithIncludesCollection.from_list(parser.get_data(), Paginator(self.client, parser.get_pagination(), PriceWithIncludesCollection)) | ||
|
||
|
||
def get(self, price_id: str, includes = None): | ||
if includes is None: | ||
includes = [] | ||
|
||
# Validate 'includes' items and build parameters | ||
params = {'include': ','.join(include.value for include in includes)} if includes else {} | ||
response = self.client.get_raw(f"/prices/{price_id}", params) | ||
parser = ResponseParser(response) | ||
|
||
return PriceWithIncludes.from_dict(parser.get_data()) | ||
|
||
|
||
# def create(self, create_operation: CreatePrice): | ||
# response = self.client.post_raw('/prices', create_operation.get_parameters()) | ||
# parser = ResponseParser(response) | ||
# | ||
# return PriceWithIncludes.from_dict(parser.get_data()) | ||
# | ||
# | ||
# def update(self, price_id: str, operation: UpdatePrice): | ||
# response = self.client.patch_raw(f"/prices/{price_id}", operation.get_parameters()) | ||
# parser = ResponseParser(response) | ||
# | ||
# return PriceWithIncludes.from_dict(parser.get_data()) | ||
# | ||
# | ||
# def archive(self, price_id: str): | ||
# operation = UpdatePrice(status=Status.Archived) | ||
# | ||
# return self.update(price_id, operation) |