Skip to content

Commit

Permalink
Merge branch 'release/v0.7.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
ja573 committed Dec 7, 2021
2 parents 004a50f + ba1ca5f commit 4e217d2
Show file tree
Hide file tree
Showing 220 changed files with 6,164 additions and 56 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Python client for Thoth's GraphQL and REST APIs
Python client for Thoth's GraphQL and REST APIs. Currently supports Thoth version 0.6.0.

[![Build Status](https://travis-ci.org/openbookpublishers/thoth-client.svg?branch=master)](https://travis-ci.org/openbookpublishers/thoth-client) [![Release](https://img.shields.io/github/release/openbookpublishers/thoth-client.svg?colorB=58839b)](https://github.com/openbookpublishers/thoth-client/releases) [![License](https://img.shields.io/github/license/openbookpublishers/thoth-client.svg?colorB=ff0000)](https://github.com/openbookpublishers/thoth-client/blob/master/LICENSE)

Expand All @@ -9,7 +9,7 @@ Install is either via pip or cloning the repository.

From pip:
```sh
python3 -m pip install thothlibrary==0.6.2
python3 -m pip install thothlibrary==0.7.0
```

Or from the repo:
Expand All @@ -23,7 +23,7 @@ pip3 install -r ./requirements.txt
```python
from thothlibrary import ThothClient

thoth = ThothClient(version="0.4.2")
thoth = ThothClient(version="0.6.0")
print(thoth.works())
```

Expand All @@ -35,8 +35,8 @@ python3 -m thothlibrary.cli contribution_count
python3 -m thothlibrary.cli contributor --contributor_id=e8def8cf-0dfe-4da9-b7fa-f77e7aec7524
python3 -m thothlibrary.cli contributors --limit=10
python3 -m thothlibrary.cli contributor_count --search="Vincent"
python3 -m thothlibrary.cli funder --funder_id=194614ac-d189-4a74-8bf4-74c0c9de4a81
python3 -m thothlibrary.cli funders --limit=10
python3 -m thothlibrary.cli institution --institution_id=194614ac-d189-4a74-8bf4-74c0c9de4a81
python3 -m thothlibrary.cli institutions --limit=10
python3 -m thothlibrary.cli funder_count
python3 -m thothlibrary.cli funding --funding_id=5323d3e7-3ae9-4778-8464-9400fbbb959e
python3 -m thothlibrary.cli fundings --limit=10
Expand All @@ -52,7 +52,7 @@ python3 -m thothlibrary.cli language_count --language_code=CHI
python3 -m thothlibrary.cli price --price_id=818567dd-7d3a-4963-8704-3381b5432877
python3 -m thothlibrary.cli prices --limit=10 --currency_code=GBP
python3 -m thothlibrary.cli price_count --currency_code=GBP
python3 -m thothlibrary.cli publication --publication_id=34712b75-dcdd-408b-8d0c-cf29a35be2e5
python3 -m thothlibrary.cli publication --publication_id=27b7bdab-e9e5-4220-811e-1f370861f5e1
python3 -m thothlibrary.cli publications --limit=10 --publishers='["85fd969a-a16c-480b-b641-cb9adf979c3b"]'
python3 -m thothlibrary.cli publication_count --publication_type="HARDBACK"
python3 -m thothlibrary.cli publisher --publisher_id=85fd969a-a16c-480b-b641-cb9adf979c3b
Expand Down
29 changes: 29 additions & 0 deletions thothdjango/management/commands/fetch_ROR.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""
(c) ΔQ Programming LLP, 2021
This program is free software; you may redistribute and/or modify
it under the terms of the Apache License v2.0.
"""
import os
import pathlib

import requests
from django.core.management.base import BaseCommand


class Command(BaseCommand):
"""
A management command that fetches and installs the latest ROR support
"""

help = "Installs ROR functionality into Thoth components"

def handle(self, *args, **options):
url = 'https://zenodo.org/api/records/' \
'?communities=ror-data&sort=mostrecent'

meta_response = requests.get(url)

print(meta_response)

print("ROR fixtures installed. At next Thoth sync, ROR functionality "
"will be enabled.")
2 changes: 1 addition & 1 deletion thothlibrary/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python3
"""GraphQL client for Thoth"""

__version__ = "0.6.2"
__version__ = "0.7.0"
__author__ = "Javier Arias <[email protected]>"
__copyright__ = "Copyright (c) 2020 Open Book Publishers"
__license__ = "Apache 2.0"
Expand Down
24 changes: 13 additions & 11 deletions thothlibrary/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def __init__(self):
A Thoth CLI client
"""
self.endpoint = "https://api.thoth.pub"
self.version = "0.4.2"
self.version = "0.6.0"

def _client(self):
"""
Expand Down Expand Up @@ -197,30 +197,31 @@ def contributor_count(self, search=None, raw=False, version=None,
print(self._client().contributor_count(search=search, raw=raw))

@fire.decorators.SetParseFn(_raw_parse)
def funder(self, funder_id, raw=False, version=None, endpoint=None,
serialize=False):
def institution(self, institution_id, raw=False, version=None,
endpoint=None, serialize=False):
"""
Retrieves a funder by ID from a Thoth instance
:param str funder_id: the funder to fetch
Retrieves an institution by ID from a Thoth instance
:param str institution_id: the institution to fetch
:param bool raw: whether to return a python object or the raw result
:param str version: a custom Thoth version
:param str endpoint: a custom Thoth endpoint
:param bool serialize: return a pickled python object
"""
self._override_version(version=version, endpoint=endpoint)

funder = self._client().funder(funder_id=funder_id, raw=raw)
funder = self._client().institution(institution_id=institution_id,
raw=raw)

if not serialize:
print(funder)
else:
print(json.dumps(funder))

@fire.decorators.SetParseFn(_raw_parse)
def funders(self, limit=100, order=None, offset=0, search=None, raw=False,
version=None, endpoint=None, serialize=False):
def institutions(self, limit=100, order=None, offset=0, search=None,
raw=False, version=None, endpoint=None, serialize=False):
"""
Retrieves funders from a Thoth instance
Retrieves institutions from a Thoth instance
:param int limit: the maximum number of results to return
:param int order: a GraphQL order query statement
:param int offset: the offset from which to retrieve results
Expand All @@ -232,8 +233,9 @@ def funders(self, limit=100, order=None, offset=0, search=None, raw=False,
"""
self._override_version(version=version, endpoint=endpoint)

funders = self._client().funders(limit=limit, order=order,
offset=offset, search=search, raw=raw)
funders = self._client().institutions(limit=limit, order=order,
offset=offset, search=search,
raw=raw)

if not raw and not serialize:
print(*funders, sep='\n')
Expand Down
2 changes: 1 addition & 1 deletion thothlibrary/thoth-0_4_2/tests/fixtures/contributions.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"data":{"contributions":[{"contributionId":"1a3ef666-c624-4240-a176-b510ff899040","contributionType":"AUTHOR","mainContribution":true,"biography":null,"institution":null,"__typename":"Contribution","firstName":"Daniela","lastName":"Cascella","fullName":"Daniela Cascella","contributionOrdinal":1,"workId":"a01f41d6-1da8-4b0b-87b4-82ecc41c6d55","work":{"fullTitle":"Nothing As We Need It: A Chimera"},"contributor":{"firstName":"Daniela","lastName":"Cascella","fullName":"Daniela Cascella","orcid":"https://orcid.org/0000-0001-7995-5915","__typename":"Contributor","website":"http://www.danielacascella.com","contributorId":"1fab9df5-d9b4-4695-973e-ebb052b184ff"}},{"contributionId":"29e4f46b-851a-4d7b-bb41-e6f305fc2b11","contributionType":"AUTHOR","mainContribution":true,"biography":null,"institution":null,"__typename":"Contribution","firstName":"Sara A.","lastName":"Rich","fullName":"Sara A. Rich","contributionOrdinal":1,"workId":"501a8862-dc30-4d1e-ab47-deb9f5579678","work":{"fullTitle":"Closer to Dust"},"contributor":{"firstName":"Sara A.","lastName":"Rich","fullName":"Sara A. Rich","orcid":"https://orcid.org/0000-0001-9176-8514","__typename":"Contributor","website":null,"contributorId":"c145d392-c37e-41b6-9225-1c3a1a46f460"}}]}}
{"data":{"contributions":[{"contributionId":"a4049dd5-bfad-4f92-8c02-fa0956e8e6e5","contributionType":"AUTHOR","mainContribution":true,"biography":null,"institution":null,"__typename":"Contribution","firstName":"Darren R.","lastName":"Reid","fullName":"Darren R. Reid","contributionOrdinal":1,"workId":"b31b6f95-4dd4-4fa9-9c55-803ce2fd36ff","work":{"fullTitle":"Documentary Making for Digital Humanists"},"contributor":{"firstName":"Darren R.","lastName":"Reid","fullName":"Darren R. Reid","orcid":"https://orcid.org/0000-0002-5785-1071","__typename":"Contributor","website":"http://www.darrenreidhistory.co.uk/","contributorId":"48a6d221-aba6-458b-901a-a857eafd5bcc"}},{"contributionId":"1a3ef666-c624-4240-a176-b510ff899040","contributionType":"AUTHOR","mainContribution":true,"biography":null,"institution":null,"__typename":"Contribution","firstName":"Daniela","lastName":"Cascella","fullName":"Daniela Cascella","contributionOrdinal":1,"workId":"a01f41d6-1da8-4b0b-87b4-82ecc41c6d55","work":{"fullTitle":"Nothing As We Need It: A Chimera"},"contributor":{"firstName":"Daniela","lastName":"Cascella","fullName":"Daniela Cascella","orcid":"https://orcid.org/0000-0001-7995-5915","__typename":"Contributor","website":"http://www.danielacascella.com","contributorId":"1fab9df5-d9b4-4695-973e-ebb052b184ff"}}]}}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"contributionId": "1a3ef666-c624-4240-a176-b510ff899040", "contributionType": "AUTHOR", "mainContribution": true, "biography": null, "institution": null, "__typename": "Contribution", "firstName": "Daniela", "lastName": "Cascella", "fullName": "Daniela Cascella", "contributionOrdinal": 1, "workId": "a01f41d6-1da8-4b0b-87b4-82ecc41c6d55", "work": {"fullTitle": "Nothing As We Need It: A Chimera"}, "contributor": {"firstName": "Daniela", "lastName": "Cascella", "fullName": "Daniela Cascella", "orcid": "https://orcid.org/0000-0001-7995-5915", "__typename": "Contributor", "website": "http://www.danielacascella.com", "contributorId": "1fab9df5-d9b4-4695-973e-ebb052b184ff"}}, {"contributionId": "29e4f46b-851a-4d7b-bb41-e6f305fc2b11", "contributionType": "AUTHOR", "mainContribution": true, "biography": null, "institution": null, "__typename": "Contribution", "firstName": "Sara A.", "lastName": "Rich", "fullName": "Sara A. Rich", "contributionOrdinal": 1, "workId": "501a8862-dc30-4d1e-ab47-deb9f5579678", "work": {"fullTitle": "Closer to Dust"}, "contributor": {"firstName": "Sara A.", "lastName": "Rich", "fullName": "Sara A. Rich", "orcid": "https://orcid.org/0000-0001-9176-8514", "__typename": "Contributor", "website": null, "contributorId": "c145d392-c37e-41b6-9225-1c3a1a46f460"}}]
[{"contributionId": "a4049dd5-bfad-4f92-8c02-fa0956e8e6e5", "contributionType": "AUTHOR", "mainContribution": true, "biography": null, "institution": null, "__typename": "Contribution", "firstName": "Darren R.", "lastName": "Reid", "fullName": "Darren R. Reid", "contributionOrdinal": 1, "workId": "b31b6f95-4dd4-4fa9-9c55-803ce2fd36ff", "work": {"fullTitle": "Documentary Making for Digital Humanists"}, "contributor": {"firstName": "Darren R.", "lastName": "Reid", "fullName": "Darren R. Reid", "orcid": "https://orcid.org/0000-0002-5785-1071", "__typename": "Contributor", "website": "http://www.darrenreidhistory.co.uk/", "contributorId": "48a6d221-aba6-458b-901a-a857eafd5bcc"}}, {"contributionId": "1a3ef666-c624-4240-a176-b510ff899040", "contributionType": "AUTHOR", "mainContribution": true, "biography": null, "institution": null, "__typename": "Contribution", "firstName": "Daniela", "lastName": "Cascella", "fullName": "Daniela Cascella", "contributionOrdinal": 1, "workId": "a01f41d6-1da8-4b0b-87b4-82ecc41c6d55", "work": {"fullTitle": "Nothing As We Need It: A Chimera"}, "contributor": {"firstName": "Daniela", "lastName": "Cascella", "fullName": "Daniela Cascella", "orcid": "https://orcid.org/0000-0001-7995-5915", "__typename": "Contributor", "website": "http://www.danielacascella.com", "contributorId": "1fab9df5-d9b4-4695-973e-ebb052b184ff"}}]
2 changes: 1 addition & 1 deletion thothlibrary/thoth-0_4_2/tests/fixtures/funder.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"data":{"funder":{"funderId":"194614ac-d189-4a74-8bf4-74c0c9de4a81","funderName":"The Danish Independent Research Council","funderDoi":null,"fundings":[{"grantNumber":"0602-02551B","program":"FSE","projectName":"Marine Renewable Energy as Alien","jurisdiction":"DK","work":{"workId":"95e15115-4009-4cb0-8824-011038e3c116","fullTitle":"Energy Worlds: In Experiment","doi":"https://doi.org/10.28938/9781912729098","publicationDate":"2021-05-01","place":"Manchester","contributions":[{"fullName":"Brit Ross Winthereik","contributionType":"AUTHOR","mainContribution":true,"contributionOrdinal":3},{"fullName":"Laura Watts","contributionType":"EDITOR","mainContribution":true,"contributionOrdinal":2},{"fullName":"James Maguire","contributionType":"EDITOR","mainContribution":true,"contributionOrdinal":1}],"imprint":{"publisher":{"publisherName":"Mattering Press","publisherId":"17d701c1-307e-4228-83ca-d8e90d7b87a6"}}}}],"__typename":"Funder"}}}
{"data":{"funder":{"funderId":"194614ac-d189-4a74-8bf4-74c0c9de4a81","funderName":"The Danish Independent Research Council","funderDoi":null,"fundings":[{"grantNumber":"0602-02551B","program":"FSE","projectName":"Marine Renewable Energy as Alien","jurisdiction":"DK","work":{"workId":"95e15115-4009-4cb0-8824-011038e3c116","fullTitle":"Energy Worlds: In Experiment","doi":"https://doi.org/10.28938/9781912729098","publicationDate":"2021-05-01","place":"Manchester, UK","contributions":[{"fullName":"Brit Ross Winthereik","contributionType":"AUTHOR","mainContribution":true,"contributionOrdinal":3},{"fullName":"James Maguire","contributionType":"EDITOR","mainContribution":true,"contributionOrdinal":1},{"fullName":"Laura Watts","contributionType":"EDITOR","mainContribution":true,"contributionOrdinal":2}],"imprint":{"publisher":{"publisherName":"Mattering Press","publisherId":"17d701c1-307e-4228-83ca-d8e90d7b87a6"}}}}],"__typename":"Funder"}}}
2 changes: 1 addition & 1 deletion thothlibrary/thoth-0_4_2/tests/fixtures/funder.pickle
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"funderId": "194614ac-d189-4a74-8bf4-74c0c9de4a81", "funderName": "The Danish Independent Research Council", "funderDoi": null, "fundings": [{"grantNumber": "0602-02551B", "program": "FSE", "projectName": "Marine Renewable Energy as Alien", "jurisdiction": "DK", "work": {"workId": "95e15115-4009-4cb0-8824-011038e3c116", "fullTitle": "Energy Worlds: In Experiment", "doi": "https://doi.org/10.28938/9781912729098", "publicationDate": "2021-05-01", "place": "Manchester", "contributions": [{"fullName": "Brit Ross Winthereik", "contributionType": "AUTHOR", "mainContribution": true, "contributionOrdinal": 3}, {"fullName": "Laura Watts", "contributionType": "EDITOR", "mainContribution": true, "contributionOrdinal": 2}, {"fullName": "James Maguire", "contributionType": "EDITOR", "mainContribution": true, "contributionOrdinal": 1}], "imprint": {"publisher": {"publisherName": "Mattering Press", "publisherId": "17d701c1-307e-4228-83ca-d8e90d7b87a6"}}}}], "__typename": "Funder"}
{"funderId": "194614ac-d189-4a74-8bf4-74c0c9de4a81", "funderName": "The Danish Independent Research Council", "funderDoi": null, "fundings": [{"grantNumber": "0602-02551B", "program": "FSE", "projectName": "Marine Renewable Energy as Alien", "jurisdiction": "DK", "work": {"workId": "95e15115-4009-4cb0-8824-011038e3c116", "fullTitle": "Energy Worlds: In Experiment", "doi": "https://doi.org/10.28938/9781912729098", "publicationDate": "2021-05-01", "place": "Manchester, UK", "contributions": [{"fullName": "Brit Ross Winthereik", "contributionType": "AUTHOR", "mainContribution": true, "contributionOrdinal": 3}, {"fullName": "James Maguire", "contributionType": "EDITOR", "mainContribution": true, "contributionOrdinal": 1}, {"fullName": "Laura Watts", "contributionType": "EDITOR", "mainContribution": true, "contributionOrdinal": 2}], "imprint": {"publisher": {"publisherName": "Mattering Press", "publisherId": "17d701c1-307e-4228-83ca-d8e90d7b87a6"}}}}], "__typename": "Funder"}
Loading

0 comments on commit 4e217d2

Please sign in to comment.