Implement response parsing and session requests
This commit is contained in:
parent
1812a076a7
commit
f05de6a52e
80
source/app.d
80
source/app.d
|
@ -1,4 +1,5 @@
|
||||||
import std.stdio;
|
import std.stdio;
|
||||||
|
import std.conv;
|
||||||
|
|
||||||
import vibe.d;
|
import vibe.d;
|
||||||
import vibe.data.json;
|
import vibe.data.json;
|
||||||
|
@ -15,6 +16,19 @@ class ApiRequest
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct ApiResponse
|
||||||
|
{
|
||||||
|
ResponseSet[] responseSets;
|
||||||
|
bool pendingResponseSets;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct ResponseSet
|
||||||
|
{
|
||||||
|
string applicationId;
|
||||||
|
int requestCounter;
|
||||||
|
Json[] responses;
|
||||||
|
}
|
||||||
|
|
||||||
class OpenSession : ApiRequest
|
class OpenSession : ApiRequest
|
||||||
{
|
{
|
||||||
string applicationType;
|
string applicationType;
|
||||||
|
@ -29,6 +43,24 @@ class OpenSession : ApiRequest
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class StartFlow : ApiRequest
|
||||||
|
{
|
||||||
|
string applicationType;
|
||||||
|
string applicationId;
|
||||||
|
string flowName;
|
||||||
|
string[string] attributes;
|
||||||
|
string[string] privateAttributes;
|
||||||
|
|
||||||
|
this(string applicationType, string applicationId, string flowName, string[string] attributes, string[string] privateAttributes)
|
||||||
|
{
|
||||||
|
this.applicationType = applicationType;
|
||||||
|
this.applicationId = applicationId;
|
||||||
|
this.flowName = flowName;
|
||||||
|
this.attributes = attributes;
|
||||||
|
this.privateAttributes = privateAttributes;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class ApiMessage
|
class ApiMessage
|
||||||
{
|
{
|
||||||
string executionMode;
|
string executionMode;
|
||||||
|
@ -50,12 +82,30 @@ class ApiMessage
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class SessionApiMessage : ApiMessage
|
||||||
|
{
|
||||||
|
string sessionId;
|
||||||
|
string applicationId;
|
||||||
|
string requestCounter;
|
||||||
|
|
||||||
|
this(string executionMode, string sessionId, string applicationId, int requestCounter)
|
||||||
|
{
|
||||||
|
super(executionMode);
|
||||||
|
this.sessionId = sessionId;
|
||||||
|
this.applicationId = applicationId;
|
||||||
|
this.requestCounter = requestCounter.to!string;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class ApiClient
|
class ApiClient
|
||||||
{
|
{
|
||||||
enum string Endpoint = "https://m.belfius.be/F2CRenderingDexiaToClient/GEPARendering/machineIdentifier=s0/";
|
enum string Endpoint = "https://m.belfius.be/F2CRenderingDexiaToClient/GEPARendering/machineIdentifier=s0/";
|
||||||
|
|
||||||
private string _locale;
|
private string _locale;
|
||||||
|
|
||||||
|
private string _sessionId;
|
||||||
|
private int _requestCounter;
|
||||||
|
|
||||||
this(string locale)
|
this(string locale)
|
||||||
{
|
{
|
||||||
_locale = locale;
|
_locale = locale;
|
||||||
|
@ -67,13 +117,29 @@ class ApiClient
|
||||||
|
|
||||||
auto response = sendRequest("sequential", openSessionRequest);
|
auto response = sendRequest("sequential", openSessionRequest);
|
||||||
|
|
||||||
writeln(response);
|
_sessionId = response.responseSets[0].responses[0]["SessionOpened"][0]["sessionId"].get!string;
|
||||||
|
_requestCounter = 1;
|
||||||
|
|
||||||
|
auto startFlowRequest = new StartFlow("yui3a", "Container", "gef0.gef1.gemd.Flow_MobileApplication.diamlflow", ["deviceType": "simple", "language": "2", "smsType": "otpUrl"], null);
|
||||||
|
response = sendRequest("sequential", startFlowRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
Json sendRequest(T : ApiRequest)(string executionMode, T request)
|
ApiResponse sendRequest(T : ApiRequest)(string executionMode, T request)
|
||||||
{
|
{
|
||||||
auto message = new ApiMessage(executionMode);
|
|
||||||
message.addRequest(T.stringof, request);
|
string requestString;
|
||||||
|
if(_sessionId !is null)
|
||||||
|
{
|
||||||
|
auto message = new SessionApiMessage(executionMode, _sessionId, "Container", ++_requestCounter);
|
||||||
|
message.addRequest(T.stringof, request);
|
||||||
|
requestString = message.serializeToJsonString;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
auto message = new ApiMessage(executionMode);
|
||||||
|
message.addRequest(T.stringof, request);
|
||||||
|
requestString = message.serializeToJsonString;
|
||||||
|
}
|
||||||
|
|
||||||
auto response = requestHTTP(Endpoint,
|
auto response = requestHTTP(Endpoint,
|
||||||
(scope request) {
|
(scope request) {
|
||||||
|
@ -81,11 +147,13 @@ class ApiClient
|
||||||
request.headers["Accept"] = "*/*";
|
request.headers["Accept"] = "*/*";
|
||||||
request.headers["Content-Type"] = "application/x-www-form-urlencoded";
|
request.headers["Content-Type"] = "application/x-www-form-urlencoded";
|
||||||
request.headers["User-Agent"] = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.76 Safari/537.36";
|
request.headers["User-Agent"] = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.76 Safari/537.36";
|
||||||
request.writeBody(cast(ubyte[])("request=" ~ message.serializeToJsonString.urlEncode));
|
request.writeBody(cast(ubyte[])("request=" ~ requestString.urlEncode));
|
||||||
}
|
}
|
||||||
).bodyReader.readAllUTF8;
|
).bodyReader.readAllUTF8;
|
||||||
|
|
||||||
return response.parseJsonString;
|
auto json = response.parseJsonString;
|
||||||
|
|
||||||
|
return json.deserializeJson!ApiResponse;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue