21
21
"""
22
22
23
23
###################################
24
- logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s")
24
+ logging.basicConfig(level=logging.INFO,
25
+ format="%(asctime)s - %(name)s - %(levelname)s - %(message)s")
25
26
logging.getLogger("pylnbits").setLevel(level=logging.WARNING)
26
27
logger = logging.getLogger(__name__)
27
28
###################################
30
31
class UserManager:
31
32
def __init__(self, config, session: ClientSession = None):
32
33
"""__init__
33
-
34
+
34
35
Initializes a UserManager extension via API
35
36
36
37
"""
@@ -50,7 +51,8 @@ async def get_users(self):
50
51
try:
51
52
upath = "/usermanager/api/v1/users"
52
53
path = self._lnbits_url + upath
53
- res = await get_url(session=self._session, path=path, headers=self._invoice_headers)
54
+ res = await get_url(session=self._session, path=path,
55
+ headers=self._invoice_headers)
54
56
return res
55
57
except Exception as e:
56
58
logger.info(e)
@@ -66,7 +68,8 @@ async def get_user(self, user_id):
66
68
try:
67
69
upath = "/usermanager/api/v1/users/" + user_id
68
70
path = self._lnbits_url + upath
69
- res = await get_url(session=self._session, path=path, headers=self._invoice_headers)
71
+ res = await get_url(session=self._session,
72
+ path=path, headers=self._invoice_headers)
70
73
return res
71
74
except Exception as e:
72
75
logger.info(e)
@@ -82,7 +85,8 @@ async def get_wallets(self, user_id):
82
85
try:
83
86
wpath = "/usermanager/api/v1/wallets/" + user_id
84
87
path = self._lnbits_url + wpath
85
- res = await get_url(session=self._session, path=path, headers=self._invoice_headers)
88
+ res = await get_url(session=self._session, path=path,
89
+ headers=self._invoice_headers)
86
90
return res
87
91
except Exception as e:
88
92
logger.info(e)
@@ -98,7 +102,8 @@ async def get_tx(self, wallet_id):
98
102
try:
99
103
tpath = "/usermanager/api/v1/wallets" + wallet_id
100
104
path = self._lnbits_url + tpath
101
- res = await get_url(session=self._session, path=path, headers=self._invoice_headers)
105
+ res = await get_url(session=self._session, path=path,
106
+ headers=self._invoice_headers)
102
107
return res
103
108
except Exception as e:
104
109
logger.info(e)
@@ -111,9 +116,11 @@ async def post_user_initial(self, admin_id, user_name, wallet_name):
111
116
try:
112
117
tpath = "/usermanager/api/v1/users"
113
118
path = self._lnbits_url + tpath
114
- body = {"admin_id": admin_id, "user_name": user_name, "wallet_name": wallet_name}
119
+ body = {"admin_id": admin_id, "user_name": user_name,
120
+ "wallet_name": wallet_name}
115
121
jbody = json.dumps(body)
116
- res = await post_url(session=self._session, path=path, headers=self._invoice_headers, body=jbody)
122
+ res = await post_url(session=self._session, path=path,
123
+ headers=self._invoice_headers, body=jbody)
117
124
return res
118
125
except Exception as e:
119
126
logger.info(e)
@@ -127,14 +134,17 @@ async def post_wallet(self, user_id, wallet_name, admin_id):
127
134
"""
128
135
Post_wallet returns api keys related to wallet
129
136
130
- Returns {"id": <string>, "admin": <string>, "name": <string>, "user": <string>, "adminkey": <string>, "inkey": <string>}
137
+ Returns {"id": <string>, "admin": <string>, "name": <string>,
138
+ "user": <string>, "adminkey": <string>, "inkey": <string>}
131
139
"""
132
140
try:
133
141
tpath = "/usermanager/api/v1/wallets"
134
142
path = self._lnbits_url + tpath
135
- body = {"user_id": user_id, "wallet_name": wallet_name, "admin_id": admin_id}
143
+ body = {"user_id": user_id, "wallet_name": wallet_name,
144
+ "admin_id": admin_id}
136
145
jbody = json.dumps(body)
137
- res = await post_url(session=self._session, path=path, headers=self._invoice_headers, body=jbody)
146
+ res = await post_url(session=self._session,
147
+ path=path, headers=self._invoice_headers, body=jbody)
138
148
return res
139
149
except Exception as e:
140
150
logger.info(e)
@@ -147,7 +157,8 @@ async def delete_user(self, user_id):
147
157
try:
148
158
tpath = "/usermanager/api/v1/users/" + user_id
149
159
path = self._lnbits_url + tpath
150
- res = await delete_url(session=self._session, path=path, headers=self._invoice_headers)
160
+ res = await delete_url(session=self._session,
161
+ path=path, headers=self._invoice_headers)
151
162
return res
152
163
except Exception as e:
153
164
logger.info(e)
@@ -160,7 +171,8 @@ async def delete_wallet(self, wallet_id):
160
171
try:
161
172
tpath = "/usermanager/api/v1/wallets/" + wallet_id
162
173
path = self._lnbits_url + tpath
163
- res = await delete_url(session=self._session, path=path, headers=self._invoice_headers)
174
+ res = await delete_url(session=self._session,
175
+ path=path, headers=self._invoice_headers)
164
176
return res
165
177
except Exception as e:
166
178
logger.info(e)
@@ -178,7 +190,8 @@ async def post_activate_ext(self, user_id: str, extension: str, active: int):
178
190
path = self._lnbits_url + tpath
179
191
body = {"userid": user_id, "extension": extension, "active": active}
180
192
jbody = json.dumps(body)
181
- res = await post_url(session=self._session, path=path, headers=self._invoice_headers, body=jbody)
193
+ res = await post_url(session=self._session, path=path,
194
+ headers=self._invoice_headers, body=jbody)
182
195
return res
183
196
except Exception as e:
184
197
logger.info(e)
0 commit comments