diff --git a/README.md b/README.md index 36817a2..8efb7e8 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Install is either via pip or cloning the repository. From pip: ```sh -python3 -m pip install thothlibrary==0.9.1 +python3 -m pip install thothlibrary==0.10.0 ``` Or from the repo: @@ -23,7 +23,7 @@ pip3 install -r ./requirements.txt ```python from thothlibrary import ThothClient -thoth = ThothClient(version="0.6.0") +thoth = ThothClient() print(thoth.works()) ``` @@ -90,7 +90,7 @@ python3 -m thothrest.cli work onix_3.0::project_muse e0f748b2-984f-45cc-8b9e-139 ``` ## Thoth Django -The thothdjango folder includes models, an import routine, subject-code support, and admin procedures to use Thoth in a django app. The import provides unidirectional synchronization from remote Thoth imports to a local database for use in a Django app. +The thothdjango folder includes models, an import routine, subject-code support, and admin procedures to use Thoth in a django app. The import provides unidirectional synchronization from remote Thoth imports to a local database for use in a Django app. ## Test Suite Tests for GraphQL queries are versioned in the thoth-[ver] folder of thothlibrary. @@ -106,4 +106,6 @@ The Thoth API is not yet considered stable and functionality changes between ver 4. Run genjson.sh _only_ from inside the tests directory of the new version. This will fetch the latest server JSON responses and store it inside the fixtures directory for these tests. If there are any errors, then the command line CLI has encountered a breaking change that must first be fixed. 5. Run the test suite for the latest version and examine breakages. It is possible that breakages are not actually full breakdown, but merely a change in the serialized object. Nonetheless, fix these by subclassing the previous versions of the API and overriding broken methods. In the cases of total breakage, a non-subclassed rewrite may be more appropriate. (May also apply at major version breaks.) 6. When the test suite passes, or a new object format has been decided and tests rewritten, run genfixtures.sh to freeze the current test suite. +7. Include the new version directory in the list of packages in `setup.py` +8. Update `THOTH_VERSION` in `thothlibrary/client.py` diff --git a/thothlibrary/__init__.py b/thothlibrary/__init__.py index 40cdcad..8967380 100644 --- a/thothlibrary/__init__.py +++ b/thothlibrary/__init__.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 """GraphQL client for Thoth""" -__version__ = "0.9.1" +__version__ = "0.10.0" __author__ = "Javier Arias " __copyright__ = "Copyright (c) 2020 Open Book Publishers" __license__ = "Apache 2.0" diff --git a/thothlibrary/client.py b/thothlibrary/client.py index 9da2140..7b9cfc6 100644 --- a/thothlibrary/client.py +++ b/thothlibrary/client.py @@ -8,18 +8,22 @@ import importlib import pkgutil +import re import thothlibrary from .auth import ThothAuthenticator from .graphql import GraphQLClientRequests as GraphQLClient from .mutation import ThothMutation from .query import ThothQuery -import re + +THOTH_ENDPOINT = "https://api.thoth.pub" +THOTH_VERSION = "0.6.0" class ThothClient: """Client to Thoth's GraphQL API""" + QUERIES = {} # populated according to each version's requirements - def __new__(cls, thoth_endpoint="https://api.thoth.pub", version="0.4.2"): + def __new__(cls, thoth_endpoint=THOTH_ENDPOINT, version=THOTH_VERSION): # this new call is the only bit of "magic" # it basically subs in the sub-class of the correct version and returns # an instance of that, instead of the generic class @@ -30,9 +34,10 @@ def __new__(cls, thoth_endpoint="https://api.thoth.pub", version="0.4.2"): version_endpoints = getattr( endpoints, 'ThothClient{0}'.format(version_replaced)) - return version_endpoints(thoth_endpoint=thoth_endpoint, version=version) + return version_endpoints(thoth_endpoint=thoth_endpoint, + version=version) - def __init__(self, thoth_endpoint="https://api.thoth.pub", version="0.4.2"): + def __init__(self, thoth_endpoint=THOTH_ENDPOINT, version=THOTH_VERSION): """Returns new ThothClient object at the specified GraphQL endpoint thoth_endpoint: Must be the full URL (eg. 'http://localhost'). @@ -142,7 +147,7 @@ def _api_request(self, endpoint_name: str, parameters, """ Makes a request to the API @param endpoint_name: the name of the endpoint - @param return_raw: whether to return the raw data or an object (default) + @param return_raw: whether to return raw data or an object (default) @param parameters: the parameters to pass to GraphQL @return: an object or JSON of the request """ @@ -150,8 +155,7 @@ def _api_request(self, endpoint_name: str, parameters, if return_raw: return response - else: - return self._build_structure(endpoint_name, response) + return self._build_structure(endpoint_name, response) def _build_structure(self, endpoint_name, data): """