develop version for new api concept

This commit is contained in:
marko
2023-12-23 14:54:48 +01:00
parent 868c05f0c1
commit 66a9761562
2 changed files with 73 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
<?php
setlocale(LC_ALL, 'de_DE@euro', 'de_DE', 'de', 'ge');
set_include_path(get_include_path() . PATH_SEPARATOR . '../lib/'. PATH_SEPARATOR. '..');
require_once 'config/participo.php';
require_once 'local/cwsvJudo.php';
require_once 'participoLib/participo.php';
if(array_key_exists("HTTP_AUTHORIZATION", $_SERVER)){
if(!empty($_SERVER["HTTP_AUTHORIZATION"])){
$auth = explode(" ", $_SERVER["HTTP_AUTHORIZATION"]);
if($auth[0]="Basic"){
$db = dbConnector::connect(
$cwsvJudoConfig['db']['host'],
$cwsvJudoConfig['db']['name'],
$cwsvJudoConfig['db']['user'],
$cwsvJudoConfig['db']['password']
);
$allowKey = ApiKey::loadFromDb($auth[1]);
}
}
}
if (!$allowKey || !$allowKey->isValidFor('api')) {
die(json_encode(['success' => false]));
}
$wkSqlQuery = 'SELECT * FROM `wettkampfkalender` WHERE `Datum` >= CURDATE();';
$wkSqlResponse = dbConnector::query($wkSqlQuery);
header('Access-Control-Allow-Headers: *');
header('Access-Control-Allow-Origin: *');
echo(
json_encode($wkSqlResponse)
// json_encode(getallheaders())
// json_encode($_SERVER)
);

View File

@@ -0,0 +1,33 @@
from http import client
import logging
import json
import yaml
host="cwsvjudo.bplaced.net"
with open("testApi.config.yaml", "r") as f:
config = yaml.load(f)
logging.basicConfig(level=logging.DEBUG)
connection = client.HTTPConnection(host=host, port=80, timeout=1)
connection.request(
method="GET",
url="/participo/api/users",
headers={
"Authorization": f"Basic {config['apiKey']}"
}
)
response = connection.getresponse()
print("Status: {} and reason: {}".format(response.status, response.reason))
body = response.read()
try:
print(json.dumps(json.loads(body),indent=2))
except:
print(f"failed to parse to json")
print(body
)
connection.close()