This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
minionlib [2020/12/13 15:44] – fxfire | minionlib [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(" | *Use RegisterEventHandler(" | ||
+ | *Requires at least 1 argument, even if it's a blank string. (ex. QueueEvent(" | ||
Line 244: | Line 245: | ||
***'' | ***'' | ||
- | ==HTTPRequest== | + | |
- | Use this function to do any kind of asynchronous http calls. | + | ===HTTPRequest=== |
+ | Use this function to do any kind of asynchronous http calls. | ||
<code lua> | <code lua> | ||
function SendHttpRequest() | function SendHttpRequest() | ||
- | local API_Key = " | + | local function success(str, |
- | local function success(str, | + | d(" |
- | d(" | + | d(" |
- | d(" | + | d(" |
- | d(" | + | |
- | + | local data = json.decode(str) | |
- | local data = json.decode(str) | + | if data then |
- | if data then | + | |
- | d(" | + | d(data) |
- | for _, v in pairs(data) do | + | end |
- | d(v.name) | + | |
- | end | + | local function HeadersTable(header) |
- | return | + | if type(header) == " |
- | end | + | header = string.match(header," |
- | end | + | local tbl = {} |
+ | for w in header: | ||
+ | local k,v = string.match(w," | ||
+ | tbl[k] = v | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | end | ||
+ | |||
+ | header = HeadersTable(header) -- if you want to convert the header string to a table | ||
+ | end | ||
+ | |||
+ | local function failed(error, | ||
+ | d(" | ||
+ | d(" | ||
+ | d(" | ||
+ | end | ||
- | local function failed(error, | + | local params = { |
- | d(" | + | host = "api.guildwars2.com", |
- | d("HTTP Failed Header: | + | path = "/ |
- | d("HTTP Failed StatusCode: | + | port = 443, |
- | d(str | + | |
- | 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 = "", | ||
+ | headers = {}, --optional, if not required for your call can be nil or "" | ||
+ | } | ||
- | local params = { | + | HttpRequest(params) |
- | host = " | + | |
- | path = "/ | + | |
- | port = 443, | + | |
- | method = " | + | |
- | https = true, | + | |
- | body = "", | + | |
- | headers = "", | + | |
- | onsuccess = success, | + | |
- | onfailure = failed, | + | |
- | getheaders = true // if true, headers will be returned | + | |
- | } | + | |
- | HttpRequest(params) | + | |
end | end | ||
</ | </ |