diff --git a/gdc_lib_main/GDC.dll b/gdc_lib_main/GDC.dll new file mode 100644 index 0000000..b74ddb0 Binary files /dev/null and b/gdc_lib_main/GDC.dll differ diff --git a/gdc_lib_main/GDC_x64.dll b/gdc_lib_main/GDC_x64.dll new file mode 100644 index 0000000..c8b83a1 Binary files /dev/null and b/gdc_lib_main/GDC_x64.dll differ diff --git a/gdc_lib_main/functions/util/fn_restCall.sqf b/gdc_lib_main/functions/util/fn_restCall.sqf new file mode 100644 index 0000000..d64e5f5 --- /dev/null +++ b/gdc_lib_main/functions/util/fn_restCall.sqf @@ -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; diff --git a/gdc_lib_main/functions/util/fn_urlFetch.sqf b/gdc_lib_main/functions/util/fn_urlFetch.sqf index c68202b..5be0c47 100644 --- a/gdc_lib_main/functions/util/fn_urlFetch.sqf +++ b/gdc_lib_main/functions/util/fn_urlFetch.sqf @@ -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]; -}; \ No newline at end of file + [_url, _res] execVM _callback; +}; diff --git a/gdc_lib_main/functions/util/fn_urlFetchSimple.sqf b/gdc_lib_main/functions/util/fn_urlFetchSimple.sqf deleted file mode 100644 index a7b84e0..0000000 --- a/gdc_lib_main/functions/util/fn_urlFetchSimple.sqf +++ /dev/null @@ -1,14 +0,0 @@ -/* - Description: - Make a call to an url - http://127.0.0.1 call GDC_fnc_urlFetch; - - Parameter(s): - 0 : URL - - Returns: - string: Return the result of the url call -*/ - -"url_fetch" callExtension _this; - diff --git a/gdc_lib_main/functions/util/index.hpp b/gdc_lib_main/functions/util/index.hpp index 0285525..f9722d0 100644 --- a/gdc_lib_main/functions/util/index.hpp +++ b/gdc_lib_main/functions/util/index.hpp @@ -13,5 +13,5 @@ class util class addSingleUseHoldAction {}; class waitUntilPlayerInMarker {}; class urlFetch {}; - class urlFetchSimple {}; + class restCall {}; }; diff --git a/url_fetch.dll b/url_fetch.dll deleted file mode 100644 index 390148c..0000000 Binary files a/url_fetch.dll and /dev/null differ