You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
2.2 KiB

extends Node2D
@onready var http_request = $HTTPRequest
# var base_address = "https://animegame.eu/api"
var base_address = "http://localhost:8000/api"
var auth_token = null
var user_name = "FooBar"
func create_dojo(dojo_name : String):
## Maybe get the HTTPRequest via parameter?
var body = JSON.stringify({"name": dojo_name})
if http_request.get_http_client_status():
# Prevent simultaneous request!
push_error("Busy with ongoing transaction!")
return
# _create_dojo_request.request_completed.connect(self._http_request_completed)
var error = http_request.request("{address}/dojos".format({"address": base_address}), ["Content-Type: application/json", "X-AUTH-TOKEN: %s" % auth_token], HTTPClient.METHOD_POST, body)
if error != OK:
push_error("An error occurred in the HTTP request.")
else:
print("Okay?")
print("Amount of children %s" % get_child_count())
# Called when the node enters the scene tree for the first time.
func _ready():
print_debug("Global Scene is ready!")
for argument in OS.get_cmdline_user_args():
print_debug("argument: %s" % argument)
var key_value = argument.split("=", true, 1)
if "--token" == key_value[0]:
print_debug("key_value[0]: %s" % key_value[0])
print_debug("key_value[1]: %s" % key_value[1])
self.auth_token = key_value[1]
# replace \-_ with /\+
print_debug("auth_token before: %s", self.auth_token)
print_debug("auth_token after: %s", self.auth_token.replace("\\", "/").replace("-", "\\").replace("_", "+"))
var chunks = Marshalls.base64_to_raw(self.auth_token.replace("\\", "/").replace("-", "\\").replace("_", "+"))
self.user_name = chunks.slice(64).get_string_from_utf8().split('|')[0]
print_debug("user name: %s" % self.user_name)
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta):
pass
func _on_http_request_request_completed(_result, _response_code, headers, body):
## Where to get the response to?
print("Completed?")
var json = JSON.new()
json.parse(body.get_string_from_utf8())
var response = json.get_data()
# Will print the user agent string used by the HTTPRequest node (as recognized by httpbin.org).
print(headers)
print(response)