changes APIHandler attribute "dump" to "header" for clarity
This commit is contained in:
@@ -9,7 +9,7 @@ class APIHandler:
|
|||||||
'''Init method, apikey suggested but not required (empty by default).'''
|
'''Init method, apikey suggested but not required (empty by default).'''
|
||||||
self.auth = {"Authorization" : apikey}
|
self.auth = {"Authorization" : apikey}
|
||||||
self.content = {"Content-Type" : "application/json"}
|
self.content = {"Content-Type" : "application/json"}
|
||||||
self.dump = {**self.auth, **self.content}
|
self.header = {**self.auth, **self.content}
|
||||||
self.elaburl = ELABFTW_API_URL
|
self.elaburl = ELABFTW_API_URL
|
||||||
def get_entry_from_elabid(self, elabid, entryType="items"):
|
def get_entry_from_elabid(self, elabid, entryType="items"):
|
||||||
'''
|
'''
|
||||||
@@ -18,7 +18,7 @@ class APIHandler:
|
|||||||
Entry type can be either "experiments" or "items".
|
Entry type can be either "experiments" or "items".
|
||||||
'''
|
'''
|
||||||
# TO-DO: validation and error handling on entryType value.
|
# TO-DO: validation and error handling on entryType value.
|
||||||
header = self.dump
|
header = self.header
|
||||||
response = requests.get(
|
response = requests.get(
|
||||||
headers = header,
|
headers = header,
|
||||||
url = f"{self.elaburl}/{entryType}/{elabid}",
|
url = f"{self.elaburl}/{entryType}/{elabid}",
|
||||||
|
|||||||
@@ -133,5 +133,5 @@ class Material:
|
|||||||
|
|
||||||
if __name__=="__main__":
|
if __name__=="__main__":
|
||||||
head = Header("MyApiKey-123456789abcdef")
|
head = Header("MyApiKey-123456789abcdef")
|
||||||
print(f"Example header:\n\t{head.dump}\n")
|
print(f"Example header:\n\t{head.header}\n")
|
||||||
print("Warning: you're not supposed to be running this as the main program.")
|
print("Warning: you're not supposed to be running this as the main program.")
|
||||||
@@ -9,13 +9,13 @@ class Header:
|
|||||||
'''Init method, apikey suggested but not required (empty by default).'''
|
'''Init method, apikey suggested but not required (empty by default).'''
|
||||||
self.auth = {"Authorization" : apikey}
|
self.auth = {"Authorization" : apikey}
|
||||||
self.content = {"Content-Type" : "application/json"}
|
self.content = {"Content-Type" : "application/json"}
|
||||||
self.dump = {**self.auth, **self.content}
|
self.header = {**self.auth, **self.content}
|
||||||
|
|
||||||
def get_entry_from_elabid(elabid, entryType="items"):
|
def get_entry_from_elabid(elabid, entryType="items"):
|
||||||
'''
|
'''
|
||||||
Function which returns entrypoint data (as dictionary) from its elabid.
|
Function which returns entrypoint data (as dictionary) from its elabid.
|
||||||
'''
|
'''
|
||||||
header = Header(apikey).dump
|
header = Header(apikey).header
|
||||||
response = requests.get(
|
response = requests.get(
|
||||||
headers = header,
|
headers = header,
|
||||||
url = f"{ELABFTW_API_URL}/{entryType}/{elabid}",
|
url = f"{ELABFTW_API_URL}/{entryType}/{elabid}",
|
||||||
|
|||||||
Reference in New Issue
Block a user