Implement getting card balance

This commit is contained in:
Les De Ridder 2017-02-14 22:24:58 +01:00
parent be847602da
commit cd2356ae2a
No known key found for this signature in database
GPG Key ID: 5EC132DFA85DB372
1 changed files with 48 additions and 2 deletions

View File

@ -1,6 +1,7 @@
import std.stdio;
import std.conv;
import std.algorithm;
import std.range;
import core.time : msecs;
import core.sys.linux.unistd;
@ -214,17 +215,58 @@ class ApiClient
widgetEventsRequest = new WidgetEvents("Container", [repeaterEvent, labelValueEvent, repeaterEvent, clickLabelEvent]);
auto response = sendRequest("sequential", widgetEventsRequest);
goHome();
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;
string available = widgetUpdate["properties"][0]["contentList"]["dynamiccontent"][0]["repeatedPane_1292926472020"]["VerticalPane_1290438166429"]["gridPane_main"]["gridRow_available"]["gridItem_available_value"]["lbl_valueavailable"]["htmlText"].get!string;
return available.map!(c => c == '.' ? ',' : (c == ',' ? '.' : c)).map!(to!char).array;
}
}
return null;
}
string getCardAvailable()
{
auto clickImageEvent = createClickImageEvent("Container@reuse_Screen@img_card");
auto widgetEventsRequest = new WidgetEvents("Container", [clickImageEvent]);
sendRequest("sequential", widgetEventsRequest);
auto repeaterEvent = createChangeRepeaterValueEvent("Container@reuse_flowApplication@repeater_cards", "1");
auto labelValueEvent = createChangeLabelValueEvent("Container@reuse_flowApplication@lbl_cardNumber", "1", "INFO");
auto clickLabelEvent = createClickLabelEvent("Container@reuse_flowApplication@lbl_cardNumber");
widgetEventsRequest = new WidgetEvents("Container", [repeaterEvent, labelValueEvent, repeaterEvent, clickLabelEvent]);
auto response = sendRequest("sequential", widgetEventsRequest);
goHome();
foreach(widgetUpdate; response.responseSets[0].responses[0]["ScreenUpdate"])
{
if(widgetUpdate["widgetId"] == "Container@reuse_flowApplication@reuse_CreditCardCommonData@lbl_available_amount_value")
{
string available = widgetUpdate["properties"][1]["htmlText"].get!string;
return available.map!(c => c == '.' ? ',' : (c == ',' ? '.' : c)).map!(to!char).array;
}
}
return null;
}
private void goHome()
{
auto clickImageEvent = createClickImageEvent("Container@img_Home");
auto widgetEventsRequest = new WidgetEvents("Container", [clickImageEvent]);
sendRequest("sequential", widgetEventsRequest);
}
WidgetEventInformation createClickImageEvent(string widgetId)
{
return WidgetEventInformation(widgetId, "clicked", "Image", null);
@ -321,5 +363,9 @@ shared static this()
auto password = fromStringz(getpass("Password: ")).idup;
apiClient.login2(otp, password);
writeln("Funds available: " ~ apiClient.getAccountAvailable());
writeln("Account funds: " ~ apiClient.getAccountAvailable());
writeln("Card funds: " ~ apiClient.getCardAvailable());
writeln("Account funds: " ~ apiClient.getAccountAvailable());
writeln("Card funds: " ~ apiClient.getCardAvailable());
writeln("Account funds: " ~ apiClient.getAccountAvailable());
}