SatelCreative / spylib

A library to facilitate interfacing with Shopify's API
https://satelcreative.github.io/spylib
MIT License
3 stars 2 forks source link

Reorganize module structure to be more consistent #129

Closed hillairet closed 2 years ago

hillairet commented 2 years ago

The current file/module organization lacks coherence at this time. It's not clear why session_token.py belongs in "utils" for example.

I think we have a natural organization for the files that would match the documentation menu to highlight the Shopify features handled by SPyLib:

spylib
├── admin_api.py       # Instead of tokens.py
├── hmac.py            # Exposing to the user more directly. Maybe should be added to docs menu.
├── oauth
├── session_token.py
├── webhook.py

This way we have a natural organization for future Shopify features that SPyLib handles and it makes the imports a lot more logical:

from spylib.session_token import SessionToken

Also we should reorganize the webhooks into functions to avoid making the Token class bloated. We can simply have:

from spylib import webhook

webhook_response = webhook.create_http(
    offlinetoken=offlinetoken,
    topics=['orders/create'],
    callback_url=`https://example.com/webhooks
)

Originally posted by @hillairet in https://github.com/SatelCreative/spylib/discussions/127

Additionally let's not expose the functions and classes at the top level of the package. In other words this should not be possible:

from spylib import OfflineTokenABC

Instead we can only do:

from spylib.admin_api import OfflineTokenABC