From af02613e76fec648c056ba50f8f2bc6ae624759f Mon Sep 17 00:00:00 2001 From: vlad Date: Thu, 18 Apr 2019 09:55:59 -0400 Subject: [PATCH 1/6] Allow implicit options to be passed into product.sku --- bigcommerce/resources/products.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bigcommerce/resources/products.py b/bigcommerce/resources/products.py index d569de9..e741066 100644 --- a/bigcommerce/resources/products.py +++ b/bigcommerce/resources/products.py @@ -48,11 +48,11 @@ def rules(self, id=None): else: return ProductRules.all(self.id, connection=self._connection) - def skus(self, id=None): + def skus(self, id=None, **kwargs): if id: - return ProductSkus.get(self.id, id, connection=self._connection) + return ProductSkus.get(self.id, id, connection=self._connection, **kwargs) else: - return ProductSkus.all(self.id, connection=self._connection) + return ProductSkus.all(self.id, connection=self._connection, **kwargs) def videos(self, id=None): if id: From 90639646fa0e6f8b34e447d138ba284c3d75a192 Mon Sep 17 00:00:00 2001 From: vlad Date: Fri, 24 May 2019 23:57:10 -0400 Subject: [PATCH 2/6] Add support for v3 - Pass through api_path object to connection - Append catalog word to resource url - Ignore meta field when returning response --- bigcommerce/api.py | 3 ++- bigcommerce/connection.py | 11 +++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/bigcommerce/api.py b/bigcommerce/api.py index 057a4d3..404a71c 100644 --- a/bigcommerce/api.py +++ b/bigcommerce/api.py @@ -5,7 +5,7 @@ class BigcommerceApi(object): - def __init__(self, host=None, basic_auth=None, + def __init__(self, host=None, api_path=None, basic_auth=None, client_id=None, store_hash=None, access_token=None, rate_limiting_management=None): self.api_service = os.getenv('BC_API_ENDPOINT', 'api.bigcommerce.com') self.auth_service = os.getenv('BC_AUTH_SERVICE', 'login.bigcommerce.com') @@ -14,6 +14,7 @@ def __init__(self, host=None, basic_auth=None, self.connection = connection.Connection(host, basic_auth) elif client_id and store_hash: self.connection = connection.OAuthConnection(client_id, store_hash, access_token, self.api_service, + api_path=api_path, rate_limiting_management=rate_limiting_management) else: raise Exception("Must provide either (client_id and store_hash) or (host and basic_auth)") diff --git a/bigcommerce/connection.py b/bigcommerce/connection.py index 7bffb89..ae28acb 100644 --- a/bigcommerce/connection.py +++ b/bigcommerce/connection.py @@ -53,6 +53,10 @@ def _run_method(self, method, url, data=None, query=None, headers=None): if headers is None: headers = {} + # Support v3 + if self.api_path and 'v3' in self.api_path: + url = 'catalog/{}'.format(url) + # make full path if not given if url and url[:4] != "http": if url[0] == '/': # can call with /resource if you want @@ -156,6 +160,9 @@ def _handle_response(self, url, res, suppress_empty=True): if res.status_code in (200, 201, 202): try: result = res.json() + # Support v3 + if self.api_path and 'v3' in self.api_path: + result = result['data'] #TODO ignore meta field for now except Exception as e: # json might be invalid, or store might be down e.message += " (_handle_response failed to decode JSON: " + str(res.content) + ")" raise # TODO better exception @@ -187,11 +194,11 @@ class OAuthConnection(Connection): """ def __init__(self, client_id, store_hash, access_token=None, host='api.bigcommerce.com', - api_path='/stores/{}/v2/{}', rate_limiting_management=None): + api_path=None, rate_limiting_management=None): self.client_id = client_id self.store_hash = store_hash self.host = host - self.api_path = api_path + self.api_path = api_path if api_path else "/stores/{}/v2/{}" self.timeout = 7.0 # can attach to session? self.rate_limiting_management = rate_limiting_management From c802fa84ee60772532ba761e961951cd7b863386 Mon Sep 17 00:00:00 2001 From: vlad Date: Sat, 25 May 2019 01:58:57 -0400 Subject: [PATCH 3/6] v3 add support for variants --- bigcommerce/resources/variants.py | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 bigcommerce/resources/variants.py diff --git a/bigcommerce/resources/variants.py b/bigcommerce/resources/variants.py new file mode 100644 index 0000000..4716664 --- /dev/null +++ b/bigcommerce/resources/variants.py @@ -0,0 +1,7 @@ +from .base import * + + +class Variants(ListableApiResource, CreateableApiResource, + UpdateableApiResource, DeleteableApiResource, + CollectionDeleteableApiResource, CountableApiResource): + resource_name = 'variants' From c124d74dcdcd18d8fca9206edbaf4c885ac8e72f Mon Sep 17 00:00:00 2001 From: vlad Date: Sat, 25 May 2019 02:19:56 -0400 Subject: [PATCH 4/6] Add Variants to init --- bigcommerce/resources/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/bigcommerce/resources/__init__.py b/bigcommerce/resources/__init__.py index 541fc4f..c5b0f0d 100644 --- a/bigcommerce/resources/__init__.py +++ b/bigcommerce/resources/__init__.py @@ -20,4 +20,5 @@ from .store import * from .tax_classes import * from .time import * +from .variants import * from .webhooks import * From 01a8307415652fd5a6e63550398f44f16d3fa842 Mon Sep 17 00:00:00 2001 From: vlad Date: Thu, 30 May 2019 01:52:38 -0400 Subject: [PATCH 5/6] Added get for variants --- bigcommerce/resources/products.py | 13 +++++++++++++ bigcommerce/resources/variants.py | 9 ++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/bigcommerce/resources/products.py b/bigcommerce/resources/products.py index e741066..b9e2a71 100644 --- a/bigcommerce/resources/products.py +++ b/bigcommerce/resources/products.py @@ -54,6 +54,12 @@ def skus(self, id=None, **kwargs): else: return ProductSkus.all(self.id, connection=self._connection, **kwargs) + def variants(self, id=None, **kwargs): + if id: + return ProductVariants.get(self.id, id, connection=self._connection, **kwargs) + else: + return ProductVariants.all(self.id, connection=self._connection, **kwargs) + def videos(self, id=None): if id: return ProductVideos.get(self.id, id, connection=self._connection) @@ -131,6 +137,13 @@ class ProductSkus(ListableApiSubResource, CreateableApiSubResource, parent_key = 'product_id' count_resource = 'products/skus' +class ProductVariants(ListableApiSubResource, CreateableApiSubResource, + UpdateableApiSubResource, DeleteableApiSubResource, + CollectionDeleteableApiSubResource, CountableApiSubResource): + resource_name = 'variants' + parent_resource = 'products' + parent_key = 'product_id' + count_resource = 'products/variants' class ProductVideos(ListableApiSubResource, CountableApiSubResource, CreateableApiSubResource, DeleteableApiSubResource, diff --git a/bigcommerce/resources/variants.py b/bigcommerce/resources/variants.py index 4716664..12cea16 100644 --- a/bigcommerce/resources/variants.py +++ b/bigcommerce/resources/variants.py @@ -1,7 +1,10 @@ from .base import * -class Variants(ListableApiResource, CreateableApiResource, - UpdateableApiResource, DeleteableApiResource, - CollectionDeleteableApiResource, CountableApiResource): +class Variants(ListableApiResource, CreateableApiSubResource, + UpdateableApiSubResource, DeleteableApiSubResource, + CollectionDeleteableApiSubResource, CountableApiSubResource): resource_name = 'variants' + parent_resource = 'products' + parent_key = 'product_id' + count_resource = 'products/variants' \ No newline at end of file From f4ca6e69e95d88930f207135b33e6b15720de08c Mon Sep 17 00:00:00 2001 From: vlad Date: Fri, 21 Jun 2019 15:06:59 -0400 Subject: [PATCH 6/6] Working copy --- bigcommerce/resources/products.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bigcommerce/resources/products.py b/bigcommerce/resources/products.py index b9e2a71..434b2bd 100644 --- a/bigcommerce/resources/products.py +++ b/bigcommerce/resources/products.py @@ -105,7 +105,9 @@ class ProductImages(ListableApiSubResource, CreateableApiSubResource, count_resource = 'products/images' -class ProductOptions(ListableApiSubResource): +class ProductOptions(ListableApiSubResource, CreateableApiSubResource, + UpdateableApiSubResource, DeleteableApiSubResource, + CollectionDeleteableApiSubResource, CountableApiSubResource): resource_name = 'options' parent_resource = 'products' parent_key = 'product_id'