User Tools

Site Tools



minionlib

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
minionlib [2020/12/13 15:44] fxfireminionlib [2021/04/30 18:13] (current) ace
Line 88: Line 88:
     *Queues and Fires the Event with 1-n arguments. Eventname and arguments need to be strings.      *Queues and Fires the Event with 1-n arguments. Eventname and arguments need to be strings. 
     *Use RegisterEventHandler("eventname", handlerfunc) , to register a lua function which will handle the fired event.     *Use RegisterEventHandler("eventname", handlerfunc) , to register a lua function which will handle the fired event.
 +    *Requires at least 1 argument, even if it's a blank string. (ex. QueueEvent("some event",""))
  
  
Line 244: Line 245:
   ***''ml_gui.ui_mgr:AddComponent( //table// submember, //string// componentid, //string// memberid)''**   ***''ml_gui.ui_mgr:AddComponent( //table// submember, //string// componentid, //string// memberid)''**
  
-==HTTPRequest== + 
-Use this function to do any kind of asynchronous http calls.+===HTTPRequest=== 
 +Use this function to do any kind of asynchronous http calls. Example:
  
 <code lua> <code lua>
 function SendHttpRequest() function SendHttpRequest()
- local API_Key = "XXXXXX-587C-3XXX-90B5-XXXXXXXXXXXXXXX3F-XXX-4A79-XXX-XXXXXXXXXX" +   local function success(str, header, statuscode) 
- local function success(str,header,statuscode)  +      d("HTTP Request: success."
- d("HTTP Request: success."+      d("HTTP Result Header: " .. tostring(header)
- d("HTTP Result Header: "..header) +      d("HTTP Result StatusCode: " .. tostring(statuscode)) 
- d("HTTP Result StatusCode: "..tostring(statuscode)) + 
-  +      local data = json.decode(str) 
- local data = json.decode(str) +      if data then 
- if data then +         d("HTTP Request: data valid. Currency Coin info:") 
- d("HTTP Request: data valid. Fetched Characters:") +         d(data) 
- for _in pairs(data) do +      end 
- d(v.name+       
- end +      local function HeadersTable(header) 
- return data +         if type(header) == "string" and #header > 0 then 
- end +            header = string.match(header,".?%c(.*)") -- Removing the first entry 
- end+            local tbl = {} 
 +            for w in header:gmatch("[^%c]+") do 
 +               local k,= string.match(w,"(.*): (.*)"
 +               tbl[k] = v 
 +            end 
 +            table.print(tbl) 
 +            return tbl 
 +         end 
 +      end 
 +       
 +      header = HeadersTable(header) -- if you want to convert the header string to a table 
 +   end 
 + 
 +   local function failed(error, header, statuscode) 
 +      d("HTTP Failed Error: " .. error) 
 +      d("HTTP Failed Header: " .. header) 
 +      d("HTTP Failed StatusCode: " .. tostring(statuscode)) 
 +   end
  
- local function failed(error,header,statuscode) +   local params = { 
- d("HTTP Failed Error: "..error) +      host = "api.guildwars2.com", 
- d("HTTP Failed Header: "..header) +      path = "/v2/currencies?ids=1"
- d("HTTP Failed StatusCode: "..tostring(statuscode)) +      port = 443, 
- d(str or "Updating Characters failedbut nothing returned.") +      method = "GET", -- "GET","POST","PUT","DELETE
- end+      https = true, 
 +      onsuccess = success, 
 +      onfailure = failed, 
 +      getheaders = true, --true will return the headers, if you dont need it you can leave this at nil 
 +      body = "", --optional, if not required for your call can be nil or "
 +      headers = {}--optional, if not required for your call can be nil or "
 +   }
  
- local params = {  +   HttpRequest(params)
- host = "api.guidwars2.com",  +
- path = "/v2/characters?ids=all&access_token=" .. API_Key,  +
- port = 443,  +
- method = "GET", //"GET" or "POST" +
- https = true,  +
- body = "",  +
- headers = "", +
- onsuccess = success,  +
- onfailure = failed,  +
- getheaders = true // if true, headers will be returned +
-+
- HttpRequest(params)+
 end end
 </code> </code>
minionlib.1607874264.txt.gz · Last modified: 2020/12/13 15:44 by fxfire