woocommerce-api 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- woocommerce_api-0.1.0/PKG-INFO +7 -0
- woocommerce_api-0.1.0/README.md +0 -0
- woocommerce_api-0.1.0/pyproject.toml +9 -0
- woocommerce_api-0.1.0/setup.cfg +4 -0
- woocommerce_api-0.1.0/src/__init__.py +0 -0
- woocommerce_api-0.1.0/src/brands/__init__.py +0 -0
- woocommerce_api-0.1.0/src/brands/handler.py +55 -0
- woocommerce_api-0.1.0/src/brands/models/__init__.py +0 -0
- woocommerce_api-0.1.0/src/brands/models/brand_create.py +12 -0
- woocommerce_api-0.1.0/src/categories/__init__.py +0 -0
- woocommerce_api-0.1.0/src/categories/handler.py +82 -0
- woocommerce_api-0.1.0/src/categories/models/__init__.py +3 -0
- woocommerce_api-0.1.0/src/categories/models/category_create.py +13 -0
- woocommerce_api-0.1.0/src/images/__init__.py +3 -0
- woocommerce_api-0.1.0/src/images/models/__init__.py +0 -0
- woocommerce_api-0.1.0/src/images/models/image.py +9 -0
- woocommerce_api-0.1.0/src/woocommerce_api.egg-info/PKG-INFO +7 -0
- woocommerce_api-0.1.0/src/woocommerce_api.egg-info/SOURCES.txt +19 -0
- woocommerce_api-0.1.0/src/woocommerce_api.egg-info/dependency_links.txt +1 -0
- woocommerce_api-0.1.0/src/woocommerce_api.egg-info/requires.txt +1 -0
- woocommerce_api-0.1.0/src/woocommerce_api.egg-info/top_level.txt +4 -0
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
from typing import Union
|
|
2
|
+
import requests
|
|
3
|
+
|
|
4
|
+
from src.brands.models.brand_create import BrandCreate
|
|
5
|
+
|
|
6
|
+
class BrandHandler:
|
|
7
|
+
|
|
8
|
+
def __init__(self, woocommerce_base_url: str, woocommerce_auth: tuple[str]):
|
|
9
|
+
"""Class to handle category's operations
|
|
10
|
+
|
|
11
|
+
Args:
|
|
12
|
+
woocommerce_base_url (str): The base URL of your woocommerce instance www.<...>.com. Do not add the /wp-json/...
|
|
13
|
+
woocommerce_auth (tuple[str]): A tuple with auth key from woocommerce in the type (ck_...,cs_...)
|
|
14
|
+
"""
|
|
15
|
+
self.woocommerce_url = woocommerce_base_url
|
|
16
|
+
self.formatted_url = f'{self.woocommerce_url}/wp-json/wc/v3/products/brands'
|
|
17
|
+
self.auth = woocommerce_auth
|
|
18
|
+
|
|
19
|
+
def retrieve_brands(self) -> list[dict]:
|
|
20
|
+
res = requests.get(
|
|
21
|
+
url=self.formatted_url,
|
|
22
|
+
auth=self.auth
|
|
23
|
+
)
|
|
24
|
+
return res.json()
|
|
25
|
+
|
|
26
|
+
def retrieve_single_brand(self, brand: Union[str, int]) -> dict:
|
|
27
|
+
res = requests.get(
|
|
28
|
+
url=f'{self.formatted_url}/{brand}',
|
|
29
|
+
)
|
|
30
|
+
return res.json()
|
|
31
|
+
|
|
32
|
+
def create_brand(self, brand_reate: BrandCreate) -> dict:
|
|
33
|
+
res = requests.post(
|
|
34
|
+
url=self.formatted_url,
|
|
35
|
+
auth=self.auth,
|
|
36
|
+
data=brand_reate
|
|
37
|
+
)
|
|
38
|
+
return res.json()
|
|
39
|
+
|
|
40
|
+
def delete_brand(self, id: int) -> dict:
|
|
41
|
+
res = requests.delete(
|
|
42
|
+
url=f'{self.formatted_url}/{id}',
|
|
43
|
+
auth=self.auth
|
|
44
|
+
)
|
|
45
|
+
return res.json()
|
|
46
|
+
|
|
47
|
+
def assign_brand_to_product(self, product_id: int, brands_id: list[int]) -> dict:
|
|
48
|
+
res = requests.put(
|
|
49
|
+
url=f'{self.woocommerce_url}//wp-json/wc/v3/products/{product_id}',
|
|
50
|
+
auth=self.auth,
|
|
51
|
+
data={
|
|
52
|
+
"brands":brands_id
|
|
53
|
+
}
|
|
54
|
+
)
|
|
55
|
+
return res.json()
|
|
File without changes
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
from dataclasses import dataclass, field
|
|
2
|
+
from src.images import ImageProperties
|
|
3
|
+
|
|
4
|
+
@dataclass
|
|
5
|
+
class BrandCreate:
|
|
6
|
+
name: str = field(metadata={"doc": "Category name.mandatory"})
|
|
7
|
+
slug: str = field(metadata={"doc": "An alphanumeric identifier for the resource unique to its type."})
|
|
8
|
+
parent: int = field(metadata={"doc": "The ID for the parent of the resource."})
|
|
9
|
+
description: str = field(metadata={"doc": "HTML description of the resource."})
|
|
10
|
+
display: str = field(metadata={"doc": "Category archive display type. Options: default, products, subcategories and both. Default is default."})
|
|
11
|
+
image: ImageProperties = field(metadata={"doc": "See ImageProperties doc."})
|
|
12
|
+
menu_order: int = field(metadata={"doc": "Menu order, used to custom sort the resource."})
|
|
File without changes
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
from typing import Optional
|
|
2
|
+
import requests
|
|
3
|
+
from src.categories.models import CreateCategory
|
|
4
|
+
|
|
5
|
+
class CategoryHandler:
|
|
6
|
+
|
|
7
|
+
def __init__(self, woocommerce_base_url: str, woocommerce_auth: tuple[str]):
|
|
8
|
+
"""Class to handle category's operations
|
|
9
|
+
|
|
10
|
+
Args:
|
|
11
|
+
woocommerce_base_url (str): The base URL of your woocommerce instance www.<...>.com. Do not add the /wp-json/...
|
|
12
|
+
woocommerce_auth (tuple[str]): A tuple with auth key from woocommerce in the type (ck_...,cs_...)
|
|
13
|
+
"""
|
|
14
|
+
self.woocommerce_url = woocommerce_base_url
|
|
15
|
+
self.formatted_url = f'{self.woocommerce_url}/wp-json/wc/v3/products/categories'
|
|
16
|
+
self.auth = woocommerce_auth
|
|
17
|
+
|
|
18
|
+
def retrieve_categories(self, extra_data: bool = False) -> list[dict]:
|
|
19
|
+
"""Retrieves categories data from the API
|
|
20
|
+
|
|
21
|
+
Args:
|
|
22
|
+
extra_data (bool, optional): If False, it will return only name and ID, if set to true it will retrieve all the category properties. Defaults to False.
|
|
23
|
+
|
|
24
|
+
Returns:
|
|
25
|
+
list[dict]: Output from the API
|
|
26
|
+
"""
|
|
27
|
+
res = requests.get(
|
|
28
|
+
url=self.formatted_url,
|
|
29
|
+
auth=self.auth
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
data = res.json()
|
|
33
|
+
|
|
34
|
+
if not extra_data:
|
|
35
|
+
data = [{"ID":d['id'], "Name": d['name'], "Slug":d["slug"]} for d in data]
|
|
36
|
+
|
|
37
|
+
return data
|
|
38
|
+
|
|
39
|
+
def create_category(self, category: CreateCategory) -> dict:
|
|
40
|
+
res = requests.post(
|
|
41
|
+
url= self.formatted_url,
|
|
42
|
+
auth=self.auth,
|
|
43
|
+
data=category
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
return res.json()
|
|
47
|
+
|
|
48
|
+
def retrive_category_by_id(self, id: int) -> dict:
|
|
49
|
+
res = requests.get(
|
|
50
|
+
url=f'{self.formatted_url}/{id}'
|
|
51
|
+
)
|
|
52
|
+
return res.json()
|
|
53
|
+
|
|
54
|
+
def update_category(self, id: int, **kwargs) -> dict:
|
|
55
|
+
res = requests.put(
|
|
56
|
+
url=f'{self.formatted_url}/{id}',
|
|
57
|
+
json=kwargs
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
return res.json()
|
|
61
|
+
|
|
62
|
+
def delete_category(self, id: int, force: bool) -> dict:
|
|
63
|
+
res = requests.delete(
|
|
64
|
+
url=f'{self.formatted_url}/{id}',
|
|
65
|
+
params={'force':force}
|
|
66
|
+
)
|
|
67
|
+
return res.json()
|
|
68
|
+
|
|
69
|
+
def batch_update(self, create: Optional[list[dict]] = None, update: Optional[list[dict]] = None, delete: Optional[list[int]] = None):
|
|
70
|
+
d = {}
|
|
71
|
+
if create:
|
|
72
|
+
d["create"] = create
|
|
73
|
+
if update:
|
|
74
|
+
d["update"] = update
|
|
75
|
+
if delete:
|
|
76
|
+
d["delete"] = delete
|
|
77
|
+
res = requests.post(
|
|
78
|
+
url=f'{self.formatted_url}/batch',
|
|
79
|
+
data=d
|
|
80
|
+
)
|
|
81
|
+
return res.json()
|
|
82
|
+
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
from dataclasses import dataclass, field
|
|
2
|
+
from src.images import ImageProperties
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
@dataclass
|
|
6
|
+
class CreateCategory:
|
|
7
|
+
name: str = field(metadata={"doc": "Category name.mandatory"})
|
|
8
|
+
slug: str = field(metadata={"doc": "An alphanumeric identifier for the resource unique to its type."})
|
|
9
|
+
parent: int = field(metadata={"doc": "The ID for the parent of the resource."})
|
|
10
|
+
description: str = field(metadata={"doc": "HTML description of the resource."})
|
|
11
|
+
display: str = field(metadata={"doc": "Category archive display type. Options: default, products, subcategories and both. Default is default."})
|
|
12
|
+
image: ImageProperties = field(metadata={"doc": "See ImageProperties doc."})
|
|
13
|
+
menu_order: int = field(metadata={"doc": "Menu order, used to custom sort the resource."})
|
|
File without changes
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
pyproject.toml
|
|
3
|
+
src/__init__.py
|
|
4
|
+
src/brands/__init__.py
|
|
5
|
+
src/brands/handler.py
|
|
6
|
+
src/brands/models/__init__.py
|
|
7
|
+
src/brands/models/brand_create.py
|
|
8
|
+
src/categories/__init__.py
|
|
9
|
+
src/categories/handler.py
|
|
10
|
+
src/categories/models/__init__.py
|
|
11
|
+
src/categories/models/category_create.py
|
|
12
|
+
src/images/__init__.py
|
|
13
|
+
src/images/models/__init__.py
|
|
14
|
+
src/images/models/image.py
|
|
15
|
+
src/woocommerce_api.egg-info/PKG-INFO
|
|
16
|
+
src/woocommerce_api.egg-info/SOURCES.txt
|
|
17
|
+
src/woocommerce_api.egg-info/dependency_links.txt
|
|
18
|
+
src/woocommerce_api.egg-info/requires.txt
|
|
19
|
+
src/woocommerce_api.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
requests>=2.32.5
|