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 250: | Line 251: | ||
<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) | + | |
- | if data then | + | |
- | d(" | + | |
- | for _, v in pairs(data) do | + | |
- | d(v.name) | + | |
- | end | + | |
- | return data | + | |
- | end | + | |
- | end | + | |
- | local function failed(error, | + | |
- | d(" | + | if data then |
- | d("HTTP Failed Header: "..header) | + | d(" |
- | d("HTTP Failed StatusCode: | + | |
- | d(str or "Updating Characters failed, but nothing returned.") | + | end |
- | end | + | |
+ | local function HeadersTable(header) | ||
+ | if type(header) == "string" | ||
+ | header = string.match(header," | ||
+ | local tbl = {} | ||
+ | for w in header: | ||
+ | local k,v = string.match(w,"(.*): (.*)" | ||
+ | | ||
+ | end | ||
+ | table.print(tbl) | ||
+ | return tbl | ||
+ | end | ||
+ | end | ||
+ | |||
+ | header = HeadersTable(header) -- if you want to convert the header string to a table | ||
+ | | ||
- | local params = { | + | local function failed(error, |
- | host = "api.guidwars2.com", | + | d(" |
- | path = "/v2/characters?ids=all& | + | d(" |
- | port = 443, | + | d(" |
- | method = " | + | end |
- | https = true, | + | |
- | body = "", | + | local params = { |
- | headers = "", | + | host = "api.guildwars2.com", |
- | onsuccess = success, | + | path = "/v2/currencies?ids=1", |
- | onfailure = failed, | + | port = 443, |
- | getheaders = true // if true, headers | + | method = " |
- | } | + | https = true, |
- | HttpRequest(params) | + | onsuccess = success, |
+ | onfailure = failed, | ||
+ | getheaders = true, --true will return the headers, if you dont need it you can leave this at nil | ||
+ | body = "", | ||
+ | | ||
+ | | ||
+ | |||
+ | HttpRequest(params) | ||
end | end | ||
</ | </ |