Files
Aurora.3/code/modules/http/forum_api.dm
Matt Atlas cadd19beac Ports the TG globals controller and converts globals. (#18057)
* SDQL2 update

* fix that verb

* cl

* fix that

* toworld

* this is pointless

* update info

* siiiiick..

* vv edit update

* fix that

* fix editing vars

* fix VV

* Port the /TG/ globals controller.

* part 1

* part 2

* oops

* part 3

* Hollow Purple

* sadas

* bsbsdb

* muda na agaki ta

* ids 1-15

* 16-31

* 41-75

* bring me back to how things used to be before i lost it all

* the strength of mayhem

* final touches

* cl

* protect some vars

* update sdql2 to use glob

* stuff?

* forgot that is not defined there

* whoops

* observ

* but it never gets better

* a

---------

Co-authored-by: Matt Atlas <liermattia@gmail.com>
2023-12-26 01:16:02 +00:00

52 lines
1.3 KiB
Plaintext

var/global/forum_api_key = null
/datum/http_request/forum_api
var/end_point
/datum/http_request/forum_api/New(ep)
end_point = ep
/datum/http_request/forum_api/proc/_get_url(suffix)
PRIVATE_PROC(TRUE)
. = "[GLOB.config.forum_api_path]/[end_point]"
if (suffix)
. += "/[suffix]"
. += "?key=[global.forum_api_key]"
/datum/http_request/forum_api/proc/prepare_get(subtopic, list/params)
var/url = _get_url(subtopic)
if (length(params))
url += "&[list2params(params)]"
prepare(RUSTG_HTTP_METHOD_GET, url, null, null)
/datum/http_request/forum_api/proc/prepare_post(subtopic, list/params)
prepare(RUSTG_HTTP_METHOD_POST, _get_url(subtopic), params2list(params), list("Content-Type" = "application/x-www-form-urlencoded"))
/datum/http_request/forum_api/proc/prepare_delete(subtopic, list/params)
prepare(RUSTG_HTTP_METHOD_DELETE, _get_url(subtopic), params2list(params), list("Content-Type" = "application/x-www-form-urlencoded"))
/datum/http_request/forum_api/into_response()
var/datum/http_response/R = ..()
if (R.errored)
return R
try
R.body = json_decode(R.body)
catch
R.errored = TRUE
R.error = "Malformed JSON returned."
return R
var/list/resp_data = R.body
if (resp_data["errorCode"])
R.errored = TRUE
R.error = resp_data["errorMessage"]
return R