|
@@ 91-114 (lines=24) @@
|
| 88 |
|
|
| 89 |
|
return r.status_code, r |
| 90 |
|
|
| 91 |
|
def putCNBP(token, endpoint, data): |
| 92 |
|
""" |
| 93 |
|
Put some data to a LORIS end point. |
| 94 |
|
:param endpoint: |
| 95 |
|
:param data: |
| 96 |
|
:return: bool on if request is successful, r for the request (CAN BE NULL for 201 based requests) |
| 97 |
|
""" |
| 98 |
|
logger = logging.getLogger('LORIS_put') |
| 99 |
|
logger.info("Putting data to: "+endpoint) |
| 100 |
|
logger.info("Data: "+data) |
| 101 |
|
logger.info("!!!!!!!!!!BEWARE THAT SOME ENDPOINTS HAVE TRAILING SLASH, OTHERS DON'T.!!!!!!!!!!!!!!") |
| 102 |
|
|
| 103 |
|
load_dotenv() |
| 104 |
|
url = os.getenv("LORISurl") |
| 105 |
|
updatedurl = url + endpoint |
| 106 |
|
|
| 107 |
|
HEADERS = {'Authorization': 'token {}'.format(token)} |
| 108 |
|
|
| 109 |
|
with requests.Session() as s: |
| 110 |
|
s.headers.update(HEADERS) |
| 111 |
|
r = s.put(updatedurl, data=data) |
| 112 |
|
logger.info("Put Result:" + str(r.status_code) + r.reason) |
| 113 |
|
|
| 114 |
|
return r.status_code, r |
| 115 |
|
|
| 116 |
|
|
| 117 |
|
|
|
@@ 67-89 (lines=23) @@
|
| 64 |
|
return r.status_code, r.json() |
| 65 |
|
|
| 66 |
|
|
| 67 |
|
def postCNBP(token, endpoint, data): |
| 68 |
|
""" |
| 69 |
|
post some data to a LORIS end point. |
| 70 |
|
:param endpoint: |
| 71 |
|
:param data: |
| 72 |
|
:return: bool on if request is successful, r for the request (CAN BE NULL for 201 based requests) |
| 73 |
|
""" |
| 74 |
|
logger = logging.getLogger('LORIS_post') |
| 75 |
|
logger.info("Posting data to: "+endpoint) |
| 76 |
|
logger.info("Data: "+data) |
| 77 |
|
logger.info("!!!!!!!!!!BEWARE THAT SOME ENDPOINTS HAVE TRAILING SLASH, OTHERS DON'T.!!!!!!!!!!!!!!") |
| 78 |
|
load_dotenv() |
| 79 |
|
url = os.getenv("LORISurl") |
| 80 |
|
updatedurl = url + endpoint |
| 81 |
|
|
| 82 |
|
HEADERS = {'Authorization': 'token {}'.format(token)} |
| 83 |
|
|
| 84 |
|
with requests.Session() as s: |
| 85 |
|
s.headers.update(HEADERS) |
| 86 |
|
r = s.post(updatedurl, data=data) |
| 87 |
|
logger.info("Post Result:" + str(r.status_code) + r.reason) |
| 88 |
|
|
| 89 |
|
return r.status_code, r |
| 90 |
|
|
| 91 |
|
def putCNBP(token, endpoint, data): |
| 92 |
|
""" |
|
@@ 45-64 (lines=20) @@
|
| 42 |
|
return is_response_success(r.status_code, 200), response_json.get('token') |
| 43 |
|
|
| 44 |
|
|
| 45 |
|
def getCNBP(token, endpoint): |
| 46 |
|
""" |
| 47 |
|
Get from a CNBP LORIS database endpoint |
| 48 |
|
:param endpoint: |
| 49 |
|
:return: bool on if such PSCID (INSTITUTIONID + PROJECTID + SUBJECTID) exist already. |
| 50 |
|
""" |
| 51 |
|
logger = logging.getLogger('LORIS_get') |
| 52 |
|
logger.info("Getting LORIS endpoing: "+ endpoint + "at") |
| 53 |
|
load_dotenv() |
| 54 |
|
url = os.getenv("LORISurl") |
| 55 |
|
updatedurl = url + endpoint |
| 56 |
|
logger.info(updatedurl) |
| 57 |
|
HEADERS = {'Authorization': 'token {}'.format(token)} |
| 58 |
|
|
| 59 |
|
with requests.Session() as s: |
| 60 |
|
s.headers.update(HEADERS) |
| 61 |
|
r = s.get(updatedurl) |
| 62 |
|
logger.info("Get Result:" + str(r.status_code) + r.reason) |
| 63 |
|
|
| 64 |
|
return r.status_code, r.json() |
| 65 |
|
|
| 66 |
|
|
| 67 |
|
def postCNBP(token, endpoint, data): |