forked from CenterForOpenScience/osf.io
-
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.
- Loading branch information
Showing
1 changed file
with
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,28 @@ | ||
import requests | ||
|
||
from urllib.parse import quote_plus | ||
|
||
from website import settings | ||
|
||
|
||
class CedarClient(object): | ||
|
||
host = settings.CEDAR_API_HOST | ||
api_key = settings.CEDAR_API_KEY | ||
home_folder_id = quote_plus(settings.CEDAR_HOME_FOLDER_ID) | ||
headers = { | ||
'Authorization': f'apikey {api_key}' | ||
'Authorization': f'apiKey {api_key}', | ||
} | ||
|
||
def retrieve_all_template_ids(self): | ||
url = f'{self.host}folders/{self.home_folder_id}/contents/?resource_types=template' | ||
# TODO: add error handling | ||
r = requests.get(url, headers=self.headers) | ||
resources = r.json()['resources'] | ||
return [item['@id'] for item in resources] | ||
|
||
def retrieve_template_by_id(self, id): | ||
url = f'{self.host}templates/{quote_plus(id)}' | ||
# TODO: add error handling | ||
r = requests.get(url, headers=self.headers) | ||
return r.json() |