This repository was archived by the owner on Oct 29, 2022. It is now read-only.
forked from SynapseFI/SynapseFI-Python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNodes.py
More file actions
55 lines (47 loc) · 1.97 KB
/
Nodes.py
File metadata and controls
55 lines (47 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from .HelperFunctions import *
NODES_PATH = '/users/{0}/nodes/{1}'
class Nodes():
def __init__(self, client):
self.client = client
def create_node_path(self, node_id=None):
if node_id:
return NODES_PATH.format(self.client.user_id, node_id)
else:
return NODES_PATH.replace('/{1}', '').format(self.client.user_id)
def add(self, **kwargs):
if not 'payload' in kwargs:
return create_custom_error_message(error_message='Missing the "payload" parameter.')
path = self.create_node_path()
response = self.client.post(path, kwargs['payload'])
return analyze_response(response)
def verify(self, **kwargs):
micro_keys = ['payload', 'node_id']
ok_micro, error_micro = checkKwargs(micro_keys, kwargs)
mfa_keys = ['payload']
ok_mfa, error_mfa = checkKwargs(mfa_keys, kwargs)
response = None
if ok_micro:
path = self.create_node_path(kwargs['node_id'])
response = self.client.patch(path, kwargs['payload'])
elif ok_mfa:
path = self.create_node_path()
response = self.client.post(path, kwargs['payload'])
else:
return error_micro
return analyze_response(response)
def delete(self, **kwargs):
if not 'node_id' in kwargs:
return create_custom_error_message(error_message='Missing "node_id" argument')
path = self.create_node_path(kwargs['node_id'])
response = self.client.delete(path)
return analyze_response(response)
def get(self, **kwargs):
path = None
if 'node_id' in kwargs:
path = self.create_node_path(kwargs['node_id'])
elif self.client.user_id:
path = self.create_node_path()
else:
return create_custom_error_message(error_message='Set the user id before making this API call.')
response = self.client.get(path)
return analyze_response(response)