From 4a57cd3c6a0856d91ebf72828a350d5b63ef7a58 Mon Sep 17 00:00:00 2001 From: Gabriel Candal Date: Thu, 2 Sep 2021 17:45:59 +0100 Subject: [PATCH] feat: add inventory item API --- CHANGELOG.md | 2 +- src/shopify/__init__.py | 2 ++ src/shopify/base.py | 2 ++ src/shopify/inventory_item.py | 55 +++++++++++++++++++++++++++++++++++ 4 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 src/shopify/inventory_item.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 657206a..f6191bb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added -* +* Inventory Item API ### Changed diff --git a/src/shopify/__init__.py b/src/shopify/__init__.py index f4842ac..5c5e639 100644 --- a/src/shopify/__init__.py +++ b/src/shopify/__init__.py @@ -36,6 +36,7 @@ from . import base from . import cart +from . import inventory_item from . import location from . import order from . import product @@ -45,6 +46,7 @@ from .base import API, OAuthAPI from .cart import CartAPI +from .inventory_item import InventoryItemAPI from .location import LocationAPI from .order import OrderAPI from .product import ProductAPI diff --git a/src/shopify/base.py b/src/shopify/base.py index 075f560..b6d79fa 100644 --- a/src/shopify/base.py +++ b/src/shopify/base.py @@ -44,6 +44,7 @@ import appier from . import cart +from . import inventory_item from . import shop from . import order from . import product @@ -73,6 +74,7 @@ class API( appier.API, cart.CartAPI, + inventory_item.InventoryItemAPI, shop.ShopAPI, order.OrderAPI, product.ProductAPI, diff --git a/src/shopify/inventory_item.py b/src/shopify/inventory_item.py new file mode 100644 index 0000000..2a597b7 --- /dev/null +++ b/src/shopify/inventory_item.py @@ -0,0 +1,55 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +# Hive Shopify API +# Copyright (c) 2008-2020 Hive Solutions Lda. +# +# This file is part of Hive Shopify API. +# +# Hive Shopify API is free software: you can redistribute it and/or modify +# it under the terms of the Apache License as published by the Apache +# Foundation, either version 2.0 of the License, or (at your option) any +# later version. +# +# Hive Shopify API is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# Apache License for more details. +# +# You should have received a copy of the Apache License along with +# Hive Shopify API. If not, see . + +__author__ = "João Magalhães " +""" The author(s) of the module """ + +__version__ = "1.0.0" +""" The version of the module """ + +__revision__ = "$LastChangedRevision$" +""" The revision number of the module """ + +__date__ = "$LastChangedDate$" +""" The last change date of the module """ + +__copyright__ = "Copyright (c) 2008-2020 Hive Solutions Lda." +""" The copyright for the module """ + +__license__ = "Apache License, Version 2.0" +""" The license for the module """ + +class InventoryItemAPI(object): + + def list_inventory_items(self, *args, **kwargs): + url = self.base_url + "admin/inventory_items.json" + contents = self.get(url, **kwargs) + return contents["inventory_items"] + + def get_inventory_item(self, id): + url = self.base_url + "admin/inventory_items/%d.json" % id + contents = self.get(url) + return contents["inventory_item"] + + def update_inventory_item(self, id, inventory_item): + url = self.base_url + "admin/inventory_items/%d.json" % id + contents = self.put(url, data_j = dict(inventory_item = inventory_item)) + return contents["inventory_item"]