Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added gdc_lib_main/GDC.dll
Binary file not shown.
Binary file added gdc_lib_main/GDC_x64.dll
Binary file not shown.
56 changes: 56 additions & 0 deletions gdc_lib_main/functions/util/fn_restCall.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
Description:
Make a rest call to an url, with the right verb and if needed the body
[URL, "Get", nil, { Function }] call GDC_fnc_restCall;
[URL, "Post", "{ json: ""valid"" }", { Function }] call GDC_fnc_restCall;

Parameters:
0: URL
1: Verb (Get, Post, Put, Delete, Patch) // Patch Not implemented Yet
2: Body as json format, could be nil if verb is Get or Delete
3: Callback ( parameters [_fromUrl, _result] )

Tests:
Could be tested with https://docs.postman-echo.com/
GET -
systemChat str (["https://postman-echo.com/get?foo1=bar1", "Get"] call GDC_fnc_restCall);
GET with callback -
systemChat str (["https://postman-echo.com/get?foo1=bar1", "Get", nil, { systemChat str _this }] call GDC_fnc_restCall);
POST -
systemChat str (["https://postman-echo.com/post", "Post", "{ a: 1 }"] call GDC_fnc_restCall);
POST with callback -
systemChat str (["https://postman-echo.com/post", "Post", "{ a: 1 }", { systemChat str _this }] call GDC_fnc_restCall);
PUT -
systemChat str (["https://postman-echo.com/put", "Put", "{ a: 1 }"] call GDC_fnc_restCall);
DELETE -
systemChat str (["https://postman-echo.com/delete", "Delete"] call GDC_fnc_restCall);

Returns:
string: the body of the response
*/

params [
["_url","",[""]],
["_verb",{},[""]],
["_body",{},[""]],
["_callback",{},[{}, ""]]
];

if(! (_verb in ["Get", "Post", "Put", "Delete", "Patch"])) exitWith {
systemChat str ["Wrong verb: ", _verb];
};

_response = "";
if(_verb in ["Get", "Delete"]) then {
_response = "GDC" callExtension ["send", [_url, _verb]];
} else {
_response = "GDC" callExtension ["send", [_url, _verb, _body]];
};

if (typeName _callback == typeName {}) then {
[_url, _response] spawn _callback;
} else {
[_url, _response] execVM _callback;
};

_response;
55 changes: 17 additions & 38 deletions gdc_lib_main/functions/util/fn_urlFetch.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,27 @@
Make a call to an url
[URL, { Function }] call GDC_fnc_urlFetch;

Author & Source: http://killzonekid.com/arma-scripting-tutorials-url_fetch-callback/

Parameter(s):
0 : URL
1 : Callback ( parameters [_fromUrl, _result] )
0: URL
1: Callback ( parameters [_fromUrl, _result] )

Tests:
Could be tested with https://docs.postman-echo.com/
GET -
["https://postman-echo.com/get?foo1=bar1", { systemChat str _this }] call GDC_fnc_urlFetch;

Returns:
string: Return nothing
*/

if (isNil "url_fetch_queue") then {
url_fetch_queue = [_this];
{
_url = _x select 0;
_scr = _x select 1;
waitUntil {
if ("url_fetch" callExtension format [
"%1",
_url
] == "OK") exitWith {true};
false
};
private "_res";
waitUntil {
_res = "url_fetch" callExtension "OK";
if (_res != "WAIT") exitWith {true};
false
};
if (_res == "ERROR") then {
0 = [
_url,
"url_fetch" callExtension "ERROR"
] spawn url_fetch_error;
} else {
if (typeName _scr == typeName {}) then {
[_url, _res] spawn _scr;
} else {
[_url, _res] execVM _scr;
};
};
} forEach url_fetch_queue;
url_fetch_queue = nil;
params [
["_url","",[""]],
["_callback",{},[{}, ""]]
];

_res = "GDC" callExtension ["send", [_url, "Get"]];
if (typeName _callback == typeName {}) then {
[_url, _res] spawn _callback;
} else {
url_fetch_queue set [count url_fetch_queue, _this];
};
[_url, _res] execVM _callback;
};
14 changes: 0 additions & 14 deletions gdc_lib_main/functions/util/fn_urlFetchSimple.sqf

This file was deleted.

2 changes: 1 addition & 1 deletion gdc_lib_main/functions/util/index.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ class util
class addSingleUseHoldAction {};
class waitUntilPlayerInMarker {};
class urlFetch {};
class urlFetchSimple {};
class restCall {};
};
Binary file removed url_fetch.dll
Binary file not shown.