1
1
import json
2
2
import logging
3
3
4
+ import urllib .parse
5
+
4
6
from aiohttp .client import ClientSession
5
7
6
8
from pylnbits .utils import delete_url , get_url , post_url
@@ -52,7 +54,7 @@ async def get_users(self):
52
54
upath = "/usermanager/api/v1/users"
53
55
path = self ._lnbits_url + upath
54
56
res = await get_url (session = self ._session , path = path ,
55
- headers = self ._invoice_headers )
57
+ headers = self ._admin_headers )
56
58
return res
57
59
except Exception as e :
58
60
logger .info (e )
@@ -86,7 +88,7 @@ async def get_wallets(self, user_id):
86
88
wpath = "/usermanager/api/v1/wallets/" + user_id
87
89
path = self ._lnbits_url + wpath
88
90
res = await get_url (session = self ._session , path = path ,
89
- headers = self ._invoice_headers )
91
+ headers = self ._admin_headers )
90
92
return res
91
93
except Exception as e :
92
94
logger .info (e )
@@ -120,7 +122,7 @@ async def post_user_initial(self, admin_id, user_name, wallet_name):
120
122
"wallet_name" : wallet_name }
121
123
jbody = json .dumps (body )
122
124
res = await post_url (session = self ._session , path = path ,
123
- headers = self ._invoice_headers , body = jbody )
125
+ headers = self ._admin_headers , body = jbody )
124
126
return res
125
127
except Exception as e :
126
128
logger .info (e )
@@ -144,7 +146,7 @@ async def post_wallet(self, user_id, wallet_name, admin_id):
144
146
"admin_id" : admin_id }
145
147
jbody = json .dumps (body )
146
148
res = await post_url (session = self ._session ,
147
- path = path , headers = self ._invoice_headers , body = jbody )
149
+ path = path , headers = self ._admin_headers , body = jbody )
148
150
return res
149
151
except Exception as e :
150
152
logger .info (e )
@@ -158,7 +160,7 @@ async def delete_user(self, user_id):
158
160
tpath = "/usermanager/api/v1/users/" + user_id
159
161
path = self ._lnbits_url + tpath
160
162
res = await delete_url (session = self ._session ,
161
- path = path , headers = self ._invoice_headers )
163
+ path = path , headers = self ._admin_headers )
162
164
return res
163
165
except Exception as e :
164
166
logger .info (e )
@@ -172,26 +174,23 @@ async def delete_wallet(self, wallet_id):
172
174
tpath = "/usermanager/api/v1/wallets/" + wallet_id
173
175
path = self ._lnbits_url + tpath
174
176
res = await delete_url (session = self ._session ,
175
- path = path , headers = self ._invoice_headers )
177
+ path = path , headers = self ._admin_headers )
176
178
return res
177
179
except Exception as e :
178
180
logger .info (e )
179
181
return e
180
182
181
- # temporarily use this to activate extensions:
182
- # https://yourdomain.com/extensions?usr=89.....&enable=lnurlp
183
- # unclear why curl doesn't work ?
184
- async def post_activate_ext (self , user_id : str , extension : str , active : int ):
183
+ async def post_activate_ext (self , user_id : str , extension : str , active : bool ):
185
184
"""
186
185
activates an extension for a user created by User Manager Extension
187
186
"""
188
187
try :
189
188
tpath = "/usermanager/api/v1/extensions"
190
- path = self . _lnbits_url + tpath
191
- body = { "userid" : user_id , "extension" : extension , "active" : active }
192
- jbody = json . dumps ( body )
189
+ params = { "extension" : extension , "userid" : user_id , "active" : active }
190
+ query_params = urllib . parse . urlencode ( params )
191
+ path = self . _lnbits_url + tpath + "?" + query_params
193
192
res = await post_url (session = self ._session , path = path ,
194
- headers = self ._invoice_headers , body = jbody )
193
+ headers = self ._invoice_headers , body = "" )
195
194
return res
196
195
except Exception as e :
197
196
logger .info (e )
0 commit comments