1
+ import json
2
+
1
3
from api_connect import ApiConnect
2
4
3
5
class ApiFunctions ():
@@ -7,50 +9,53 @@ def __init__(self):
7
9
self .echo = True
8
10
self .verbose = True
9
11
10
- def __return_config (self , return_value , json_val = False ): # TODO: which functions return json()
12
+ def __return_config (self , funct_name , return_value , is_json = False ):
11
13
"""Configure echo and verbosity of function returns."""
12
14
13
- if self .echo is True and self . verbose is True :
15
+ if self .echo is True :
14
16
print ('-' * 100 )
15
- if json_val is True :
16
- print (f'FUNCTION: { return_value } \n ' )
17
- return print (return_value )
17
+ print (f'FUNCTION: { funct_name } \n ' )
18
+ if is_json is True :
19
+ readable_json = json .dumps (return_value , indent = 4 )
20
+ print (readable_json )
18
21
else :
19
- print (f'FUNCTION: { return_value } \n ' )
20
- return print (return_value )
21
- elif self .echo is True and self .verbose is False :
22
- print ('-' * 100 )
23
- return print (return_value )
24
- elif self .echo is False and self .verbose is False :
25
- return return_value
22
+ print (return_value )
23
+ elif self .echo is False :
24
+ pass
26
25
else :
27
26
print ('-' * 100 )
28
27
return print ("ERROR: Incompatible return configuration." )
29
28
29
+ return return_value
30
+
30
31
def get_token (self , email , password , server = 'https://my.farm.bot' ):
31
32
token_str = self .api_connect .get_token (email , password , server )
32
- return token_str
33
+ return self . __return_config ( "get_token()" , token_str , is_json = True )
33
34
34
35
# data = get_info() and like functions will assign 'data' JSON object
35
36
# data["name"] will access the field "name" and return the field value
36
37
37
38
def get_info (self , endpoint , id = None ):
38
- return self .api_connect .get (endpoint , id )
39
+ endpoint_data = self .api_connect .get (endpoint , id )
40
+ return self .__return_config ("get_info()" , endpoint_data , is_json = True )
39
41
40
42
def set_info (self , endpoint , field , value , id = None ):
41
43
new_value = {
42
44
field : value
43
45
}
44
46
45
47
self .api_connect .patch (endpoint , id , new_value )
46
- return self .api_connect .get (endpoint , id )
48
+
49
+ endpoint_data = self .api_connect .get (endpoint , id )
50
+ return self .__return_config ("set_info()" , endpoint_data , is_json = True )
47
51
48
52
def env (self , id = None , field = None , new_val = None ): # TODO: Fix
49
53
if id is None :
50
- data = self .api_connect .get ('farmware_envs' , id = None )
54
+ env_data = self .api_connect .get ('farmware_envs' , id = None )
51
55
else :
52
- data = self .api_connect .get ('farmware_envs' , id )
53
- # return ...
56
+ env_data = self .api_connect .get ('farmware_envs' , id )
57
+
58
+ return self .__return_config ("env()" , env_data , is_json = True )
54
59
55
60
def log (self , message , type = None , channel = None ):
56
61
log_message = {
0 commit comments