Posts: 21
Threads: 1
Joined: Oct 2013
01-25-2015, 03:47 PM
Hi,
Is there anything i can use out of the box to perform HTTP request ?
Ideally i'd like to parse a http page returning some json and use it in my module.
Please help ^^
Many thanks
Posts: 2,172
Threads: 65
Joined: Oct 2013
You would have to include the portable "curl.exe" in your module, and use io.popen to read the results from it. Minion's version of lua doesn't include LuaSocket or anything else with a built-in http request API.
Posts: 21
Threads: 1
Joined: Oct 2013
01-27-2015, 07:05 PM
(This post was last modified: 01-27-2015, 07:09 PM by jm86.)
Thank you for your answer. In the meantime i did a small research on the forum and ended up on Havoc's module which uses this (and another library to extract json data). I got it to work, the main issue is as soon as i use fp:read it freezes FFXIV until i get the results from the API i'm calling.... and it takes about 4 seconds to get the response...
Code:
function prohunter.getDataFromAPI(ticks)
local fp = io.popen(
prohunter.curl ..
' "' ..
prohunter.apiURL
.. '"'
)
d('Read ticks');
prohunter.readticks = ticks
local response = fp:read("*a")
fp:close()
SendTextCommand(prohunter.CallText .. response);
end
I got the API URL from Guilwork digging in the network tab of chrome and found the ajax call to it ^o^
Code:
prohunter.apiURL = "http://guildwork.com/api/games/ffxiv/moogle/hunts";
You can imagine where i want to go with this... but yeah this 4 seconds total freeze is not a viable option. Any other workaround ?
I thought using a library for it like this one (=>
https://github.com/diegonehab/luasocket)... but this goes far beyond my knowledge (i'm a web dev)
Edit : I didn't read entirely your answer, so yeah that would the ideal solution. But is there any way i can use it even if it's not included in minion files... Or is it even possible to get it included by modifying a few things ? I tried to, by putting lua files directly in FFXIV folder (when i use require in my module it looks for the files in FFXIV dir, no matter what i do like this : prohunter.path = GetStartupPath() .. [[\LuaMods\prohunter\]]; but at some point it looks for core.lua , but there's no core.lua file, only a dll and i can't get lua to call it... Dunno if that makes sense ...
Anyway thanks for replying greatly appreciated[/code]
Posts: 737
Threads: 31
Joined: Apr 2013
Try os.execute instead of io.popen. But I am not sure if it will work in this situation.
Posts: 21
Threads: 1
Joined: Oct 2013
os.execute doesn't return anything :( Though i managed to get it work by creating a txt file and appending > [PATH TO FILE] so it saves the results in a tmp txt file.
Anyway i got the same issue with os.execute, it freezes FFXIV until it gets the job done. I guess i just have to give it up because of this, such a pity :(
Thanks for the help anyway