Implement getting account balance and heartbeat
This commit is contained in:
parent
200f737083
commit
be847602da
158
source/app.d
158
source/app.d
|
@ -1,6 +1,7 @@
|
||||||
import std.stdio;
|
import std.stdio;
|
||||||
import std.conv;
|
import std.conv;
|
||||||
|
import std.algorithm;
|
||||||
|
import core.time : msecs;
|
||||||
import core.sys.linux.unistd;
|
import core.sys.linux.unistd;
|
||||||
|
|
||||||
import vibe.d;
|
import vibe.d;
|
||||||
|
@ -66,25 +67,34 @@ class StartFlow : ApiRequest
|
||||||
class WidgetEvents : ApiRequest
|
class WidgetEvents : ApiRequest
|
||||||
{
|
{
|
||||||
string applicationId;
|
string applicationId;
|
||||||
Json[string][] widgetEventInformations;
|
Json[] widgetEventInformations;
|
||||||
|
|
||||||
this(string applicationId, string[string] widgetEventInformations, string[string] attributes)
|
this(string applicationId, WidgetEventInformation[] events)
|
||||||
{
|
{
|
||||||
this.applicationId = applicationId;
|
this.applicationId = applicationId;
|
||||||
|
|
||||||
Json[string] eventInformations;
|
foreach(event; events)
|
||||||
foreach(key, value; widgetEventInformations)
|
|
||||||
{
|
{
|
||||||
eventInformations[key] = value.serializeToJson;
|
widgetEventInformations ~= event.serializeToJson;
|
||||||
}
|
}
|
||||||
this.widgetEventInformations = [eventInformations];
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Json[string] jsonAttributes;
|
struct WidgetEventInformation
|
||||||
foreach(key, value; attributes)
|
{
|
||||||
{
|
string widgetId;
|
||||||
jsonAttributes[key] = value.serializeToJson;
|
string eventType;
|
||||||
}
|
string widgetType;
|
||||||
this.widgetEventInformations[0]["attributes"] = jsonAttributes;
|
string[string] attributes;
|
||||||
|
}
|
||||||
|
|
||||||
|
class TechnicalRequest : ApiRequest
|
||||||
|
{
|
||||||
|
string requestType;
|
||||||
|
|
||||||
|
this(string requestType)
|
||||||
|
{
|
||||||
|
this.requestType = requestType;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,67 +164,107 @@ class ApiClient
|
||||||
|
|
||||||
void login1(string cardNumber, string phoneZone, string phoneSubscriber)
|
void login1(string cardNumber, string phoneZone, string phoneSubscriber)
|
||||||
{
|
{
|
||||||
auto widgetEventsRequest = createClickImageEvent("Container@reuse_Screen@img_Operations");
|
auto widgetEvent = createClickImageEvent("Container@reuse_Screen@img_Operations");
|
||||||
sendRequest("sequential", widgetEventsRequest);
|
sendRequest("sequential", new WidgetEvents("Container", [widgetEvent]));
|
||||||
|
|
||||||
widgetEventsRequest = createChangeValueEvent("Container@reuse_flowAuthentication@inp_PanNumbersimple", cardNumber[0 .. 4]);
|
widgetEvent = createChangeInputValueEvent("Container@reuse_flowAuthentication@inp_PanNumbersimple", cardNumber[0 .. 4]);
|
||||||
sendRequest("sequential", widgetEventsRequest);
|
sendRequest("sequential", new WidgetEvents("Container", [widgetEvent]));
|
||||||
|
|
||||||
widgetEventsRequest = createChangeValueEvent("Container@reuse_flowAuthentication@inp_PanNumbersimple", cardNumber);
|
widgetEvent = createChangeInputValueEvent("Container@reuse_flowAuthentication@inp_PanNumbersimple", cardNumber);
|
||||||
sendRequest("sequential", widgetEventsRequest);
|
sendRequest("sequential", new WidgetEvents("Container", [widgetEvent]));
|
||||||
|
|
||||||
widgetEventsRequest = createChangeValueEvent("Container@reuse_flowAuthentication@inp_PhoneZone", phoneZone);
|
widgetEvent = createChangeInputValueEvent("Container@reuse_flowAuthentication@inp_PhoneZone", phoneZone);
|
||||||
sendRequest("sequential", widgetEventsRequest);
|
sendRequest("sequential", new WidgetEvents("Container", [widgetEvent]));
|
||||||
|
|
||||||
widgetEventsRequest = createChangeValueEvent("Container@reuse_flowAuthentication@inp_PhoneSubscriber", phoneSubscriber);
|
widgetEvent = createChangeInputValueEvent("Container@reuse_flowAuthentication@inp_PhoneSubscriber", phoneSubscriber);
|
||||||
sendRequest("sequential", widgetEventsRequest);
|
sendRequest("sequential", new WidgetEvents("Container", [widgetEvent]));
|
||||||
|
|
||||||
widgetEventsRequest = createClickButtonEvent("Container@reuse_flowAuthentication@btn_Identification");
|
widgetEvent = createClickButtonEvent("Container@reuse_flowAuthentication@btn_Identification");
|
||||||
sendRequest("sequential", widgetEventsRequest);
|
sendRequest("sequential", new WidgetEvents("Container", [widgetEvent]));
|
||||||
}
|
}
|
||||||
|
|
||||||
void login2(string otp, string password)
|
void login2(string otp, string password)
|
||||||
{
|
{
|
||||||
auto widgetEventsRequest = createClickImageEvent("Container@reuse_Screen@img_Operations");
|
auto widgetEvent = createClickImageEvent("Container@reuse_Screen@img_Operations");
|
||||||
sendRequest("sequential", widgetEventsRequest);
|
sendRequest("sequential", new WidgetEvents("Container", [widgetEvent]));
|
||||||
|
|
||||||
widgetEventsRequest = createChangeValueEvent("Container@reuse_flowAuthentication@inp_otp", otp);
|
widgetEvent = createChangeInputValueEvent("Container@reuse_flowAuthentication@inp_otp", otp);
|
||||||
sendRequest("sequential", widgetEventsRequest);
|
sendRequest("sequential", new WidgetEvents("Container", [widgetEvent]));
|
||||||
|
|
||||||
widgetEventsRequest = createChangeValueEvent("Container@reuse_flowAuthentication@inp_pw", password);
|
widgetEvent = createChangeInputValueEvent("Container@reuse_flowAuthentication@inp_pw", password);
|
||||||
sendRequest("sequential", widgetEventsRequest);
|
sendRequest("sequential", new WidgetEvents("Container", [widgetEvent]));
|
||||||
|
|
||||||
widgetEventsRequest = createClickButtonEvent("Container@reuse_flowAuthentication@btn_Identification");
|
widgetEvent = createClickButtonEvent("Container@reuse_flowAuthentication@btn_Identification");
|
||||||
sendRequest("sequential", widgetEventsRequest);
|
sendRequest("sequential", new WidgetEvents("Container", [widgetEvent]));
|
||||||
|
|
||||||
|
runTask(&heartbeatLoop);
|
||||||
}
|
}
|
||||||
|
|
||||||
WidgetEvents createClickImageEvent(string widgetId)
|
string getAccountAvailable()
|
||||||
{
|
{
|
||||||
return new WidgetEvents("Container", [
|
auto clickImageEvent = createClickImageEvent("Container@reuse_Screen@img_Account");
|
||||||
"widgetId": widgetId,
|
|
||||||
"eventType": "clicked",
|
auto widgetEventsRequest = new WidgetEvents("Container", [clickImageEvent]);
|
||||||
"widgetType": "Image",
|
sendRequest("sequential", widgetEventsRequest);
|
||||||
], null);
|
|
||||||
|
auto repeaterEvent = createChangeRepeaterValueEvent("Container@reuse_flowApplication@repeater_main", "1");
|
||||||
|
auto labelValueEvent = createChangeLabelValueEvent("Container@reuse_flowApplication@lbl_AccountLabel", "1", "INFO");
|
||||||
|
auto clickLabelEvent = createClickLabelEvent("Container@reuse_flowApplication@lbl_AccountLabel");
|
||||||
|
|
||||||
|
widgetEventsRequest = new WidgetEvents("Container", [repeaterEvent, labelValueEvent, repeaterEvent, clickLabelEvent]);
|
||||||
|
auto response = sendRequest("sequential", widgetEventsRequest);
|
||||||
|
|
||||||
|
foreach(widgetUpdate; response.responseSets[0].responses[0]["ScreenUpdate"])
|
||||||
|
{
|
||||||
|
if(widgetUpdate["widgetId"] == "Container@reuse_flowApplication@repeater_1292926459910")
|
||||||
|
{
|
||||||
|
return widgetUpdate["properties"][0]["contentList"]["dynamiccontent"][0]["repeatedPane_1292926472020"]["VerticalPane_1290438166429"]["gridPane_main"]["gridRow_available"]["gridItem_available_value"]["lbl_valueavailable"]["htmlText"].get!string;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
WidgetEvents createClickButtonEvent(string widgetId)
|
WidgetEventInformation createClickImageEvent(string widgetId)
|
||||||
{
|
{
|
||||||
return new WidgetEvents("Container", [
|
return WidgetEventInformation(widgetId, "clicked", "Image", null);
|
||||||
"widgetId": widgetId,
|
|
||||||
"eventType": "clicked",
|
|
||||||
"widgetType": "ActionButton",
|
|
||||||
], null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
WidgetEvents createChangeValueEvent(string widgetId, string value)
|
WidgetEventInformation createClickButtonEvent(string widgetId)
|
||||||
{
|
{
|
||||||
return new WidgetEvents("Container", [
|
return WidgetEventInformation(widgetId, "clicked", "ActionButton", null);
|
||||||
"widgetId": widgetId,
|
}
|
||||||
"eventType": "valueChanged",
|
|
||||||
"widgetType": "Input",
|
WidgetEventInformation createClickLabelEvent(string widgetId)
|
||||||
], [
|
{
|
||||||
"text": value
|
return WidgetEventInformation(widgetId, "linkClicked", "Label", null);
|
||||||
]);
|
}
|
||||||
|
|
||||||
|
WidgetEventInformation createChangeInputValueEvent(string widgetId, string value)
|
||||||
|
{
|
||||||
|
return WidgetEventInformation(widgetId, "valueChanged", "Input", ["text": value]);
|
||||||
|
}
|
||||||
|
|
||||||
|
WidgetEventInformation createChangeRepeaterValueEvent(string widgetId, string activeElement)
|
||||||
|
{
|
||||||
|
return WidgetEventInformation(widgetId, "valueChanged", "Repeater", ["activeElement": activeElement]);
|
||||||
|
}
|
||||||
|
|
||||||
|
WidgetEventInformation createChangeLabelValueEvent(string widgetId, string currentLink, string currentTarget)
|
||||||
|
{
|
||||||
|
return WidgetEventInformation(widgetId, "valueChanged", "Label", ["currentLink": currentLink, "currentTarget": currentTarget]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void heartbeatLoop()
|
||||||
|
{
|
||||||
|
auto technicalRequest = new TechnicalRequest("heartbeat");
|
||||||
|
sendRequest("sequential", technicalRequest);
|
||||||
|
|
||||||
|
sleep(10000.msecs);
|
||||||
|
|
||||||
|
//TODO: Add a random action to prevent timeout
|
||||||
|
|
||||||
|
heartbeatLoop();
|
||||||
}
|
}
|
||||||
|
|
||||||
private ApiResponse sendRequest(T : ApiRequest)(string executionMode, T request)
|
private ApiResponse sendRequest(T : ApiRequest)(string executionMode, T request)
|
||||||
|
@ -270,4 +320,6 @@ shared static this()
|
||||||
auto otp = readln()[0 .. $-1];
|
auto otp = readln()[0 .. $-1];
|
||||||
auto password = fromStringz(getpass("Password: ")).idup;
|
auto password = fromStringz(getpass("Password: ")).idup;
|
||||||
apiClient.login2(otp, password);
|
apiClient.login2(otp, password);
|
||||||
|
|
||||||
|
writeln("Funds available: " ~ apiClient.getAccountAvailable());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue