diff --git a/README.md b/README.md index 7a2a76a..7528ab7 100644 --- a/README.md +++ b/README.md @@ -32,25 +32,37 @@ for page in client.products.all(paginate=True, limit=100) # Get specific product by id product = client.products.get(resource_id=1234) -# List product metafields for product id -metafields = client.products.metafields.all(resource_id=1234) - -# Get speficic metafield by id -metafield = client.products.metafields.all(resource_id=1234, sub_resource_id=5678) - # Create a product data = {"product":{"title":"Burton Custom Freestyle 151","body_html":"Good snowboard!","vendor":"Burton","product_type":"Snowboard","status":"draft"}} product = client.products.create(json=data) # Update product -product = client.products.create(resource_id=1234, json=data) +product = client.products.update(resource_id=1234, json=data) # Delete product -deleted = client.products.delete(resource=1234) +deleted = client.products.delete(resource_id=1234) # Count of products count = client.products.count() +# Get product metafields +metafields = client.products.metafields.all(resource_id=1234) + +# Get product metafield +metafield = client.products.metafields.get(resource_id=1234, sub_resource_id=5678) + +# Create product metafield +data = {"metafield": {"namespace": "warehouse", "key": "foo", "value": 25, "type": "integer"}} +metafield = client.products.metafields.create(resource_id=5678, json=data) + +# Update product metafield +data = {"metafield": {"value": 30}} +metafield = client.products.metafields.update(resource_id=1234, sub_resource_id=5678, json=data) + +# Delete product metafield +deleted = client.products.metafields.delete(resource_id=1234, sub_resource_id=5678) + + # Cancel order order = client.orders.cancel(resource_id=1234) diff --git a/VERSION b/VERSION index bcab45a..81340c7 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.0.3 +0.0.4 diff --git a/shopify_client/endpoint.py b/shopify_client/endpoint.py index dcc37c8..9ed2d62 100644 --- a/shopify_client/endpoint.py +++ b/shopify_client/endpoint.py @@ -63,8 +63,8 @@ def get(self, resource_id, **params): url = self.__build_url(resource_id=resource_id, **params) return self.client.parse_response(self.client.get(url)) - def create(self, json: dict): - url = self.__build_url() + def create(self, json: dict, **params): + url = self.__build_url(**params) return self.client.parse_response(self.client.post(url, json=json)) def update(self, resource_id, json, **params): diff --git a/tests/test_endpoint.py b/tests/test_endpoint.py index 4d5a2ee..fbde5e2 100644 --- a/tests/test_endpoint.py +++ b/tests/test_endpoint.py @@ -26,6 +26,31 @@ def test_build_url_with_params(endpoint): url = endpoint._Endpoint__build_url(resource_id=1, action="test", param="value") assert url == "test_endpoint/1/test.json?param=value" +def test_build_url_for_sub_endpoint_create(endpoint): + endpoint.sub_endpoint = "metafields" + url = endpoint._Endpoint__build_url(resource_id=1) + assert url == "test_endpoint/1/metafields.json" + +def test_build_url_for_sub_endpoint_get(endpoint): + endpoint.sub_endpoint = "metafields" + url = endpoint._Endpoint__build_url(resource_id=1, sub_resource_id=2) + assert url == "test_endpoint/1/metafields/2.json" + +def test_build_url_for_sub_endpoint_all(endpoint): + endpoint.sub_endpoint = "metafields" + url = endpoint._Endpoint__build_url(resource_id=1) + assert url == "test_endpoint/1/metafields.json" + +def test_build_url_for_sub_endpoint_update(endpoint): + endpoint.sub_endpoint = "metafields" + url = endpoint._Endpoint__build_url(resource_id=1, sub_resource_id=2) + assert url == "test_endpoint/1/metafields/2.json" + +def test_build_url_for_sub_endpoint_delete(endpoint): + endpoint.sub_endpoint = "metafields" + url = endpoint._Endpoint__build_url(resource_id=1, sub_resource_id=2) + assert url == "test_endpoint/1/metafields/2.json" + def test_get(endpoint, mock_client): mock_client.get.return_value = {"result": "success"} response = endpoint.get(1, param="value")