Skip to content
Snippets Groups Projects
Commit 5e175009 authored by GATEAU Thibault's avatar GATEAU Thibault
Browse files

[api] typos correction

parent 4f2fc9eb
Branches
No related tags found
No related merge requests found
import requests as rq
class Nanospace:
def login(self):
"""
......@@ -51,7 +52,7 @@ class Nanospace:
else:
raise ValueError(r_data)
def update__string_value(self, id, name, value):
def update_string_value(self, id, name, value):
"""
Update the value passed as id.
Raise ValueError if errors occures
......@@ -83,7 +84,7 @@ class Nanospace:
else:
raise ValueError(r_data)
def update__formula_value(self, id, name, value):
def update_formula_value(self, id, name, value):
"""
Update the formula passed as id.
Raise ValueError if errors occures
......@@ -96,7 +97,115 @@ class Nanospace:
if r.status_code < 200 or r.status_code >= 300:
raise ValueError(r_data)
else:
return r_data['formula']
#return r_data['formula']
return r_data
def _create_component(self, idParent, componentName):
"""
Create a component children of the parent passed as id
Return a JSON component
:Exemple:
nanospace._create_component(89, 'mySuperComponent')
"""
r = rq.post(self.ApiBaseAddress + 'component?parentId=' + str(idParent), json={'name': componentName}, headers=self.headers)
r_data = r.json()
if r.status_code < 200 or r.status_code >= 300:
raise ValueError(r_data)
else:
return r_data
def _create_mode(self, idParent, modeName):
"""
Create a mode of a component parent passed as id
Return the a JSON component
:Exemple:
nanospace._create_mode(28, 'test-mode')
"""
r = rq.post(self.ApiBaseAddress + 'mode?parentId=' + str(idParent), json={'name': modeName}, headers=self.headers)
r_data = r.json()
if r.status_code < 200 or r.status_code >= 300:
raise ValueError(r_data)
else:
return r_data
def _create_string_value(self, idParent, valueName, value):
"""
Create a string of a mode parent passed as id
Return the a JSON component
:Exemple:
nanospace._create_string_value(28, 'string_value', 'Hello-World')
"""
r = rq.post(self.ApiBaseAddress + 'string?parentId=' + str(idParent), json={'name': valueName, 'value': value, 'type': 'string_value'}, headers=self.headers)
r_data = r.json()
if r.status_code < 200 or r.status_code >= 300:
raise ValueError(r_data)
else:
return r_data
def _create_formula_value(self, idParent, valueName, value):
"""
Create a formula of a mode parent passed as id
Return the a JSON component
:Exemple:
nanospace._create_formula_value(28, 'value', '5*8')
"""
r = rq.post(self.ApiBaseAddress + 'formula?parentId=' + str(idParent), json={'name': valueName, 'formula': value, 'type': 'string_value'}, headers=self.headers)
r_data = r.json()
if r.status_code < 200 or r.status_code >= 300:
raise ValueError(r_data)
else:
return r_data
def _delete_value(self, idValue):
"""
Delete a value which the id has been passed as parameter
Return the a JSON component
:Exemple:
nanospace._delete_value(28)
"""
r = rq.delete(self.ApiBaseAddress + 'value/' + str(idValue), headers=self.headers)
# r_data = r.json()
# if r.status_code < 200 or r.status_code >= 300:
# raise ValueError(r_data)
# else:
# return r_data
def _delete_mode(self, idMode):
"""
Delete a mode which the id has been passed as parameter
Return the a JSON component
:Exemple:
nanospace._delete_mode(28)
"""
r = rq.delete(self.ApiBaseAddress + 'mode/' + str(idMode), headers=self.headers)
# r_data = r.json()
# if r.status_code < 200 or r.status_code >= 300:
# raise ValueError(r_data)
# else:
# return r_data
def _delete_component(self, idComponent):
"""
Delete a component which the id has been passed as parameter
Return the a JSON component
:Exemple:
nanospace._delete_component(28)
"""
r = rq.delete(self.ApiBaseAddress + 'component/' + str(idComponent), headers=self.headers)
# r_data = r.json()
# if r.status_code < 200 or r.status_code >= 300:
# raise ValueError(r_data)
# else:
# return r_data
def setApiBaseAddress(self, url):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment