remove users collection and used code

This commit is contained in:
Martz
2023-02-28 21:12:38 +01:00
parent c52ff18bea
commit 78fd67a12d
4 changed files with 11 additions and 54 deletions

View File

@@ -10,9 +10,7 @@
"autoload": { "autoload": {
"classmap": [ "classmap": [
"src/Client.php", "src/Client.php",
"src/Collection.php", "src/Collection.php"
"src/UsersCollection.php"
]
}, },
"require": { "require": {
"php": "^8.1|^8.2", "php": "^8.1|^8.2",

View File

@@ -2,28 +2,16 @@
namespace Pb; namespace Pb;
use UsersCollection;
class Client class Client
{ {
private string $response;
private string $url; private string $url;
private string $route;
public function __construct(string $url) public function __construct(string $url)
{ {
$this->response = '{}';
$this->url = $url; $this->url = $url;
$this->users = [];
} }
public function users() public function collection(string $collection): Collection
{
return new UsersCollection($this->url, 'records');
}
public function collection(string $collection)
{ {
return new Collection($this->url ,$collection); return new Collection($this->url ,$collection);
} }

View File

@@ -35,9 +35,9 @@ class Collection
/** /**
* @param int $batch * @param int $batch
* @param array $queryParams * @param array $queryParams
* @return mixed * @return array
*/ */
public function getFullList(int $batch = 200, array $queryParams = []) public function getFullList(int $batch = 200, array $queryParams = []): array
{ {
$getParams = !empty($queryParams) ? http_build_query($queryParams) : ""; $getParams = !empty($queryParams) ? http_build_query($queryParams) : "";
$response = $this->doRequest($this->url . "/api/collections/" . $this->collection . "/records?" . $getParams, 'GET'); $response = $this->doRequest($this->url . "/api/collections/" . $this->collection . "/records?" . $getParams, 'GET');
@@ -50,7 +50,7 @@ class Collection
* @param array $queryParams * @param array $queryParams
* @return array * @return array
*/ */
public function getFirstListItem(string $filter, array $queryParams = []) public function getFirstListItem(string $filter, array $queryParams = []): array
{ {
$queryParams['perPage'] = 1; $queryParams['perPage'] = 1;
$getParams = !empty($queryParams) ? http_build_query($queryParams) : ""; $getParams = !empty($queryParams) ? http_build_query($queryParams) : "";
@@ -63,7 +63,7 @@ class Collection
* @param array $queryParams * @param array $queryParams
* @return void * @return void
*/ */
public function create(array $bodyParams = [], array $queryParams = []) public function create(array $bodyParams = [], array $queryParams = []): void
{ {
$this->doRequest($this->url . "/api/collections/" . $this->collection . "/records", 'POST', json_encode($bodyParams)); $this->doRequest($this->url . "/api/collections/" . $this->collection . "/records", 'POST', json_encode($bodyParams));
} }
@@ -74,7 +74,7 @@ class Collection
* @param array $queryParams * @param array $queryParams
* @return void * @return void
*/ */
public function update(string $recordId, array $bodyParams = [], array $queryParams = []) public function update(string $recordId, array $bodyParams = [], array $queryParams = []): void
{ {
// Todo bodyParams equals json, currently workaround // Todo bodyParams equals json, currently workaround
$this->doRequest($this->url . "/api/collections/" . $this->collection . "/records/" . $recordId, 'PATCH', json_encode($bodyParams)); $this->doRequest($this->url . "/api/collections/" . $this->collection . "/records/" . $recordId, 'PATCH', json_encode($bodyParams));
@@ -85,7 +85,7 @@ class Collection
* @param array $queryParams * @param array $queryParams
* @return void * @return void
*/ */
public function delete(string $recordId, array $queryParams = []) public function delete(string $recordId, array $queryParams = []): void
{ {
$this->doRequest($this->url . "/api/collections/" . $this->collection . "/records/" . $recordId, 'DELETE'); $this->doRequest($this->url . "/api/collections/" . $this->collection . "/records/" . $recordId, 'DELETE');
} }
@@ -96,7 +96,7 @@ class Collection
* @param string $method * @param string $method
* @return bool|string * @return bool|string
*/ */
public function doRequest(string $url, string $method, $bodyParams = []) public function doRequest(string $url, string $method, $bodyParams = []): string
{ {
$ch = curl_init(); $ch = curl_init();
@@ -126,7 +126,7 @@ class Collection
* @param array $queryParams * @param array $queryParams
* @return mixed * @return mixed
*/ */
public function getOne(string $recordId, array $queryParams = []) public function getOne(string $recordId, array $queryParams = []): array
{ {
$output = $this->doRequest($this->url . "/api/collections/" . $this->collection . "/records/" . $recordId, 'GET'); $output = $this->doRequest($this->url . "/api/collections/" . $this->collection . "/records/" . $recordId, 'GET');
return json_decode($output, JSON_FORCE_OBJECT); return json_decode($output, JSON_FORCE_OBJECT);
@@ -137,7 +137,7 @@ class Collection
* @param string $password * @param string $password
* @return void * @return void
*/ */
public function authAsAdmin(string $email, string $password) public function authAsAdmin(string $email, string $password): void
{ {
$bodyParams['identity'] = $email; $bodyParams['identity'] = $email;
$bodyParams['password'] = $password; $bodyParams['password'] = $password;

View File

@@ -1,29 +0,0 @@
<?php
class UsersCollection
{
private string $url;
private string $collection;
public function __construct(string $url, string $collection)
{
$this->url = $url;
$this->collection = $collection;
}
public function getList($page = 1, $perPage = 30)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->url . "/api/collections/users/records");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
return json_decode($output, JSON_FORCE_OBJECT);
}
public function authWithPassword()
{
var_dump('try auth');
}
}