Thread Rating:
  • 5 Vote(s) - 3.2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
HTTP or cURL Request
#1
Star 
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
Reply
#2
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.
Reply
#3
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]
Reply
#4
Try os.execute instead of io.popen. But I am not sure if it will work in this situation.
Reply
#5
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
Reply
 


Forum Jump:


Users browsing this thread: 4 Guest(s)

We help you win the game.

FFXIV Bot and More.

 

Products