diff --git a/CHANGELOG.md b/CHANGELOG.md index d6878b6..d769a34 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,16 +18,3 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed * - -## [0.2.1] - 2024-04-30 - -### Changed - -* Direct inclusion of pyi files in `setup.py` - -## [0.2.0] - 2024-04-20 - -### Changed - -* Sanitization of the code structure, making compliant with `black` -* Improved support for type hints diff --git a/setup.py b/setup.py index 7745a13..51f6a37 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ keywords="colony-print api", url="http://colony-print-api.hive.pt", zip_safe=False, - packages=["colony_print"], + packages=["colony_print", "colony_print.scripts"], test_suite="colony_print.test", package_dir={"": os.path.normpath("src")}, package_data={"colony_print": ["*.pyi"]}, diff --git a/src/colony_print/__init__.py b/src/colony_print/__init__.py index 9318819..ac27dce 100644 --- a/src/colony_print/__init__.py +++ b/src/colony_print/__init__.py @@ -2,5 +2,7 @@ # -*- coding: utf-8 -*- from . import base +from . import node -from .base import BASE_URL, API, Attachment, AttachmentPayload, Message, MessagePayload +from .base import BASE_URL, API, Ping +from .node import NodeAPI, Node diff --git a/src/colony_print/base.py b/src/colony_print/base.py index 2a3d099..4975b44 100644 --- a/src/colony_print/base.py +++ b/src/colony_print/base.py @@ -3,12 +3,14 @@ import appier +from .node import NodeAPI + BASE_URL = "https://print.bemisc.com/api/" """ The default base URL to be used when no other base URL value is provided to the constructor """ -class API(appier.API): +class API(appier.API, NodeAPI): """ Implementation of the Colony Print API specification for a simplified python client usage. @@ -42,23 +44,6 @@ def ping(self): contents = self.get(url, auth=False) return contents - def send(self, payload): - url = self.base_url + "send" - contents = self.post(url, data_j=payload) - return contents - - -class Attachment(dict): - pass - - -class AttachmentPayload(dict): - pass - - -class Message(dict): - pass - -class MessagePayload(dict): +class Ping(dict): pass diff --git a/src/colony_print/base.pyi b/src/colony_print/base.pyi index fa2d720..9859f20 100644 --- a/src/colony_print/base.pyi +++ b/src/colony_print/base.pyi @@ -1,58 +1,12 @@ -from typing import NotRequired, Sequence, TypedDict +from typing import TypedDict from appier import API as BaseAPI -BASE_URL: str = ... - -class Attachment(TypedDict): - name: str - data: str - mime: str - hash: str - etag: str - guid: str - engine: str +from .node import NodeAPI -class AttachmentPayload(TypedDict): - name: str - data: str - mime: NotRequired[str] - hash: NotRequired[str] - etag: NotRequired[str] - guid: NotRequired[str] - engine: NotRequired[str] - -class Message(TypedDict): - sender: str | None - receivers: Sequence[str] - cc: Sequence[str] - bcc: Sequence[str] - reply_to: Sequence[str] - subject: str - title: str - subtitle: str | None - contents: str - html: str - plain: str - copyright: str - logo_url: str | None - attachments: Sequence[Attachment] - id: str | None - inline: bool - style: str - mode: str +BASE_URL: str = ... -class MessagePayload(TypedDict): - receivers: Sequence[str] - subject: NotRequired[str] - title: NotRequired[str] - contents: NotRequired[str] - html: NotRequired[str] - plain: NotRequired[str] - copyright: NotRequired[str] - attachments: NotRequired[Sequence[AttachmentPayload]] - inline: NotRequired[bool] - style: NotRequired[str] - mode: NotRequired[str] +class Ping(TypedDict): + time: float -class API(BaseAPI): - def send(self, payload: MessagePayload) -> Message: ... +class API(BaseAPI, NodeAPI): + def ping(self) -> Ping: ... diff --git a/src/colony_print/node.py b/src/colony_print/node.py new file mode 100644 index 0000000..7b0106a --- /dev/null +++ b/src/colony_print/node.py @@ -0,0 +1,14 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + + +class NodeAPI(object): + + def list_nodes(self, *args, **kwargs): + url = self.base_url + "nodes" + contents = self.get(url, **kwargs) + return contents + + +class Node(dict): + pass diff --git a/src/colony_print/node.pyi b/src/colony_print/node.pyi new file mode 100644 index 0000000..b980f42 --- /dev/null +++ b/src/colony_print/node.pyi @@ -0,0 +1,14 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +from typing import NotRequired, Sequence, TypedDict + +class Node(TypedDict): + name: str + mode: str + location: NotRequired[str] + node_printer: NotRequired[str] + engines: Sequence[str] + +class NodeAPI: + def list_nodes(self) -> Sequence[Node]: ... diff --git a/src/colony_print/scripts/__init__.py b/src/colony_print/scripts/__init__.py index db35774..b56adca 100644 --- a/src/colony_print/scripts/__init__.py +++ b/src/colony_print/scripts/__init__.py @@ -1,6 +1,6 @@ #!/usr/bin/python # -*- coding: utf-8 -*- -from . import sender +from . import printer -from .sender import send +from .printer import print diff --git a/src/colony_print/scripts/sender.py b/src/colony_print/scripts/printer.py similarity index 65% rename from src/colony_print/scripts/sender.py rename to src/colony_print/scripts/printer.py index bff14cf..f37aaec 100644 --- a/src/colony_print/scripts/sender.py +++ b/src/colony_print/scripts/printer.py @@ -7,17 +7,14 @@ import colony_print -def send(*args, **kwargs): +def print(*args, **kwargs): api = colony_print.API() return api.send(kwargs) if __name__ == "__main__": - receivers = appier.conf("RECEIVERS", [], cast=list) - subject = appier.conf("SUBJECT", None) - title = appier.conf("TITLE", None) - contents = appier.conf("CONTENTS", None) - copyright = appier.conf("COPYRIGHT", None) + node = appier.conf("NODE", [], cast=list) + printer = appier.conf("PRINTER", None) kwargs = dict() if receivers: diff --git a/src/examples/app.py b/src/examples/app.py index df76b25..66b5e66 100644 --- a/src/examples/app.py +++ b/src/examples/app.py @@ -21,22 +21,10 @@ def ping(self): result = api.ping() return result - @appier.route("/send", "GET") - def send(self): - receivers = self.field("receivers", [], cast=list) - subject = self.field("subject", "Test email") - title = self.field("title", "Test email") - contents = self.field("contents", "Test email") - copyright = self.field("copyright", "Hive Solutions") - payload = dict( - receivers=receivers, - subject=subject, - title=title, - contents=contents, - copyright=copyright, - ) + @appier.route("/nodes", "GET") + def nodes(self): api = self.get_api() - result = api.send(payload) + result = api.list_nodes() return result def get_api(self): diff --git a/src/examples/base.pyi b/src/examples/base.pyi new file mode 100644 index 0000000..d3170e1 --- /dev/null +++ b/src/examples/base.pyi @@ -0,0 +1,6 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +import colony_print + +def get_api() -> colony_print.API: ...