107 lines
2.3 KiB
D
107 lines
2.3 KiB
D
import std.stdio;
|
|
|
|
import vibe.d;
|
|
import vibe.data.json;
|
|
import vibe.textfilter.urlencode;
|
|
|
|
void helloWorld(HTTPServerRequest req,
|
|
HTTPServerResponse res)
|
|
{
|
|
res.writeBody("Hello");
|
|
}
|
|
|
|
|
|
class ApiRequest
|
|
{
|
|
}
|
|
|
|
class OpenSession : ApiRequest
|
|
{
|
|
string applicationType;
|
|
string locale;
|
|
string[string] attributes;
|
|
|
|
this(string applicationType, string locale, string[string] attributes)
|
|
{
|
|
this.applicationType = applicationType;
|
|
this.locale = locale;
|
|
this.attributes = attributes;
|
|
}
|
|
}
|
|
|
|
class ApiMessage
|
|
{
|
|
string executionMode;
|
|
string protocolVersion;
|
|
Json[string][] requests;
|
|
|
|
this(string executionMode)
|
|
{
|
|
this.executionMode = executionMode;
|
|
this.protocolVersion = "2.1";
|
|
|
|
Json[string] requestArray;
|
|
this.requests = [requestArray];
|
|
}
|
|
|
|
void addRequest(T : ApiRequest)(string name, T request)
|
|
{
|
|
requests[0][name] = request.serializeToJson;
|
|
}
|
|
}
|
|
|
|
class ApiClient
|
|
{
|
|
enum string Endpoint = "https://m.belfius.be/F2CRenderingDexiaToClient/GEPARendering/machineIdentifier=s0/";
|
|
|
|
private string _locale;
|
|
|
|
this(string locale)
|
|
{
|
|
_locale = locale;
|
|
}
|
|
|
|
void connect()
|
|
{
|
|
auto openSessionRequest = new OpenSession("yui3a", _locale, ["application": "Container", "P": "P055"]);
|
|
|
|
auto response = sendRequest("sequential", openSessionRequest);
|
|
|
|
writeln(response);
|
|
}
|
|
|
|
Json sendRequest(T : ApiRequest)(string executionMode, T request)
|
|
{
|
|
auto message = new ApiMessage(executionMode);
|
|
message.addRequest(T.stringof, request);
|
|
|
|
auto response = requestHTTP(Endpoint,
|
|
(scope request) {
|
|
request.method = HTTPMethod.POST;
|
|
request.headers["Accept"] = "*/*";
|
|
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.writeBody(cast(ubyte[])("request=" ~ message.serializeToJsonString.urlEncode));
|
|
}
|
|
).bodyReader.readAllUTF8;
|
|
|
|
return response.parseJsonString;
|
|
}
|
|
}
|
|
|
|
shared static this()
|
|
{
|
|
auto router = new URLRouter;
|
|
router.get("/hello", &helloWorld);
|
|
|
|
auto settings = new HTTPServerSettings;
|
|
settings.sessionStore = new MemorySessionStore;
|
|
settings.port = 8080;
|
|
settings.bindAddresses = ["::1", "127.0.0.1"];
|
|
|
|
listenHTTP(settings, router);
|
|
|
|
auto apiClient = new ApiClient("nl_BE");
|
|
apiClient.connect();
|
|
}
|