idi-manageorders-sdk 0.1.0__py3-none-any.whl
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.
- idi_manageorders_sdk-0.1.0.dist-info/METADATA +29 -0
- idi_manageorders_sdk-0.1.0.dist-info/RECORD +7 -0
- idi_manageorders_sdk-0.1.0.dist-info/WHEEL +4 -0
- idi_manageorders_sdk-0.1.0.dist-info/licenses/LICENSE +21 -0
- manageorders_sdk/__init__.py +5 -0
- manageorders_sdk/client.py +73 -0
- manageorders_sdk/models.py +65 -0
@@ -0,0 +1,29 @@
|
|
1
|
+
Metadata-Version: 2.3
|
2
|
+
Name: idi-manageorders-sdk
|
3
|
+
Version: 0.1.0
|
4
|
+
Summary: ShopWorks ManageOrders API SDK
|
5
|
+
Project-URL: repository, https://github.com/impressdesigns/manageorders-sdk/
|
6
|
+
Project-URL: documentation, https://impressdesigns.dev/manageorders-sdk/
|
7
|
+
Author-email: Bradley Reynolds <bradley.reynolds@impressdesigns.com>
|
8
|
+
License: MIT
|
9
|
+
Requires-Python: >=3.10
|
10
|
+
Requires-Dist: httpx>=0.27.2
|
11
|
+
Requires-Dist: pydantic>=2.9.2
|
12
|
+
Provides-Extra: dev
|
13
|
+
Requires-Dist: mypy>=1.10.1; extra == 'dev'
|
14
|
+
Requires-Dist: nox>=2024.4.15; extra == 'dev'
|
15
|
+
Requires-Dist: pre-commit>=3.7.1; extra == 'dev'
|
16
|
+
Requires-Dist: ruff>=0.5.2; extra == 'dev'
|
17
|
+
Provides-Extra: docs
|
18
|
+
Requires-Dist: furo>=2024.5.6; extra == 'docs'
|
19
|
+
Requires-Dist: releases>=2.1.1; extra == 'docs'
|
20
|
+
Requires-Dist: sphinx-autoapi>=3.1.2; extra == 'docs'
|
21
|
+
Requires-Dist: sphinx>=7.4.4; extra == 'docs'
|
22
|
+
Provides-Extra: tests
|
23
|
+
Requires-Dist: coverage>=7.6.1; extra == 'tests'
|
24
|
+
Requires-Dist: pytest-randomly>=3.15.0; extra == 'tests'
|
25
|
+
Requires-Dist: pytest>=8.2.2; extra == 'tests'
|
26
|
+
Description-Content-Type: text/markdown
|
27
|
+
|
28
|
+
# manageorders-api
|
29
|
+
ShopWorks ManageOrders API SDK
|
@@ -0,0 +1,7 @@
|
|
1
|
+
manageorders_sdk/__init__.py,sha256=5G4EMub-py1c_ZkvluDFHRMd4ZQouTmY6GnYIhUgpXc,112
|
2
|
+
manageorders_sdk/client.py,sha256=pjgmZCWx9W_MUVB8Oe6FCfT1-AFsgU6d0PV99mQbc2A,2048
|
3
|
+
manageorders_sdk/models.py,sha256=PwDTA9iRNqscI1NoFr7m9fxQkInGPvqFfFDyLJGKZX4,2334
|
4
|
+
idi_manageorders_sdk-0.1.0.dist-info/METADATA,sha256=7nuYsNB3fbh4H15C3_6dtgOMUwhM_UolUwt45fWjO3g,1104
|
5
|
+
idi_manageorders_sdk-0.1.0.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
|
6
|
+
idi_manageorders_sdk-0.1.0.dist-info/licenses/LICENSE,sha256=1zNUC2AzIRNS7IofenZpZXrr3jt93nq3Bc10iocHjRo,1072
|
7
|
+
idi_manageorders_sdk-0.1.0.dist-info/RECORD,,
|
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2024 Impress Designs
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
@@ -0,0 +1,73 @@
|
|
1
|
+
"""Interacting with ManageOrders API."""
|
2
|
+
|
3
|
+
from datetime import UTC, datetime, timedelta
|
4
|
+
from typing import Any, Self
|
5
|
+
|
6
|
+
import httpx
|
7
|
+
from httpx import Response
|
8
|
+
|
9
|
+
from .models import Order
|
10
|
+
|
11
|
+
|
12
|
+
class ManageOrdersClient:
|
13
|
+
"""A class wrapping interaction with ManageOrders API."""
|
14
|
+
|
15
|
+
def __init__(
|
16
|
+
self,
|
17
|
+
username: str,
|
18
|
+
password: str,
|
19
|
+
) -> None:
|
20
|
+
"""Initialize the ManageOrdersClient class."""
|
21
|
+
self.base_url = "https://manageordersapi.com"
|
22
|
+
self.username = username
|
23
|
+
self.password = password
|
24
|
+
self.token = ""
|
25
|
+
self.token_expires_at = datetime.now(tz=UTC)
|
26
|
+
|
27
|
+
def _update_token(self: Self) -> None:
|
28
|
+
"""Update the OAUTH token."""
|
29
|
+
if self.token_expires_at > datetime.now(tz=UTC):
|
30
|
+
return
|
31
|
+
|
32
|
+
auth_dict = {
|
33
|
+
"username": self.username,
|
34
|
+
"password": self.password,
|
35
|
+
}
|
36
|
+
response = httpx.post(f"{self.base_url}/v1/manageorders/signin", json=auth_dict)
|
37
|
+
response.raise_for_status()
|
38
|
+
data = response.json()
|
39
|
+
self.token = data["access_token"]
|
40
|
+
self.token_expires_at = datetime.now(tz=UTC) + timedelta(hours=1)
|
41
|
+
|
42
|
+
def _make_request(
|
43
|
+
self,
|
44
|
+
method: str,
|
45
|
+
path: str,
|
46
|
+
params: dict[str, Any] | None = None,
|
47
|
+
json: dict[str, Any] | None = None,
|
48
|
+
) -> Response:
|
49
|
+
"""Make a request to Core."""
|
50
|
+
self._update_token()
|
51
|
+
|
52
|
+
headers = {"Authorization": "Bearer " + self.token}
|
53
|
+
|
54
|
+
args = {
|
55
|
+
"url": self.base_url + path,
|
56
|
+
"method": method,
|
57
|
+
"headers": headers,
|
58
|
+
}
|
59
|
+
|
60
|
+
if params is not None:
|
61
|
+
args["params"] = params
|
62
|
+
|
63
|
+
if json is not None:
|
64
|
+
args["json"] = json
|
65
|
+
|
66
|
+
return httpx.request(**args) # type: ignore[arg-type]
|
67
|
+
|
68
|
+
def upload_order(
|
69
|
+
self,
|
70
|
+
order: Order,
|
71
|
+
) -> Response:
|
72
|
+
"""Upload an order to ManageOrders."""
|
73
|
+
return self._make_request("POST", "/onsite/order-push", json=order.model_dump(by_alias=True, exclude_none=True))
|
@@ -0,0 +1,65 @@
|
|
1
|
+
"""Models."""
|
2
|
+
|
3
|
+
from typing import Literal
|
4
|
+
|
5
|
+
from pydantic import BaseModel, Field
|
6
|
+
|
7
|
+
DATE_REGEX = "[0-9]{2}/[0-9]{2}/[0-9]{4}|[0-9]{2}"
|
8
|
+
|
9
|
+
|
10
|
+
class Design(BaseModel):
|
11
|
+
"""Design."""
|
12
|
+
|
13
|
+
design_number: int = Field(serialization_alias="id_Design")
|
14
|
+
design_type: int = Field(serialization_alias="id_DesignType")
|
15
|
+
|
16
|
+
|
17
|
+
class LineItem(BaseModel):
|
18
|
+
"""LineItem."""
|
19
|
+
|
20
|
+
part_number: str = Field(serialization_alias="PartNumber")
|
21
|
+
product_class: int = Field(serialization_alias="id_ProductClass")
|
22
|
+
quantity: int = Field(serialization_alias="Qty")
|
23
|
+
|
24
|
+
external_shipment_id: str = Field(serialization_alias="ExtShipID")
|
25
|
+
|
26
|
+
|
27
|
+
class Address(BaseModel):
|
28
|
+
"""Address."""
|
29
|
+
|
30
|
+
external_shipment_id: str | None = Field(None, serialization_alias="ExtShipID")
|
31
|
+
|
32
|
+
shipping_method: str | None = Field(None, serialization_alias="ShipMethod")
|
33
|
+
|
34
|
+
company: str | None = Field(None, serialization_alias="ShipCompany")
|
35
|
+
address1: str | None = Field(None, serialization_alias="ShipAddress01")
|
36
|
+
address2: str | None = Field(None, serialization_alias="ShipAddress02")
|
37
|
+
city: str | None = Field(None, serialization_alias="ShipCity")
|
38
|
+
state: str | None = Field(None, serialization_alias="ShipState")
|
39
|
+
postal_code: str | None = Field(None, serialization_alias="ShipZip")
|
40
|
+
country: str | None = Field(None, serialization_alias="ShipCountry")
|
41
|
+
|
42
|
+
|
43
|
+
class Note(BaseModel):
|
44
|
+
"""Note."""
|
45
|
+
|
46
|
+
note: str
|
47
|
+
type_: Literal["Notes To Production", "Notes To Shipping"] = Field(serialization_alias="Type")
|
48
|
+
|
49
|
+
|
50
|
+
class Order(BaseModel):
|
51
|
+
"""Order."""
|
52
|
+
|
53
|
+
external_order_id: str = Field(serialization_alias="ExtOrderID")
|
54
|
+
external_source: str = Field(serialization_alias="ExtSource")
|
55
|
+
|
56
|
+
order_type: int = Field(serialization_alias="id_OrderType")
|
57
|
+
employee_created_by: int = Field(serialization_alias="id_EmpCreatedBy")
|
58
|
+
customer_id: int = Field(serialization_alias="id_Customer")
|
59
|
+
customer_purchase_order: str = Field(serialization_alias="CustomerPurchaseOrder")
|
60
|
+
ship_date: str = Field(pattern=DATE_REGEX, serialization_alias="date_OrderRequestedToShip")
|
61
|
+
|
62
|
+
designs: list[Design] = Field(serialization_alias="Designs")
|
63
|
+
line_items: list[LineItem] = Field(serialization_alias="LineItems")
|
64
|
+
addresses: list[Address] = Field(serialization_alias="ShippingAddresses")
|
65
|
+
notes: list[Note] = Field(serialization_alias="Notes")
|