Skip to content
This repository was archived by the owner on Jan 5, 2021. It is now read-only.

Commit aff34d5

Browse files
author
Luis Correa
committed
getUserTime
1 parent e78f3b5 commit aff34d5

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

nauta_api/lib/src/nauta_api.dart

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,24 @@ class NautaProtocol {
194194
} catch (e) {
195195
throw NautaException('Fallo al obtener la informacion del usuario');
196196
}
197+
} // end getUserCredit
198+
199+
static Future<String> getUserTime(SessionObject session, String username) async {
200+
final r = await Requests.post(
201+
"https://secure.etecsa.net:8443/EtecsaQueryServlet",
202+
body: {
203+
"op": "getLeftTime",
204+
"ATTRIBUTE_UUID": session.attributeUuid,
205+
"CSRFHW": session.csrfhw,
206+
"wlanuserip": session.wlanuserip,
207+
"username": username
208+
},
209+
bodyEncoding: RequestBodyEncoding.FormURLEncoded,
210+
);
211+
212+
r.raiseForStatus();
213+
214+
return r.content();
197215
}
198216
}
199217

@@ -241,6 +259,14 @@ class NautaClient {
241259
}
242260
}
243261

262+
Future<String> remainingTime() async {
263+
if (session == null) {
264+
throw NautaTimeException('Debe iniciar sesión para conocer el tiempo restante');
265+
}
266+
267+
return await NautaProtocol.getUserTime(session, user);
268+
}
269+
244270
Future<void> logout() async {
245271
try {
246272
await NautaProtocol.logout(session, user);
@@ -251,7 +277,7 @@ class NautaClient {
251277
}
252278
}
253279

254-
void loadLastSession() async {
280+
Future<void> loadLastSession() async {
255281
session = await SessionObject.load();
256282
}
257283
}

nauta_api/lib/src/utils/exceptions.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,7 @@ class NautaLoginException extends NautaException {
1515
class NautaLogoutException extends NautaException {
1616
NautaLogoutException(message) : super(message);
1717
}
18+
19+
class NautaTimeException extends NautaException {
20+
NautaTimeException(message) : super(message);
21+
}

0 commit comments

Comments
 (0)