Skip to content

Commit

Permalink
Introduced state attribute to Orcid class to choose b/w which API to …
Browse files Browse the repository at this point in the history
…use (public/member)
  • Loading branch information
sri0606 committed Sep 6, 2023
1 parent 600e5f8 commit ee14d16
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/pyorcid/orcid.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ class Orcid():
'''
This is a wrapper class for ORCID API
'''
def __init__(self,orcid_id) -> None:
def __init__(self,orcid_id, state="public") -> None:
'''
Initialize orcid instance
orcid_id : Orcid ID of the user
state : Whether to use public or member API of ORCID
'''
self._orcid_id = orcid_id

self._state = state
#For testing purposes (pytesting on github workflow)
try:
self.__test_is_access_token_valid()
Expand Down Expand Up @@ -67,17 +68,22 @@ def __read_section(self,section="record"):
'Authorization': f'Bearer {access_token}',
'Content-Type': 'application/json'
}
api_url = ""

# # Specify the ORCID record endpoint for the desired ORCID iD
api_url = f'https://pub.orcid.org/v3.0/{self._orcid_id}/{section}'
if self._state == "public":
# Specify the ORCID record endpoint for the desired ORCID iD
api_url = f'https://pub.orcid.org/v3.0/{self._orcid_id}/{section}'

elif self._state == "member":
api_url = f'https://api.sandbox.orcid.org/v3.0/{self._orcid_id}/{section}'

# Make a GET request to retrieve the ORCID record
response = requests.get(api_url, headers=headers)

# The request was successful
data = response.json()
# Check the response status code
if response.status_code == 200:
if response.status_code == 200 or data is not None:
return data
else:
# Handle the case where the request failed
Expand Down

0 comments on commit ee14d16

Please sign in to comment.