From e3717e50ea25cad7550f3d6c9071092a10beef7e Mon Sep 17 00:00:00 2001 From: Luca Baffa Date: Fri, 11 Mar 2022 12:25:02 +0000 Subject: [PATCH 1/8] change thoth version --- thothlibrary/cli.py | 2 +- thothlibrary/thoth-0_8_0/__init__.py | 0 thothlibrary/thoth-0_8_0/endpoints.py | 793 ++++++++++++++++++++++ thothlibrary/thoth-0_8_0/fixtures/QUERIES | 626 +++++++++++++++++ thothlibrary/thoth-0_8_0/structures.py | 329 +++++++++ 5 files changed, 1749 insertions(+), 1 deletion(-) create mode 100644 thothlibrary/thoth-0_8_0/__init__.py create mode 100644 thothlibrary/thoth-0_8_0/endpoints.py create mode 100644 thothlibrary/thoth-0_8_0/fixtures/QUERIES create mode 100644 thothlibrary/thoth-0_8_0/structures.py diff --git a/thothlibrary/cli.py b/thothlibrary/cli.py index 3969feb..eddab38 100644 --- a/thothlibrary/cli.py +++ b/thothlibrary/cli.py @@ -35,7 +35,7 @@ def __init__(self): A Thoth CLI client """ self.endpoint = "https://api.thoth.pub" - self.version = "0.6.0" + self.version = "0.8.0" self.thoth_email = getenv('THOTH_EMAIL') self.thoth_pwd = getenv('THOTH_PWD') diff --git a/thothlibrary/thoth-0_8_0/__init__.py b/thothlibrary/thoth-0_8_0/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/thothlibrary/thoth-0_8_0/endpoints.py b/thothlibrary/thoth-0_8_0/endpoints.py new file mode 100644 index 0000000..733dbf4 --- /dev/null +++ b/thothlibrary/thoth-0_8_0/endpoints.py @@ -0,0 +1,793 @@ +""" +(c) ΔQ Programming LLP, July 2021 +This program is free software; you may redistribute and/or modify +it under the terms of the Apache License v2.0. +""" +import json +import os +import pathlib + +import thothlibrary +from thothlibrary.client import ThothClient + + +class ThothClient0_8_0(ThothClient): + """ + The client for Thoth 0.4.2 + """ + + def __new__(cls, *args, **kwargs): + return super(thothlibrary.ThothClient, ThothClient0_8_0).__new__(cls) + + def __init__(self, thoth_endpoint="https://api.thoth.pub", version="0.8.0"): + """ + Creates an instance of Thoth 0.8.0 endpoints + @param thoth_endpoint: the Thoth API instance endpoint + @param version: the version of the Thoth API to use + """ + if hasattr(self, 'client'): + return + + # the QUERIES field defines the fields that GraphQL will return + # note: every query should contain the field "__typename" if auto-object + # __str__ representation is to work. These are stored in the + # fixtures/QUERIES file + script_dir = pathlib.Path(__file__).parent.resolve() + path = os.path.join(script_dir, 'fixtures', 'QUERIES') + + with open(path, 'r') as query_file: + self.QUERIES = json.loads(query_file.read()) + + super().__init__(thoth_endpoint=thoth_endpoint, version=version) + + @staticmethod + def _order_limit_filter_offset_setup(order, limit, search, offset): + """ + The default setup for this version. Many methods use order, limit, + filter, and offset as parameters, so this de-duplicates that code. + @param order: the order + @param limit: the limit + @param search: the search + @param offset: the offset + @return: a parameters dictionary + """ + if not order: + order = {} + parameters = { + "offset": offset, + "limit": limit, + } + + if search and not search.startswith('"'): + search = '"{0}"'.format(search) + + ThothClient._dictionary_append(parameters, 'filter', search) + ThothClient._dictionary_append(parameters, 'order', order) + + return parameters + + def contribution(self, contribution_id: str, raw: bool = False): + """ + Returns a contribution by ID + @param contribution_id: the contribution ID + @param raw: whether to return a python object or the raw result + @return: either an object (default) or raw server response + """ + parameters = { + 'contributionId': '"' + contribution_id + '"' + } + + return self._api_request("contribution", parameters, return_raw=raw) + + def contributions(self, limit: int = 100, offset: int = 0, + order: str = None, publishers: str = None, + contribution_type: str = None, raw: bool = False): + """ + Returns a contributions list + @param limit: the maximum number of results to return + @param order: a GraphQL order query statement + @param offset: the offset from which to retrieve results + @param publishers: a list of publishers to limit by + @param contribution_type: the contribution type (e.g. AUTHOR) + @param raw: whether to return a python object or the raw server result + @return: either an object (default) or raw server response + """ + if order is None: + order = {} + parameters = { + "offset": offset, + "limit": limit, + } + + self._dictionary_append(parameters, 'order', order) + self._dictionary_append(parameters, 'publishers', publishers) + self._dictionary_append(parameters, 'contributionType', + contribution_type) + + return self._api_request("contributions", parameters, return_raw=raw) + + def contribution_count(self, search: str = "", publishers: str = None, + contribution_type: str = None, raw: bool = False): + """ + Returns a count of contributions + @param search: a search string + @param publishers: a list of publishers + @param contribution_type: a contribution type (e.g. AUTHOR) + @param raw: whether to return a raw result + @return: a count of contributions + """ + parameters = {} + + if search and not search.startswith('"'): + search = '"{0}"'.format(search) + + self._dictionary_append(parameters, 'filter', search) + self._dictionary_append(parameters, 'publishers', publishers) + self._dictionary_append(parameters, 'contributionType', + contribution_type) + + return self._api_request("contributionCount", parameters, + return_raw=raw) + + def contributor(self, contributor_id: str, raw: bool = False): + """ + Returns a contributor by ID + @param contributor_id: the ID to fetch + @param raw: whether to return a python object or the raw result + @return: either an object (default) or raw server response + """ + parameters = { + 'contributorId': '"' + contributor_id + '"' + } + + return self._api_request("contributor", parameters, return_raw=raw) + + def contributors(self, limit: int = 100, offset: int = 0, + search: str = "", order: str = None, + raw: bool = False): + """ + Returns contributors + @param limit: the maximum number of results to return + @param order: a GraphQL order query statement + @param offset: the offset from which to retrieve results + @param search: a filter string to search + @param raw: whether to return a python object or the raw result + @return: either an object (default) or raw server response + """ + parameters = self._order_limit_filter_offset_setup(order=order, + search=search, + limit=limit, + offset=offset) + + return self._api_request("contributors", parameters, return_raw=raw) + + def contributor_count(self, search: str = "", raw: bool = False): + """ + Return a count of contributors + @param search: a search string + @param raw: whether to return the raw result + @return: a count of contributors + """ + parameters = {} + + if search and not search.startswith('"'): + search = '"{0}"'.format(search) + + self._dictionary_append(parameters, 'filter', search) + + return self._api_request("contributorCount", parameters, + return_raw=raw) + + def institution(self, institution_id: str, raw: bool = False): + """ + Returns an institution by ID + @param funder_id: the ID to fetch + @param raw: whether to return a python object or the raw result + @return: either an object (default) or raw server response + """ + parameters = { + 'institutionId': '"' + institution_id + '"' + } + + return self._api_request("institution", parameters, return_raw=raw) + + def institutions(self, limit: int = 100, offset: int = 0, order: str = None, + search: str = "", raw: bool = False): + """ + Return institutions + @param limit: the limit on the number of results + @param offset: the offset from which to start + @param order: the order of results + @param search: a search string + @param raw: whether to return raw result + @return: an object or raw result + """ + + parameters = { + "limit": limit, + "offset": offset, + } + + if search and not search.startswith('"'): + search = '"{0}"'.format(search) + + self._dictionary_append(parameters, 'filter', search) + self._dictionary_append(parameters, 'order', order) + + return self._api_request("institutions", parameters, return_raw=raw) + + def funder_count(self, search: str = "", raw: bool = False): + """ + A count of funders + @param search: a search string + @param raw: whether to return raw result + @return: a count of funders + """ + parameters = {} + + if search and not search.startswith('"'): + search = '"{0}"'.format(search) + + self._dictionary_append(parameters, 'filter', search) + + return self._api_request("funderCount", parameters, return_raw=raw) + + def funding(self, funding_id: str, raw: bool = False): + """ + Returns a funding by ID + @param funding_id: the ID to fetch + @param raw: whether to return a python object or the raw result + @return: either an object (default) or raw server response + """ + parameters = { + 'fundingId': '"' + funding_id + '"' + } + + return self._api_request("funding", parameters, return_raw=raw) + + def fundings(self, limit: int = 100, offset: int = 0, order: str = None, + publishers: str = None, raw: bool = False): + """ + Returns a fundings list + @param limit: the maximum number of results to return + @param order: a GraphQL order query statement + @param offset: the offset from which to retrieve results + @param publishers: a list of publishers to limit by + @param raw: whether to return a python object or the raw server result + @return: either an object (default) or raw server response + """ + if order is None: + order = {} + parameters = { + "offset": offset, + "limit": limit, + } + + self._dictionary_append(parameters, 'order', order) + self._dictionary_append(parameters, 'publishers', publishers) + + return self._api_request("fundings", parameters, return_raw=raw) + + def funding_count(self, raw: bool = False): + """ + A count of fundings + @param raw: whether to return a raw result + @return: a count of fundings + """ + parameters = {} + + return self._api_request("fundingCount", parameters, return_raw=raw) + + def imprint(self, imprint_id: str, raw: bool = False): + """ + Return an imprint + @param imprint_id: the imprint + @param raw: whether to return a python object or the raw result + @return: either an object (default) or raw server response + """ + parameters = { + 'imprintId': '"' + imprint_id + '"' + } + + return self._api_request("imprint", parameters, return_raw=raw) + + def imprints(self, limit: int = 100, offset: int = 0, order: str = None, + search: str = "", publishers: str = None, + raw: bool = False): + """ + Return imprints + @param limit: the limit on the number of results returned + @param offset: the offset from which to begin + @param order: the order in which to present results + @param search: a search string + @param publishers: a list of publishers by which to limit the query + @param raw: whether to return a raw result + @return: an object or raw result + """ + parameters = self._order_limit_filter_offset_setup(order=order, + search=search, + limit=limit, + offset=offset) + self._dictionary_append(parameters, 'publishers', publishers) + + return self._api_request("imprints", parameters, return_raw=raw) + + def imprint_count(self, search: str = "", publishers: str = None, + raw: bool = False): + """ + A count of imprints + @param search: a search string + @param publishers: a list of publishers by which to limit the result + @param raw: whether to return a raw result + @return: a count of imprints + """ + parameters = {} + + self._dictionary_append(parameters, 'filter', search) + self._dictionary_append(parameters, 'publishers', publishers) + + return self._api_request("imprintCount", parameters, return_raw=raw) + + def issue(self, issue_id: str, raw: bool = False): + """ + Returns an issue by ID + @param issue_id: the issue + @param raw: whether to return a python object or the raw result + @return: either an object (default) or raw server response + """ + parameters = { + 'issueId': '"' + issue_id + '"' + } + + return self._api_request("issue", parameters, return_raw=raw) + + def issues(self, limit: int = 100, offset: int = 0, order: str = None, + search: str = "", publishers: str = None, raw: bool = False): + """ + Return issues + @param limit: the limit on the number of results to return + @param offset: the offset from which to begin + @param order: the order in which to return results + @param search: a search string + @param publishers: a list of publishers by which to limit results + @param raw: whether to return a raw response + @return: an object or raw response + """ + parameters = self._order_limit_filter_offset_setup(order=order, + search=search, + limit=limit, + offset=offset) + self._dictionary_append(parameters, 'publishers', publishers) + + return self._api_request("issues", parameters, return_raw=raw) + + def issue_count(self, raw: bool = False): + """ + A count of issues + @param raw: whether to return a raw result + @return: a count of issues + """ + parameters = {} + + return self._api_request("issueCount", parameters, + return_raw=raw) + + def language(self, language_id: str, raw: bool = False): + """ + Returns a language by ID + @param language_id: the ID to fetch + @param raw: whether to return a python object or the raw result + @return: either an object (default) or raw server response + """ + parameters = { + 'languageId': '"' + language_id + '"' + } + + return self._api_request("language", parameters, return_raw=raw) + + def languages(self, limit: int = 100, offset: int = 0, order: str = None, + search: str = "", publishers: str = None, raw: bool = False, + language_code: str = "", language_relation: str = ""): + """ + Return languages + @param limit: the limit on the number of results to return + @param offset: the offset from which to begin + @param order: the order in which to return results + @param search: a search string + @param publishers: a list of publishers by which to limit the result + @param raw: whether to return a raw result + @param language_code: the language code to query + @param language_relation: the language relation to query (e.g. ORIGINAL) + @return: an object or raw result + """ + parameters = self._order_limit_filter_offset_setup(order=order, + search=search, + limit=limit, + offset=offset) + self._dictionary_append(parameters, 'publishers', publishers) + self._dictionary_append(parameters, 'languageCode', language_code) + self._dictionary_append(parameters, 'languageRelation', + language_relation) + + return self._api_request("languages", parameters, return_raw=raw) + + def language_count(self, language_code: str = "", + language_relation: str = "", raw: bool = False): + """ + A count of languages + @param language_code: a language code (e.g. CHI) + @param language_relation: a language relation (e.g. ORIGINAL) + @param raw: whether to return a raw result + @return: a count of languages + """ + parameters = {} + + self._dictionary_append(parameters, 'languageCode', language_code) + self._dictionary_append(parameters, 'languageRelation', + language_relation) + + return self._api_request("languageCount", parameters, return_raw=raw) + + def price(self, price_id: str, raw: bool = False): + """ + Returns a price by ID + @param price_id: the ID to fetch + @param raw: whether to return a python object or the raw result + @return: either an object (default) or raw server response + """ + parameters = { + 'priceId': '"' + price_id + '"' + } + + return self._api_request("price", parameters, return_raw=raw) + + def prices(self, limit: int = 100, offset: int = 0, order: str = None, + publishers: str = None, currency_code: str = None, + raw: bool = False): + """ + Returns prices + @param limit: the maximum number of results to return + @param order: a GraphQL order query statement + @param offset: the offset from which to retrieve results + @param publishers: a list of publishers to limit by + @param currency_code: the currency code (e.g. GBP) + @param raw: whether to return a python object or the raw server result + @return: either an object (default) or raw server response + """ + if order is None: + order = {} + parameters = { + "offset": offset, + "limit": limit, + } + + self._dictionary_append(parameters, 'order', order) + self._dictionary_append(parameters, 'publishers', publishers) + self._dictionary_append(parameters, 'currencyCode', currency_code) + + return self._api_request("prices", parameters, return_raw=raw) + + def price_count(self, currency_code: str = None, raw: bool = False): + """ + A count of prices + @param currency_code: a currency code (e.g. GBP) + @param raw: whether to return a raw result + @return: a count of prices + """ + parameters = {} + + self._dictionary_append(parameters, 'currencyCode', currency_code) + + return self._api_request("priceCount", parameters, return_raw=raw) + + def publication(self, publication_id: str, raw: bool = False): + """ + Returns a publication by ID + @param publication_id: the ID to fetch + @param raw: whether to return a python object or the raw result + @return: either an object (default) or raw server response + """ + parameters = { + 'publicationId': '"' + publication_id + '"' + } + + return self._api_request("publication", parameters, return_raw=raw) + + def publications(self, limit: int = 100, offset: int = 0, + search: str = "", order: str = None, + publishers: str = None, publication_type: str = None, + raw: bool = False): + """ + Returns publications + @param limit: the maximum number of results to return + @param order: a GraphQL order query statement + @param offset: the offset from which to retrieve results + @param publishers: a list of publishers to limit by + @param search: a filter string to search + @param publication_type: the work type (e.g. PAPERBACK) + @param raw: whether to return a python object or the raw server result + @return: either an object (default) or raw server response + """ + parameters = self._order_limit_filter_offset_setup(order=order, + search=search, + limit=limit, + offset=offset) + self._dictionary_append(parameters, 'publishers', publishers) + self._dictionary_append(parameters, 'publicationType', publication_type) + + return self._api_request("publications", parameters, return_raw=raw) + + def publication_count(self, search: str = "", publishers: str = None, + publication_type: str = None, raw: bool = False): + """ + A count of publications + @param search: a search string + @param publishers: a list of publishers by which to limit the result + @param publication_type: the publication type (e.g. PAPERBACK) + @param raw: whether to return a raw result + @return: a count of publications + """ + parameters = {} + + if search and not search.startswith('"'): + search = '"{0}"'.format(search) + + self._dictionary_append(parameters, 'filter', search) + self._dictionary_append(parameters, 'publishers', publishers) + self._dictionary_append(parameters, 'publicationType', publication_type) + + return self._api_request("publicationCount", parameters, + return_raw=raw) + + def publisher(self, publisher_id: str, raw: bool = False): + """ + Returns a publisher by ID + @param publisher_id: the publisher + @param raw: whether to return a python object or the raw result + @return: either an object (default) or raw server response + """ + parameters = { + 'publisherId': '"' + publisher_id + '"' + } + + return self._api_request("publisher", parameters, return_raw=raw) + + def publishers(self, limit: int = 100, offset: int = 0, order: str = None, + search: str = "", publishers: str = None, + raw: bool = False): + """ + Return publishers + @param limit: the limit on the number of results + @param offset: the offset from which to begin + @param order: the order for the returned results + @param search: a search string + @param publishers: a list of publishers by which to limit the results + @param raw: whether to return a raw result + @return: an object or raw result + """ + parameters = self._order_limit_filter_offset_setup(order=order, + search=search, + limit=limit, + offset=offset) + self._dictionary_append(parameters, 'publishers', publishers) + + return self._api_request("publishers", parameters, return_raw=raw) + + def publisher_count(self, search: str = "", publishers: str = None, + raw: bool = False): + """ + Return a count of publishers + @param search: a search string + @param publishers: a list of publishers by which to limit the result + @param raw: whether to return a raw result + @return: a count of publishers + """ + parameters = {} + + if search and not search.startswith('"'): + search = '"{0}"'.format(search) + + self._dictionary_append(parameters, 'filter', search) + self._dictionary_append(parameters, 'publishers', publishers) + + return self._api_request("publisherCount", parameters, return_raw=raw) + + def series(self, series_id: str, raw: bool = False): + """ + Returns a series by ID + @param series_id: the ID to fetch + @param raw: whether to return a python object or the raw result + @return: either an object (default) or raw server response + """ + parameters = { + 'seriesId': '"' + series_id + '"' + } + + return self._api_request("series", parameters, return_raw=raw) + + def serieses(self, limit: int = 100, offset: int = 0, order: str = None, + search: str = "", publishers: str = None, + series_type: str = "", raw: bool = False): + """ + Return serieses + @param limit: the limit on the number of results to retrieve + @param offset: the offset from which to start + @param order: the order in which to present the results + @param search: a search string + @param publishers: a list of publishers by which to limit results + @param series_type: the series type (e.g. BOOK_SERIES) + @param raw: whether to return a raw result + @return: an object or raw result + """ + parameters = self._order_limit_filter_offset_setup(order=order, + search=search, + limit=limit, + offset=offset) + self._dictionary_append(parameters, 'publishers', publishers) + self._dictionary_append(parameters, 'seriesType', series_type) + + return self._api_request("serieses", parameters, return_raw=raw) + + def series_count(self, search: str = "", publishers: str = None, + series_type: str = None, raw: bool = False): + """ + Return a count of serieses + @param search: a search string + @param publishers: a list of publishers by which to limit the results + @param series_type: the type of series (e.g. BOOK_SERIES) + @param raw: whether to return a raw result + @return: a count of serieses + """ + parameters = {} + + if search and not search.startswith('"'): + search = '"{0}"'.format(search) + + self._dictionary_append(parameters, 'filter', search) + self._dictionary_append(parameters, 'publishers', publishers) + self._dictionary_append(parameters, 'seriesType', + series_type) + + return self._api_request("seriesCount", parameters, return_raw=raw) + + def subject(self, subject_id: str, raw: bool = False): + """ + Returns a subject by ID + @param subject_id: the ID to fetch + @param raw: whether to return a python object or the raw result + @return: either an object (default) or raw server response + """ + parameters = { + 'subjectId': '"' + subject_id + '"' + } + + return self._api_request("subject", parameters, return_raw=raw) + + def subjects(self, limit: int = 100, offset: int = 0, order: str = None, + search: str = "", publishers: str = None, raw: bool = False, + subject_type: str = ""): + """ + Return subjects + @param limit: a limit on the number of results + @param offset: the offset from which to retrieve results + @param order: the order in which to present results + @param search: a search string + @param publishers: a list of publishers + @param raw: whether to return a raw result + @param subject_type: the subject type (e.g. BIC) + @return: subjects + """ + parameters = self._order_limit_filter_offset_setup(order=order, + search=search, + limit=limit, + offset=offset) + self._dictionary_append(parameters, 'publishers', publishers) + self._dictionary_append(parameters, 'subjectType', subject_type) + + return self._api_request("subjects", parameters, return_raw=raw) + + def subject_count(self, subject_type: str = "", search: str = "", + raw: bool = False): + """ + A count of subjects + @param subject_type: the type of subject + @param search: a search string + @param raw: whether to return a raw result + @return: a count of subjects + """ + parameters = {} + + if search and not search.startswith('"'): + search = '"{0}"'.format(search) + + # there is a bug in this version of Thoth. Filter is REQUIRED. + if not search: + search = '""' + + self._dictionary_append(parameters, 'subjectType', subject_type) + self._dictionary_append(parameters, 'filter', search) + + return self._api_request("subjectCount", parameters, return_raw=raw) + + def works(self, limit: int = 100, offset: int = 0, search: str = "", + order: str = None, publishers: str = None, work_type: str = None, + work_status: str = None, raw: bool = False): + """ + Returns works + @param limit: the maximum number of results to return + @param order: a GraphQL order query statement + @param offset: the offset from which to retrieve results + @param publishers: a list of publishers to limit by + @param search: a filter string to search + @param work_type: the work type (e.g. MONOGRAPH) + @param work_status: the work status (e.g. ACTIVE) + @param raw: whether to return a python object or the raw server result + @return: either an object (default) or raw server response + """ + if order is None: + order = {} + parameters = { + "offset": offset, + "limit": limit, + } + + if search and not search.startswith('"'): + search = '"{0}"'.format(search) + + self._dictionary_append(parameters, 'filter', search) + self._dictionary_append(parameters, 'order', order) + self._dictionary_append(parameters, 'publishers', publishers) + self._dictionary_append(parameters, 'workType', work_type) + self._dictionary_append(parameters, 'workStatus', work_status) + + return self._api_request("works", parameters, return_raw=raw) + + def work_by_doi(self, doi: str, raw: bool = False): + """ + Returns a work by DOI + @param doi: the DOI to fetch + @param raw: whether to return a python object or the raw result + @return: either an object (default) or raw server response + """ + parameters = { + 'doi': '"' + doi + '"' + } + + return self._api_request("workByDoi", parameters, return_raw=raw) + + def work_by_id(self, work_id: str, raw: bool = False): + """ + Returns a work by ID + @param work_id: the ID to fetch + @param raw: whether to return a python object or the raw result + @return: either an object (default) or raw server response + """ + parameters = { + 'workId': '"' + work_id + '"' + } + + return self._api_request("work", parameters, return_raw=raw) + + def work_count(self, search: str = "", publishers: str = None, + work_type: str = None, work_status: str = None, + raw: bool = False): + """ + A count of works + @param search: a search string + @param publishers: a list of publishers by which to limit results + @param work_type: the work type (e.g. MONOGRAPH) + @param work_status: the work status (e.g. ACTIVE) + @param raw: whether to return a raw result + @return: a count of works + """ + parameters = {} + + if search and not search.startswith('"'): + search = '"{0}"'.format(search) + + self._dictionary_append(parameters, 'filter', search) + self._dictionary_append(parameters, 'publishers', publishers) + self._dictionary_append(parameters, 'workType', work_type) + self._dictionary_append(parameters, 'workStatus', work_status) + + return self._api_request("workCount", parameters, return_raw=raw) diff --git a/thothlibrary/thoth-0_8_0/fixtures/QUERIES b/thothlibrary/thoth-0_8_0/fixtures/QUERIES new file mode 100644 index 0000000..be7124f --- /dev/null +++ b/thothlibrary/thoth-0_8_0/fixtures/QUERIES @@ -0,0 +1,626 @@ +{ + "contribution": { + "fields": [ + "contributionId", + "contributionType", + "mainContribution", + "biography", + "affiliations { affiliationId institution { institutionName ror fundings { program projectName projectShortname grantNumber jurisdiction } } }", + "__typename", + "firstName", + "lastName", + "fullName", + "contributionOrdinal", + "workId", + "work { fullTitle }", + "contributor {firstName lastName fullName orcid __typename website contributorId}" + ], + "parameters": [ + "contributionId" + ] + }, + "contributionCount": { + "parameters": [ + "filter", + "publishers", + "contributionType" + ] + }, + "contributions": { + "fields": [ + "contributionId", + "contributionType", + "mainContribution", + "biography", + "affiliations { affiliationId institution { institutionName ror fundings { program projectName projectShortname grantNumber jurisdiction } } }", + "__typename", + "firstName", + "lastName", + "fullName", + "contributionOrdinal", + "workId", + "work { fullTitle }", + "contributor {firstName lastName fullName orcid __typename website contributorId}" + ], + "parameters": [ + "limit", + "offset", + "filter", + "order", + "publishers", + "contributionType" + ] + }, + "contributor": { + "fields": [ + "contributorId", + "firstName", + "lastName", + "fullName", + "orcid", + "__typename", + "contributions { contributionId contributionType work { workId fullTitle} }" + ], + "parameters": [ + "contributorId" + ] + }, + "contributorCount": { + "parameters": [ + "filter" + ] + }, + "contributors": { + "fields": [ + "contributorId", + "firstName", + "lastName", + "fullName", + "orcid", + "__typename", + "contributions { contributionId contributionType work { workId fullTitle} }" + ], + "parameters": [ + "limit", + "offset", + "filter", + "order" + ] + }, + "institution": { + "fields": [ + "institutionId", + "institutionName", + "institutionDoi", + "fundings { grantNumber program projectName jurisdiction work { workId fullTitle doi publicationDate place contributions { fullName contributionType mainContribution contributionOrdinal } imprint { publisher { publisherName publisherId } } } }", + "__typename" + ], + "parameters": [ + "institutionId" + ] + }, + "funderCount": { + "parameters": [ + "filter" + ] + }, + "institutions": { + "fields": [ + "institutionId", + "institutionName", + "institutionDoi", + "ror", + "countryCode", + "fundings { grantNumber program projectName jurisdiction work { workId fullTitle doi publicationDate place contributions { fullName contributionType mainContribution contributionOrdinal } imprint { publisher { publisherName publisherId } } } }", + "affiliations { affiliationOrdinal position contribution { fullName contributionType mainContribution contributionOrdinal } }", + "__typename" + ], + "parameters": [ + "limit", + "offset", + "filter", + "order" + ] + }, + "funding": { + "fields": [ + "fundingId", + "workId", + "institution { institutionId institutionDoi ror countryCode updatedAt createdAt }", + "program", + "grantNumber", + "projectName", + "projectShortname", + "jurisdiction", + "work { workId fullTitle doi publicationDate place contributions { fullName contributionType mainContribution contributionOrdinal } imprint { publisher { publisherName publisherId } } }", + "__typename" + ], + "parameters": [ + "fundingId" + ] + }, + "fundingCount": {}, + "fundings": { + "fields": [ + "fundingId", + "workId", + "institution { institutionId institutionDoi ror countryCode updatedAt createdAt }", + "program", + "grantNumber", + "projectName", + "projectShortname", + "jurisdiction", + "work { workId fullTitle doi publicationDate place contributions { fullName contributionType mainContribution contributionOrdinal } imprint { publisher { publisherName publisherId } } }", + "__typename" + ], + "parameters": [ + "limit", + "offset", + "publishers", + "order" + ] + }, + "imprint": { + "fields": [ + "imprintUrl", + "imprintId", + "imprintName", + "updatedAt", + "createdAt", + "publisherId", + "publisher { publisherName publisherId }", + "works { workId fullTitle doi publicationDate place contributions { fullName contributionType mainContribution contributionOrdinal } }__typename" + ], + "parameters": [ + "imprintId" + ] + }, + "imprintCount": { + "parameters": [ + "filter", + "publishers" + ] + }, + "imprints": { + "fields": [ + "imprintUrl", + "imprintId", + "imprintName", + "updatedAt", + "createdAt", + "publisherId", + "publisher { publisherName publisherId }", + "works { workId fullTitle doi publicationDate place contributions { fullName contributionType mainContribution contributionOrdinal } }__typename" + ], + "parameters": [ + "limit", + "offset", + "filter", + "order", + "publishers" + ] + }, + "issue": { + "fields": [ + "issueId", + "seriesId", + "issueOrdinal", + "updatedAt", + "createdAt", + "series { seriesId seriesType seriesName imprintId imprint { __typename publisher { publisherName publisherId __typename } }}", + "work { workId fullTitle doi publicationDate place contributions { fullName contributionType mainContribution contributionOrdinal } }__typename" + ], + "parameters": [ + "issueId" + ] + }, + "issues": { + "fields": [ + "issueId", + "seriesId", + "issueOrdinal", + "updatedAt", + "createdAt", + "series { seriesId seriesType seriesName imprintId imprint { __typename publisher { publisherName publisherId __typename } }}", + "work { workId fullTitle doi publicationDate place contributions { fullName contributionType mainContribution contributionOrdinal } }__typename" + ], + "parameters": [ + "limit", + "offset", + "filter", + "order", + "publishers" + ] + }, + "issuesCount": {}, + "language": { + "fields": [ + "languageId", + "workId", + "languageCode", + "languageRelation", + "createdAt", + "mainLanguage", + "work { workId fullTitle doi publicationDate place contributions { fullName contributionType mainContribution contributionOrdinal } }__typename" + ], + "parameters": [ + "languageId" + ] + }, + "languageCount": { + "parameters": [ + "languageCode", + "languageRelation" + ] + }, + "languages": { + "fields": [ + "languageId", + "workId", + "languageCode", + "languageRelation", + "createdAt", + "mainLanguage", + "work { workId fullTitle doi publicationDate place contributions { fullName contributionType mainContribution contributionOrdinal } }__typename" + ], + "parameters": [ + "limit", + "offset", + "filter", + "order", + "publishers", + "languageCode", + "languageRelation" + ] + }, + "price": { + "fields": [ + "currencyCode", + "publicationId", + "priceId", + "unitPrice", + "publication { work { workId fullTitle doi publicationDate place contributions { fullName contributionType mainContribution contributionOrdinal } imprint { publisher { publisherName publisherId } } } }", + "createdAt", + "updatedAt", + "__typename" + ], + "parameters": [ + "priceId" + ] + }, + "priceCount": { + "parameters": [ + "currencyCode" + ] + }, + "prices": { + "fields": [ + "currencyCode", + "publicationId", + "priceId", + "unitPrice", + "publication { work { workId fullTitle doi publicationDate place contributions { fullName contributionType mainContribution contributionOrdinal } imprint { publisher { publisherName publisherId } } } }", + "createdAt", + "updatedAt", + "__typename" + ], + "parameters": [ + "limit", + "offset", + "filter", + "order", + "publishers", + "currencyCode" + ] + }, + "publication": { + "fields": [ + "publicationId", + "publicationType", + "workId", + "isbn", + "locations { locationId landingPage locationPlatform canonical }", + "createdAt", + "updatedAt", + "prices { currencyCode unitPrice __typename}", + "work { workId fullTitle doi publicationDate place contributions { fullName contributionType mainContribution contributionOrdinal } imprint { publisher { publisherName publisherId } } }", + "__typename" + ], + "parameters": [ + "publicationId" + ] + }, + "publicationCount": { + "parameters": [ + "filter", + "publishers", + "publicationType" + ] + }, + "publications": { + "fields": [ + "publicationId", + "publicationType", + "workId", + "isbn", + "createdAt", + "locations { locationId landingPage locationPlatform canonical }", + "updatedAt", + "prices { currencyCode unitPrice __typename}", + "work { workId fullTitle doi publicationDate place contributions { fullName contributionType mainContribution contributionOrdinal } imprint { publisher { publisherName publisherId } } }", + "__typename" + ], + "parameters": [ + "limit", + "offset", + "filter", + "order", + "publishers", + "publicationType" + ] + }, + "publisher": { + "fields": [ + "imprints { imprintUrl imprintId imprintName __typename}updatedAt", + "createdAt", + "publisherId", + "publisherName", + "publisherShortname", + "publisherUrl", + "__typename" + ], + "parameters": [ + "publisherId" + ] + }, + "publisherCount": { + "parameters": [ + "filter", + "publishers" + ] + }, + "publishers": { + "fields": [ + "imprints { imprintUrl imprintId imprintName __typename}updatedAt", + "createdAt", + "publisherId", + "publisherName", + "publisherShortname", + "publisherUrl", + "__typename" + ], + "parameters": [ + "limit", + "offset", + "filter", + "order", + "publishers" + ] + }, + "series": { + "fields": [ + "seriesId", + "seriesType", + "seriesName", + "updatedAt", + "createdAt", + "imprintId", + "imprint { __typename publisher { publisherName publisherId __typename } }", + "issues { issueId work { workId fullTitle doi publicationDate place contributions { fullName contributionType mainContribution contributionOrdinal } } }", + "__typename" + ], + "parameters": [ + "seriesId" + ] + }, + "seriesCount": { + "parameters": [ + "filter", + "publishers", + "seriesType" + ] + }, + "serieses": { + "fields": [ + "seriesId", + "seriesType", + "seriesName", + "updatedAt", + "createdAt", + "imprintId", + "imprint { __typename publisher { publisherName publisherId __typename } }", + "issues { issueId work { workId fullTitle doi publicationDate place contributions { fullName contributionType mainContribution contributionOrdinal } } }", + "__typename" + ], + "parameters": [ + "limit", + "offset", + "filter", + "order", + "publishers", + "seriesType" + ] + }, + "subject": { + "fields": [ + "subjectId", + "workId", + "subjectCode", + "subjectType", + "subjectOrdinal", + "createdAt", + "work { workId fullTitle doi publicationDate place contributions { fullName contributionType mainContribution contributionOrdinal } }__typename" + ], + "parameters": [ + "subjectId" + ] + }, + "subjectCount": { + "parameters": [ + "filter", + "subjectType" + ] + }, + "subjects": { + "fields": [ + "subjectId", + "workId", + "subjectCode", + "subjectType", + "subjectOrdinal", + "createdAt", + "work { workId fullTitle doi publicationDate place contributions { fullName contributionType mainContribution contributionOrdinal } }__typename" + ], + "parameters": [ + "limit", + "offset", + "filter", + "order", + "publishers", + "subjectType" + ] + }, + "work": { + "fields": [ + "workType", + "workStatus", + "fullTitle", + "title", + "subtitle", + "reference", + "edition", + "imprintId", + "doi", + "publicationDate", + "place", + "width", + "height", + "pageCount", + "pageBreakdown", + "imageCount", + "tableCount", + "audioCount", + "videoCount", + "license", + "copyrightHolder", + "landingPage", + "lccn", + "oclc", + "shortAbstract", + "longAbstract", + "generalNote", + "toc", + "workId", + "coverUrl", + "coverCaption", + "publications { isbn publicationType __typename }", + "contributions { fullName contributionType mainContribution contributor { contributorId orcid firstName lastName } contributionId contributionOrdinal __typename }", + "imprint { __typename publisher { publisherName publisherId __typename } }", + "subjects { subjectId, subjectType, subjectCode, subjectOrdinal, __typename }", + "__typename" + ], + "parameters": [ + "workId" + ] + }, + "workByDoi": { + "fields": [ + "workId", + "workType", + "workStatus", + "fullTitle", + "title", + "subtitle", + "reference", + "edition", + "imprintId", + "doi", + "publicationDate", + "place", + "width", + "height", + "pageCount", + "pageBreakdown", + "imageCount", + "tableCount", + "audioCount", + "videoCount", + "license", + "copyrightHolder", + "landingPage", + "lccn", + "oclc", + "shortAbstract", + "longAbstract", + "generalNote", + "toc", + "coverUrl", + "coverCaption", + "publications { isbn publicationType locations { locationId landingPage fullTextUrl locationPlatform } __typename }", + "subjects { subjectId, subjectType, subjectCode, subjectOrdinal, __typename }", + "contributions { fullName contributionType mainContribution contributor { contributorId orcid firstName lastName fullName } contributionId contributionOrdinal __typename }", + "imprint { __typename publisher { publisherName publisherId __typename } }", + "__typename" + ], + "parameters": [ + "doi" + ] + }, + "workCount": { + "parameters": [ + "filter", + "publishers", + "workType", + "workStatus" + ] + }, + "works": { + "fields": [ + "workType", + "workStatus", + "fullTitle", + "title", + "subtitle", + "reference", + "edition", + "imprintId", + "doi", + "publicationDate", + "place", + "width", + "height", + "pageCount", + "pageBreakdown", + "imageCount", + "tableCount", + "audioCount", + "videoCount", + "license", + "copyrightHolder", + "landingPage", + "lccn", + "oclc", + "shortAbstract", + "longAbstract", + "generalNote", + "toc", + "workId", + "coverUrl", + "coverCaption", + "subjects { subjectId, subjectType, subjectCode, subjectOrdinal, __typename }", + "publications { isbn publicationType __typename }", + "contributions { fullName contributionType mainContribution contributor { contributorId orcid firstName lastName fullName } contributionId contributionOrdinal __typename }", + "imprint { __typename publisher { publisherName publisherId __typename } }", + "__typename" + ], + "parameters": [ + "limit", + "offset", + "filter", + "order", + "publishers", + "workType", + "workStatus" + ] + } +} diff --git a/thothlibrary/thoth-0_8_0/structures.py b/thothlibrary/thoth-0_8_0/structures.py new file mode 100644 index 0000000..837e112 --- /dev/null +++ b/thothlibrary/thoth-0_8_0/structures.py @@ -0,0 +1,329 @@ +""" +(c) ΔQ Programming LLP, November 2021 +This program is free software; you may redistribute and/or modify +it under the terms of the Apache License v2.0. +""" +import collections + +from munch import Munch +from datetime import datetime + + +def _munch_repr(obj): + """ + This is a hacky munch context switcher. It passes the original __repr__ + pointer back + @param obj: the object to represent + @return: the original munch representation + """ + Munch.__repr__ = munch_local + return obj.__repr__() + + +def _author_parser(obj): + """ + This parses a list of contributors into authors and editors + @param obj: the Work to parse + @return: a string representation of authors + """ + if 'contributions' not in obj: + return None + + author_dict = {} + authors = '' + + for contributor in obj.contributions: + if contributor.contributionType == 'AUTHOR': + author_dict[contributor.contributionOrdinal] = contributor.fullName + if contributor.contributionType == "EDITOR": + author_dict[contributor.contributionOrdinal] = \ + contributor.fullName + " (ed.)" + + od_authors = collections.OrderedDict(sorted(author_dict.items())) + + for k, v in od_authors.items(): + authors += v + ', ' + + return authors + + +def _date_parser(date): + """ + Formats a date nicely + @param date: the date string or None + @return: a formatted date string + """ + if date: + return datetime.strptime(date, "%Y-%m-%d").year + else: + return "n.d." + + +def _price_parser(prices): + if len(prices) > 0 and 'currencyCode' not in prices: + return '({0}{1})'.format(prices[0].unitPrice, prices[0].currencyCode) + elif 'currencyCode' in prices: + return '{0}{1}'.format(prices.unitPrice, prices.currencyCode) + else: + return '' + + +# these are formatting statements for the endpoints +# they are injected to replace the default dictionary (Munch) __repr__ and +# __str__ methods. They let us create nice-looking string representations +# of objects, such as books + +def _generic_formatter(format_object, type_name, output): + """ + A generic formatter that returns either the input or the stored munch repr + @param format_object: the object on which to operate + @param type_name: the expected type name + @param output: the f-string to substitute + @return: a formatted string + """ + if "__typename" in format_object and format_object.__typename == type_name: + return output + else: + return f"{_munch_repr(format_object)}" + + +def _contribution_formatter(contribution): + """ + A formatting string for contributions + @param contribution: The contribution object + @return: A formatted contribution object + """ + format_str = f"{contribution.fullName} " \ + f"({contribution.contributionType} of " \ + f"{contribution.work.fullTitle}) " \ + f"[{contribution.contributionId}]" + return _generic_formatter(contribution, 'Contribution', format_str) + + +def _contributor_formatter(contributor): + """ + A formatting string for contributors + @param contributor: The contributor object + @return: A formatted contributor object + """ + format_str = f"{contributor.fullName} " \ + f"contributed to {len(contributor.contributions)} works " \ + f"[{contributor.contributorId}]" + return _generic_formatter(contributor, 'Contributor', format_str) + + +def _institution_formatter(institution): + """ + A formatting string for funders + @param institution: The funder object + @return: A formatted funder object + """ + format_str = f"{institution.institutionName} " \ + f"affiliated with {len(institution.fundings)} books " \ + f"[{institution.institutionId}]" + return _generic_formatter(institution, 'Institution', format_str) + + +def _funding_formatter(funding): + """ + A formatting string for fundings + @param funding: The funding object + @return: A formatted funding object + """ + format_str = f"{funding.funder.funderName} " \ + f"funded {funding.work.fullTitle} " \ + f"[{funding.fundingId}]" + return _generic_formatter(funding, 'Funding', format_str) + + +def _imprint_formatter(imprint): + """ + A formatting string for imprints + @param imprint: The imprint object + @return: A formatted imprint object + """ + format_str = f"{imprint.imprintName} " \ + f"({imprint.publisher.publisherName}/{imprint.publisherId}) " \ + f"[{imprint.imprintId}]" + return _generic_formatter(imprint, 'Imprint', format_str) + + +def _issue_formatter(issues): + """ + A formatting string for issues + @param issues: The issues object + @return: A formatted issue object + """ + format_str = f"{issues.work.fullTitle} " \ + f"in {issues.series.seriesName} " \ + f"({issues.series.imprint.publisher.publisherName}) " \ + f"[{issues.issueId}]" + return _generic_formatter(issues, 'Issue', format_str) + + +def _language_formatter(language): + """ + A formatting string for languages + @param language: The language object + @return: A formatted language object + """ + format_str = f"{language.work.fullTitle} " \ + f"is in {language.languageCode} " \ + f"({language.languageRelation}) " \ + f"[{language.languageId}]" + return _generic_formatter(language, 'Language', format_str) + + +def _price_formatter(price): + """ + A formatting string for prices + @param price: The price object + @return: A formatted price object + """ + format_str = f'{price.publication.work.fullTitle} ' \ + f'({price.publication.work.place}: ' \ + f'{price.publication.work.imprint.publisher.publisherName}, ' \ + f'{_date_parser(price.publication.work.publicationDate)}) ' \ + f"costs {_price_parser(price)} [{price.priceId}]" + return _generic_formatter(price, 'Price', format_str) + + +def _publication_formatter(publication): + """ + A formatting string for publications + @param publication: the publication on which to operate + @return: a formatted publication string + """ + format_str = f'{_author_parser(publication.work)}' \ + f'{publication.work.fullTitle} ' \ + f'({publication.work.place}: ' \ + f'{publication.work.imprint.publisher.publisherName}, ' \ + f'{_date_parser(publication.work.publicationDate)}) ' \ + f"[{publication.publicationType}] " \ + f"{_price_parser(publication.prices)} " \ + f"[{publication.publicationId}]" + return _generic_formatter(publication, 'Publication', format_str) + + +def _publisher_formatter(publisher): + """ + A formatting string for publishers + @param publisher: the publisher on which to operate + @return: a formatted publisher string + """ + format_str = f"{publisher.publisherName} ({publisher.publisherId})" + return _generic_formatter(publisher, 'Publisher', format_str) + + +def _series_formatter(series): + """ + A formatting string for series + @param series: the series on which to operate + @return: a formatted series string + """ + format_str = f"{series.seriesName} " \ + f"({series.imprint.publisher.publisherName}) " \ + f"[{series.seriesId}]" + return _generic_formatter(series, 'Series', format_str) + + +def _subject_formatter(subject): + """ + A formatting string for subjects + @param subject: the subject on which to operate + @return: a formatted subject string + """ + format_str = f"{subject.work.fullTitle} " \ + f"is in the {subject.subjectCode} " \ + f"subject area " \ + f"({subject.subjectType}) " \ + f"[{subject.subjectId}]" + return _generic_formatter(subject, 'Subject', format_str) + + +def _work_formatter(work): + """ + A formatting string for works + @param work: the work on which to operate + @return: a formatted work string + """ + format_str = f'{_author_parser(work)}' \ + f'{work.fullTitle} ' \ + f'({work.place}: ' \ + f'{work.imprint.publisher.publisherName}, ' \ + f'{_date_parser(work.publicationDate)}) ' \ + f'[{work.workId}]' + return _generic_formatter(work, 'Work', format_str) + + +default_fields = { + "contribution": _contribution_formatter, + "contributions": _contribution_formatter, + "contributor": _contributor_formatter, + "contributors": _contributor_formatter, + "funding": _funding_formatter, + "fundings": _funding_formatter, + "imprint": _imprint_formatter, + "imprints": _imprint_formatter, + "institution": _institution_formatter, + "institutions": _institution_formatter, + "issue": _issue_formatter, + "issues": _issue_formatter, + "language": _language_formatter, + "languages": _language_formatter, + "price": _price_formatter, + "prices": _price_formatter, + "publication": _publication_formatter, + "publications": _publication_formatter, + "publisher": _publisher_formatter, + "publishers": _publisher_formatter, + "series": _series_formatter, + "serieses": _series_formatter, + "subject": _subject_formatter, + "subjects": _subject_formatter, + "work": _work_formatter, + "workByDoi": _work_formatter, + "works": _work_formatter, +} + +# this stores the original function pointer of Munch.__repr__ so that we can +# re-inject it above in "_munch_repr" +munch_local = Munch.__repr__ + + +class StructureBuilder: + """A class to build a Thoth object structure""" + + def __init__(self, structure, data): + self.structure = structure + self.data = data + + def create_structure(self): + """ + Creates an object structure from dictionary input + @return: an object + """ + structures = [] + if isinstance(self.data, list): + for item in self.data: + x = self._munch(item) + structures.append(x) + else: + x = self._munch(self.data) + return x + + return structures + + def _munch(self, item): + """ + Converts our JSON or dict object into an addressable object. + Also sets up the Munch __repr__ and __str__ functions. + @param item: the item to convert + @return: a converted object with string representation + """ + x = Munch.fromDict(item) + if self.structure in default_fields.keys(): + struct = default_fields[self.structure] + Munch.__repr__ = Munch.__str__ + Munch.__str__ = struct + return x From cad70f975b2c671ec6d72c59d3d6758921d1c259 Mon Sep 17 00:00:00 2001 From: Luca Baffa Date: Fri, 11 Mar 2022 12:26:59 +0000 Subject: [PATCH 2/8] remove width and height field from work, works, and workById queries --- thothlibrary/thoth-0_8_0/fixtures/QUERIES | 6 ------ 1 file changed, 6 deletions(-) diff --git a/thothlibrary/thoth-0_8_0/fixtures/QUERIES b/thothlibrary/thoth-0_8_0/fixtures/QUERIES index be7124f..36876b6 100644 --- a/thothlibrary/thoth-0_8_0/fixtures/QUERIES +++ b/thothlibrary/thoth-0_8_0/fixtures/QUERIES @@ -493,8 +493,6 @@ "doi", "publicationDate", "place", - "width", - "height", "pageCount", "pageBreakdown", "imageCount", @@ -537,8 +535,6 @@ "doi", "publicationDate", "place", - "width", - "height", "pageCount", "pageBreakdown", "imageCount", @@ -587,8 +583,6 @@ "doi", "publicationDate", "place", - "width", - "height", "pageCount", "pageBreakdown", "imageCount", From 19dee66a0e2e29e8e92d84b2a749f2b08cfc94ae Mon Sep 17 00:00:00 2001 From: Luca Baffa Date: Fri, 11 Mar 2022 12:42:17 +0000 Subject: [PATCH 3/8] add width, height, depth and weight to the publication schema --- thothlibrary/thoth-0_8_0/fixtures/QUERIES | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/thothlibrary/thoth-0_8_0/fixtures/QUERIES b/thothlibrary/thoth-0_8_0/fixtures/QUERIES index 36876b6..9b328c1 100644 --- a/thothlibrary/thoth-0_8_0/fixtures/QUERIES +++ b/thothlibrary/thoth-0_8_0/fixtures/QUERIES @@ -319,6 +319,10 @@ "publicationType", "workId", "isbn", + "width", + "height", + "depth", + "weight", "locations { locationId landingPage locationPlatform canonical }", "createdAt", "updatedAt", From 59368f9a6d00cbd77b26c43002e82d9eaa5353ec Mon Sep 17 00:00:00 2001 From: Luca Baffa Date: Fri, 11 Mar 2022 13:12:47 +0000 Subject: [PATCH 4/8] add publication -> publicationId to workByDoi query --- thothlibrary/thoth-0_8_0/fixtures/QUERIES | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/thothlibrary/thoth-0_8_0/fixtures/QUERIES b/thothlibrary/thoth-0_8_0/fixtures/QUERIES index 9b328c1..d42b712 100644 --- a/thothlibrary/thoth-0_8_0/fixtures/QUERIES +++ b/thothlibrary/thoth-0_8_0/fixtures/QUERIES @@ -556,7 +556,7 @@ "toc", "coverUrl", "coverCaption", - "publications { isbn publicationType locations { locationId landingPage fullTextUrl locationPlatform } __typename }", + "publications { isbn publicationType publicationId locations { locationId landingPage fullTextUrl locationPlatform } __typename }", "subjects { subjectId, subjectType, subjectCode, subjectOrdinal, __typename }", "contributions { fullName contributionType mainContribution contributor { contributorId orcid firstName lastName fullName } contributionId contributionOrdinal __typename }", "imprint { __typename publisher { publisherName publisherId __typename } }", From 4f72420b98b380314da2c77dc9973f0e0e6d8ad0 Mon Sep 17 00:00:00 2001 From: Luca Baffa Date: Fri, 11 Mar 2022 15:24:16 +0000 Subject: [PATCH 5/8] update schema by moving width and height data to publication type --- thothlibrary/mutation.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/thothlibrary/mutation.py b/thothlibrary/mutation.py index ed871a9..ca70957 100644 --- a/thothlibrary/mutation.py +++ b/thothlibrary/mutation.py @@ -58,8 +58,6 @@ class ThothMutation(): ("doi", True), ("publicationDate", True), ("place", True), - ("width", False), - ("height", False), ("pageCount", False), ("pageBreakdown", True), ("imageCount", False), @@ -84,6 +82,10 @@ class ThothMutation(): "fields": [ ("publicationType", False), ("workId", True), + ("width", False), + ("height", False), + ("depth", False), + ("weight", False), ("isbn", True) ], "return_value": "publicationId" @@ -213,8 +215,6 @@ class ThothMutation(): ("doi", True), ("publicationDate", True), ("place", True), - ("width", False), - ("height", False), ("pageCount", False), ("pageBreakdown", True), ("imageCount", False), From 4a8a1dc0f67266dfbdadc59d5f38d7339c030647 Mon Sep 17 00:00:00 2001 From: Luca Baffa Date: Fri, 11 Mar 2022 15:28:57 +0000 Subject: [PATCH 6/8] remove unit support in mutations --- thothlibrary/cli.py | 2 +- thothlibrary/client.py | 4 ++-- thothlibrary/mutation.py | 10 ++-------- 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/thothlibrary/cli.py b/thothlibrary/cli.py index eddab38..ab403ca 100644 --- a/thothlibrary/cli.py +++ b/thothlibrary/cli.py @@ -1012,7 +1012,7 @@ def update_cover(self, doi=None, work_id=None, url=None, version=None, client.login(self.thoth_email, self.thoth_pwd) - mutation = client.mutation('updateWork', data, units='MM') + mutation = client.mutation('updateWork', data) if __name__ == '__main__': diff --git a/thothlibrary/client.py b/thothlibrary/client.py index 3a3456b..bb7e708 100644 --- a/thothlibrary/client.py +++ b/thothlibrary/client.py @@ -54,9 +54,9 @@ def login(self, email, password): bearer = "Bearer {}".format(auth.get_token()) self.client.inject_token(bearer) - def mutation(self, mutation_name, data, units=False): + def mutation(self, mutation_name, data): """Instantiate a thoth mutation and execute""" - mutation = ThothMutation(mutation_name, data, units) + mutation = ThothMutation(mutation_name, data) return mutation.run(self.client) def query(self, query_name, parameters, raw=False): diff --git a/thothlibrary/mutation.py b/thothlibrary/mutation.py index ca70957..cc8b3dc 100644 --- a/thothlibrary/mutation.py +++ b/thothlibrary/mutation.py @@ -237,7 +237,7 @@ class ThothMutation(): } } - def __init__(self, mutation_name, mutation_data, units=False): + def __init__(self, mutation_name, mutation_data): """Returns new ThothMutation object with specified mutation data mutation_name: Must match one of the keys found in MUTATIONS. @@ -245,7 +245,6 @@ def __init__(self, mutation_name, mutation_data, units=False): mutation_data: Dictionary of mutation fields and their values. """ self.mutation_name = mutation_name - self.units = units self.return_value = self.MUTATIONS[mutation_name]["return_value"] self.mutation_data = mutation_data self.data_str = self.generate_values() @@ -256,17 +255,12 @@ def prepare_request(self): values = { "mutation_name": self.mutation_name, "data": self.data_str, - "return_value": self.return_value, - "units": "" + "return_value": self.return_value } - if self.units: - values.update({"units": "units: {},".format(self.units)}) - payload = """ mutation { %(mutation_name)s( - %(units)s data: { %(data)s } From 9ece7111b4586f9731a4f0c9b36b5ed7ec5e8f86 Mon Sep 17 00:00:00 2001 From: Luca Baffa Date: Mon, 14 Mar 2022 09:28:46 +0000 Subject: [PATCH 7/8] add thoth v8.0 to the list in `setup.py` --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index 3c4e689..b8bb91b 100644 --- a/setup.py +++ b/setup.py @@ -25,6 +25,7 @@ "thothrest.thoth-0_4_2", "thothlibrary.thoth-0_5_0", "thothlibrary.thoth-0_6_0", + "thothlibrary.thoth-0_8_0" ], include_package_data=True, install_requires=["graphqlclient", "requests", "munch"], From 7e66af2fa8c91e7300615312c2282b1af520785e Mon Sep 17 00:00:00 2001 From: Javier Arias Date: Fri, 18 Mar 2022 11:12:41 +0000 Subject: [PATCH 8/8] Bump v0.11.0 --- README.md | 2 +- thothlibrary/__init__.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9f087a1..4258d8b 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.10.5 +python3 -m pip install thothlibrary==0.11.0 ``` Or from the repo: diff --git a/thothlibrary/__init__.py b/thothlibrary/__init__.py index 86922a9..136fd7b 100644 --- a/thothlibrary/__init__.py +++ b/thothlibrary/__init__.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 """GraphQL client for Thoth""" -__version__ = "0.10.5" +__version__ = "0.11.0" __author__ = "Javier Arias " __copyright__ = "Copyright (c) 2020 Open Book Publishers" __license__ = "Apache 2.0"