Implement getting account balance and heartbeat

This commit is contained in:
Les De Ridder 2017-02-14 21:43:55 +01:00
parent 200f737083
commit be847602da
No known key found for this signature in database
GPG Key ID: 5EC132DFA85DB372
1 changed files with 105 additions and 53 deletions

View File

@ -1,6 +1,7 @@
import std.stdio;
import std.conv;
import std.algorithm;
import core.time : msecs;
import core.sys.linux.unistd;
import vibe.d;
@ -66,25 +67,34 @@ class StartFlow : ApiRequest
class WidgetEvents : ApiRequest
{
string applicationId;
Json[string][] widgetEventInformations;
Json[] widgetEventInformations;
this(string applicationId, string[string] widgetEventInformations, string[string] attributes)
this(string applicationId, WidgetEventInformation[] events)
{
this.applicationId = applicationId;
Json[string] eventInformations;
foreach(key, value; widgetEventInformations)
foreach(event; events)
{
eventInformations[key] = value.serializeToJson;
widgetEventInformations ~= event.serializeToJson;
}
this.widgetEventInformations = [eventInformations];
}
}
Json[string] jsonAttributes;
foreach(key, value; attributes)
{
jsonAttributes[key] = value.serializeToJson;
}
this.widgetEventInformations[0]["attributes"] = jsonAttributes;
struct WidgetEventInformation
{
string widgetId;
string eventType;
string widgetType;
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)
{
auto widgetEventsRequest = createClickImageEvent("Container@reuse_Screen@img_Operations");
sendRequest("sequential", widgetEventsRequest);
auto widgetEvent = createClickImageEvent("Container@reuse_Screen@img_Operations");
sendRequest("sequential", new WidgetEvents("Container", [widgetEvent]));
widgetEventsRequest = createChangeValueEvent("Container@reuse_flowAuthentication@inp_PanNumbersimple", cardNumber[0 .. 4]);
sendRequest("sequential", widgetEventsRequest);
widgetEvent = createChangeInputValueEvent("Container@reuse_flowAuthentication@inp_PanNumbersimple", cardNumber[0 .. 4]);
sendRequest("sequential", new WidgetEvents("Container", [widgetEvent]));
widgetEventsRequest = createChangeValueEvent("Container@reuse_flowAuthentication@inp_PanNumbersimple", cardNumber);
sendRequest("sequential", widgetEventsRequest);
widgetEvent = createChangeInputValueEvent("Container@reuse_flowAuthentication@inp_PanNumbersimple", cardNumber);
sendRequest("sequential", new WidgetEvents("Container", [widgetEvent]));
widgetEventsRequest = createChangeValueEvent("Container@reuse_flowAuthentication@inp_PhoneZone", phoneZone);
sendRequest("sequential", widgetEventsRequest);
widgetEvent = createChangeInputValueEvent("Container@reuse_flowAuthentication@inp_PhoneZone", phoneZone);
sendRequest("sequential", new WidgetEvents("Container", [widgetEvent]));
widgetEventsRequest = createChangeValueEvent("Container@reuse_flowAuthentication@inp_PhoneSubscriber", phoneSubscriber);
sendRequest("sequential", widgetEventsRequest);
widgetEvent = createChangeInputValueEvent("Container@reuse_flowAuthentication@inp_PhoneSubscriber", phoneSubscriber);
sendRequest("sequential", new WidgetEvents("Container", [widgetEvent]));
widgetEventsRequest = createClickButtonEvent("Container@reuse_flowAuthentication@btn_Identification");
sendRequest("sequential", widgetEventsRequest);
widgetEvent = createClickButtonEvent("Container@reuse_flowAuthentication@btn_Identification");
sendRequest("sequential", new WidgetEvents("Container", [widgetEvent]));
}
void login2(string otp, string password)
{
auto widgetEventsRequest = createClickImageEvent("Container@reuse_Screen@img_Operations");
sendRequest("sequential", widgetEventsRequest);
auto widgetEvent = createClickImageEvent("Container@reuse_Screen@img_Operations");
sendRequest("sequential", new WidgetEvents("Container", [widgetEvent]));
widgetEventsRequest = createChangeValueEvent("Container@reuse_flowAuthentication@inp_otp", otp);
sendRequest("sequential", widgetEventsRequest);
widgetEvent = createChangeInputValueEvent("Container@reuse_flowAuthentication@inp_otp", otp);
sendRequest("sequential", new WidgetEvents("Container", [widgetEvent]));
widgetEventsRequest = createChangeValueEvent("Container@reuse_flowAuthentication@inp_pw", password);
sendRequest("sequential", widgetEventsRequest);
widgetEvent = createChangeInputValueEvent("Container@reuse_flowAuthentication@inp_pw", password);
sendRequest("sequential", new WidgetEvents("Container", [widgetEvent]));
widgetEventsRequest = createClickButtonEvent("Container@reuse_flowAuthentication@btn_Identification");
sendRequest("sequential", widgetEventsRequest);
widgetEvent = createClickButtonEvent("Container@reuse_flowAuthentication@btn_Identification");
sendRequest("sequential", new WidgetEvents("Container", [widgetEvent]));
runTask(&heartbeatLoop);
}
WidgetEvents createClickImageEvent(string widgetId)
string getAccountAvailable()
{
return new WidgetEvents("Container", [
"widgetId": widgetId,
"eventType": "clicked",
"widgetType": "Image",
], null);
auto clickImageEvent = createClickImageEvent("Container@reuse_Screen@img_Account");
auto widgetEventsRequest = new WidgetEvents("Container", [clickImageEvent]);
sendRequest("sequential", widgetEventsRequest);
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", [
"widgetId": widgetId,
"eventType": "clicked",
"widgetType": "ActionButton",
], null);
return WidgetEventInformation(widgetId, "clicked", "Image", null);
}
WidgetEvents createChangeValueEvent(string widgetId, string value)
WidgetEventInformation createClickButtonEvent(string widgetId)
{
return new WidgetEvents("Container", [
"widgetId": widgetId,
"eventType": "valueChanged",
"widgetType": "Input",
], [
"text": value
]);
return WidgetEventInformation(widgetId, "clicked", "ActionButton", null);
}
WidgetEventInformation createClickLabelEvent(string widgetId)
{
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)
@ -270,4 +320,6 @@ shared static this()
auto otp = readln()[0 .. $-1];
auto password = fromStringz(getpass("Password: ")).idup;
apiClient.login2(otp, password);
writeln("Funds available: " ~ apiClient.getAccountAvailable());
}