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:
84
plugins/com.noccy.apiclient/Api/Catalog.php
Normal file
84
plugins/com.noccy.apiclient/Api/Catalog.php
Normal 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,
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
36
plugins/com.noccy.apiclient/Api/Method.php
Normal file
36
plugins/com.noccy.apiclient/Api/Method.php
Normal 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,
|
||||
];
|
||||
}
|
||||
}
|
13
plugins/com.noccy.apiclient/Api/Profile.php
Normal file
13
plugins/com.noccy.apiclient/Api/Profile.php
Normal 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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user