Multiple fixes

* Implemented ScriptRunner with environment expansion and cleaner
  code.
* Added ApiClient plugin (com.noccy.apiclient)
* Renamed CHANGELOG.md to VERSIONS.md
* Shuffled buildtools
* Added first unittests
This commit is contained in:
2021-12-11 01:44:01 +01:00
parent 8c6f7c1e93
commit 8cc1eac7a4
33 changed files with 1976 additions and 891 deletions

View File

@ -0,0 +1,84 @@
<?php // "name":"Call on web APIs", "author":"Noccy"
namespace SparkPlug\Com\Noccy\ApiClient\Api;
use JsonSerializable;
class Catalog implements JsonSerializable
{
private array $properties = [];
private array $methods = [];
private ?string $name;
private ?string $info;
public function __construct(array $catalog=[])
{
$catalog = $catalog['catalog']??[];
$this->name = $catalog['name']??null;
$this->info = $catalog['info']??null;
foreach ($catalog['props']??[] as $k=>$v) {
$this->properties[$k] = $v;
}
foreach ($catalog['methods']??[] as $k=>$v) {
$this->methods[$k] = new Method($v);
}
}
public static function createFromFile(string $filename): Catalog
{
$json = file_get_contents($filename);
$catalog = json_decode($json, true);
$catalog['name'] = basename($filename, ".json");
return new Catalog($catalog);
}
public function getName(): ?string
{
return $this->name;
}
public function getInfo(): ?string
{
return $this->info;
}
public function getProperties(): array
{
return $this->properties;
}
public function applyProperties(array $props)
{
$this->properties = array_merge($this->properties, $props);
}
public function addMethod(string $name, Method $method)
{
$this->methods[$name] = $method;
}
public function getMethod(string $method): ?Method
{
return $this->methods[$method]??null;
}
public function getMethods(): array
{
return $this->methods;
}
public function jsonSerialize(): mixed
{
return [
'catalog' => [
'name' => $this->name,
'info' => $this->info,
'props' => $this->properties,
'methods' => $this->methods,
]
];
}
}

View File

@ -0,0 +1,36 @@
<?php // "name":"Call on web APIs", "author":"Noccy"
namespace SparkPlug\Com\Noccy\ApiClient\Api;
use JsonSerializable;
class Method implements JsonSerializable
{
private array $properties = [];
private ?string $info;
public function __construct(array $method)
{
$this->properties = $method['props']??[];
$this->info = $method['info']??null;
}
public function getProperties(): array
{
return $this->properties;
}
public function getInfo(): ?string
{
return $this->info;
}
public function jsonSerialize(): mixed
{
return [
'info' => $this->info,
'props' => $this->properties,
];
}
}

View File

@ -0,0 +1,13 @@
<?php // "name":"Call on web APIs", "author":"Noccy"
namespace SparkPlug\Com\Noccy\ApiClient\Api;
class Profile
{
private array $properties = [];
public function getProperties(): array
{
return $this->properties;
}
}