Skip to content

Commit

Permalink
Merge pull request #27 from UAL-RE/feature/26_orcid_info
Browse files Browse the repository at this point in the history
Add method to retrieve ORCID and Figshare account ID for users
  • Loading branch information
astrochun committed Jul 7, 2021
2 parents 61e9394 + 9fac094 commit c7706af
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 7 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,16 @@
# Changelog

## [v0.3.2](https://github.com/UAL-RE/ldcoolp-figshare/tree/v0.3.2) (2021-07-07)

**Implemented enhancements:**
- Add method to retrieve ORCID and Figshare account ID for users
[#27](https://github.com/UAL-RE/ldcoolp-figshare/pull/27)

**Closed issues:**
- Add method to retrieve ORCID and Figshare account ID for users
[#26](https://github.com/UAL-RE/ldcoolp-figshare/issues/26)


## [v0.3.1](https://github.com/UAL-RE/ldcoolp-figshare/tree/v0.3.1) (2021-07-01)

**Merged pull requests:**
Expand Down
2 changes: 1 addition & 1 deletion docs/source/conf.py
Expand Up @@ -24,7 +24,7 @@
author = 'Chun Ly, UA Research Data Repository (ReDATA) Team'

# The full version, including alpha/beta/rc tags
release = 'v0.3.1'
release = 'v0.3.2'


# -- General configuration ---------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion ldcoolp_figshare/__init__.py
@@ -1,3 +1,3 @@
__version__ = "0.3.1"
__version__ = "0.3.2"

from .main import FigshareInstituteAdmin
36 changes: 32 additions & 4 deletions ldcoolp_figshare/main.py
Expand Up @@ -106,7 +106,7 @@ def get_user_articles(self, account_id: int, process: bool = True) \
See: https://docs.figshare.com/#private_articles_list
:param account_id: Figshare account ID
:param account_id: Figshare *institute* account ID
:param process: Returns JSON content from ``redata_request``, otherwise
the full request is provided. Default: True
Expand Down Expand Up @@ -135,7 +135,7 @@ def get_user_projects(self, account_id: int, process: bool = True) \
See: https://docs.figshare.com/#private_projects_list
:param account_id: Figshare account ID
:param account_id: Figshare *institute* account ID
:param process: Returns JSON content from ``redata_request``, otherwise
the full request is provided. Default: True
Expand Down Expand Up @@ -164,7 +164,7 @@ def get_user_collections(self, account_id: int, process: bool = True) \
See: https://docs.figshare.com/#private_collections_list
:param account_id: Figshare account ID
:param account_id: Figshare *institute* account ID
:param process: Returns JSON content from ``redata_request``, otherwise
the full request is provided. Default: True
Expand Down Expand Up @@ -253,7 +253,7 @@ def get_account_group_roles(self, account_id: int, process: bool = True) \
See: https://docs.figshare.com/#private_institution_account_group_roles
:param account_id: Figshare account ID
:param account_id: Figshare *institute* account ID
:param process: Returns JSON content from ``redata_request``, otherwise
the full request is provided. Default: True
Expand Down Expand Up @@ -289,13 +289,21 @@ def get_account_details(self, flag: bool = True) -> pd.DataFrame:
num_projects = np.zeros(n_accounts, dtype=np.intc)
num_collections = np.zeros(n_accounts, dtype=np.intc)

orcid_num = [''] * n_accounts
user_id = np.zeros(n_accounts, dtype=np.intc) # This is the Figshare user ID

if flag:
admin_flag = [''] * n_accounts
reviewer_flag = [''] * n_accounts
group_assoc = ['N/A'] * n_accounts

# Determine group roles for each account
for n, account_id in zip(range(n_accounts), accounts_df['id']):
# Save ORCID and account ID
other_account_dict = self.get_other_account_details(account_id)
orcid_num[n] = other_account_dict['orcid_id']
user_id[n] = other_account_dict['id']

roles = self.get_account_group_roles(account_id)

try:
Expand Down Expand Up @@ -336,6 +344,9 @@ def get_account_details(self, flag: bool = True) -> pd.DataFrame:
accounts_df['Projects'] = num_projects
accounts_df['Collections'] = num_collections

accounts_df['ORCID'] = orcid_num
accounts_df['user_id'] = user_id

if flag:
accounts_df['Admin'] = admin_flag
accounts_df['Reviewer'] = reviewer_flag
Expand All @@ -348,6 +359,23 @@ def get_account_details(self, flag: bool = True) -> pd.DataFrame:
accounts_df['Group'] = group_assoc
return accounts_df

def get_other_account_details(self, account_id: int) -> dict:
"""
Retrieve ORCID and Figshare account information (among other metadata)
See: https://docs.figshare.com/#private_account_institution_user
:param account_id: Figshare *institute* account ID
:return: Dictionary with full account details
"""

url = self.endpoint(f"users/{account_id}", institute=True)

other_account_dict = redata_request('GET', url, self.headers)

return other_account_dict

def get_curation_list(self, article_id: int = None,
status: Optional[str] = "", process: bool = True) \
-> Union[pd.DataFrame, Response]:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -8,7 +8,7 @@

setup(
name='ldcoolp-figshare',
version='0.3.1',
version='0.3.2',
packages=find_namespace_packages(),
url='https://github.com/UAL-RE/ldcoolp-figshare/',
project_urls={
Expand Down

0 comments on commit c7706af

Please sign in to comment.