MMOMinion

Full Version: HTTP or cURL Request
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
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.
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]
Try os.execute instead of io.popen. But I am not sure if it will work in this situation.
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