forked from pybliometrics-dev/pybliometrics
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pybliometrics-dev#351 Implementation of ScienceDirect ArticleEntitlement
- Loading branch information
1 parent
3aba0a6
commit 630051e
Showing
5 changed files
with
137 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
"""Module for retrieving article entitlement information from ScienceDirect.""" | ||
from typing import Optional, Union | ||
|
||
from pybliometrics.superclasses import Retrieval | ||
from pybliometrics.utils import ( | ||
chained_get, | ||
check_parameter_value, | ||
detect_id_type, | ||
VIEWS, | ||
) | ||
|
||
|
||
class ArticleEntitlement(Retrieval): | ||
"""Class to retrieve the entitlement status for a document from ScienceDirect.""" | ||
@property | ||
def status(self) -> Optional[str]: | ||
"""Status of whether a document has been found""" | ||
return self._json.get("@status") | ||
|
||
@property | ||
def identifier(self) -> Optional[str]: | ||
"""Identifier of a document.""" | ||
return self._json.get("dc:identifier") | ||
|
||
@property | ||
def eid(self) -> Optional[str]: | ||
"The eid of a document." | ||
return self._json.get("eid") | ||
|
||
@property | ||
def entitled(self) -> Optional[str]: | ||
"""Entitlement status of a document.""" | ||
return self._json.get("entitled") | ||
|
||
@property | ||
def link(self) -> Optional[str]: | ||
"""ScienceDirect canonical URL.""" | ||
return chained_get(self._json, ['link', '@href']) | ||
|
||
@property | ||
def message(self) -> Optional[str]: | ||
"""Entitlement status message.""" | ||
return self._json.get("message") | ||
|
||
@property | ||
def pii(self) -> Optional[str]: | ||
"""The pii of a document.""" | ||
return self._json.get("pii") | ||
|
||
@property | ||
def pii_norm(self) -> Optional[str]: | ||
"""The pii-norm of a document.""" | ||
return self._json.get("pii-norm") | ||
|
||
@property | ||
def doi(self) -> Optional[str]: | ||
"""The doi of a document.""" | ||
return self._json.get("prism:doi") | ||
|
||
@property | ||
def pubmed_id(self) -> Optional[str]: | ||
"""The pubmed_id of a document (when used in the request).""" | ||
return self._json.get("pubmed_id") | ||
|
||
@property | ||
def url(self) -> Optional[str]: | ||
"""API url used to check entitlement.""" | ||
return self._json.get("prism:url") | ||
|
||
|
||
@property | ||
def scopus_id(self) -> Optional[str]: | ||
"""The scopus_id of a document (when used in the request).""" | ||
return self._json.get("scopus_id") | ||
|
||
def __init__(self, | ||
identifier: Union[int, str], | ||
view: str = "FULL", | ||
id_type: Optional[str] = None, | ||
refresh: Union[bool, int] = False, | ||
**kwds: str) -> None: | ||
|
||
# Checks | ||
identifier = str(identifier) | ||
check_parameter_value(view, VIEWS["ArticleEntitlement"], "view") | ||
if not id_type: | ||
id_type = detect_id_type(identifier) | ||
else: | ||
allowed_id_types = ("eid", "pii", "scopus_id", "pubmed_id", "doi", "pui") | ||
check_parameter_value(id_type, allowed_id_types, "id_type") | ||
|
||
self._view = view | ||
self._refresh = refresh | ||
|
||
Retrieval.__init__(self, identifier=identifier, id_type=id_type, **kwds) | ||
|
||
self._json = chained_get(self._json, ["entitlement-response", "document-entitlement"]) | ||
|
||
def __str__(self) -> str: | ||
s = self.message | ||
s += f' with doi: {self.doi}' | ||
return s |
29 changes: 29 additions & 0 deletions
29
pybliometrics/sciencedirect/tests/test_ArticleEntitlement.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
"""Tests for sciencedirect.ArticleEntitlement""" | ||
from pybliometrics.sciencedirect import ArticleEntitlement, init | ||
|
||
init() | ||
|
||
ae_1 = ArticleEntitlement('10.1016/j.reseneeco.2015.06.001', view='FULL', id_type='doi', refresh=30) | ||
ae_2 = ArticleEntitlement('S0140988320302814', view='FULL', refresh=30) | ||
|
||
|
||
def test_all_fields(): | ||
"""Test all propoerties of ArticleEntitlement.""" | ||
assert ae_1.doi == '10.1016/j.reseneeco.2015.06.001' | ||
assert ae_1.eid == '1-s2.0-S092876551500038X' | ||
assert ae_1.entitled is True | ||
assert ae_1.identifier == 'http://dx.doi.org/10.1016/j.reseneeco.2015.06.001' | ||
assert ae_1.link == 'https://www.sciencedirect.com/science/article/pii/S092876551500038X' | ||
assert ae_1.message == 'Requestor is entitled to the requested resource' | ||
assert ae_1.pii == 'S0928-7655(15)00038-X' | ||
assert ae_1.pii_norm == 'S092876551500038X' | ||
assert ae_1.pubmed_id is None | ||
assert ae_1.scopus_id == '84935028440' | ||
assert ae_1.status == 'found' | ||
assert ae_1.url == 'https://api.elsevier.com/content/article/pii/S092876551500038X' | ||
|
||
|
||
def test_str(): | ||
"""Test print message.""" | ||
expected_str = 'Requestor is entitled to the requested resource with doi: 10.1016/j.eneco.2020.104941' | ||
assert ae_2.__str__() == expected_str |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters