Skip to content

Commit

Permalink
fix: wrong docs
Browse files Browse the repository at this point in the history
  • Loading branch information
npldevfr committed Jan 30, 2024
1 parent daf272f commit 3bd0db4
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 153 deletions.
32 changes: 28 additions & 4 deletions src/Interfaces/LiquipediaBuilderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,45 @@

interface LiquipediaBuilderInterface
{
public function wiki(array|string $wikis): self;

/**
* Set wikis you want to query.
*
* @param array<string> | string $wikis
*/
public function wikis(array|string $wikis): self;

/**
* Set the endpoint you want to query.
*/
public function endpoint(string $endpoint): self;

/**
* Set the conditions you want to query.
*/
public function rawConditions(string $conditions): self;

/**
* Limit the number of results.
*/
public function limit(int $limit): self;

/**
* @return array<string, mixed>
*/
public function get(): array;

/**
* Add a wiki to the wikis you want to query.
*/
public function addWiki(string $wikis): self;

/**
* Set a result offset.
*/
public function offset(int $offset): self;

/**
* Order the results.
*/
public function orderBy(string $orderBy): self;


}
5 changes: 2 additions & 3 deletions src/Liquipedia.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Npldevfr\Liquipedia;

use GuzzleHttp\Client;
use Npldevfr\Liquipedia\Query\QueryParameters;

final class Liquipedia
{
Expand All @@ -16,7 +15,7 @@ public function __construct(
?LiquipediaBuilder $builder = null
) {

if ($apiKey === ''){
if ($apiKey === '') {
throw new \InvalidArgumentException('[Liquipedia] Api key is required');
}

Expand All @@ -33,7 +32,7 @@ public function __construct(

}

public function query(array $params = [], ?QueryParameters $queryParameters = null, ?Client $client = null): LiquipediaBuilder
public function query(): LiquipediaBuilder
{
return (new self($this->apiKey))->builder;
}
Expand Down
116 changes: 5 additions & 111 deletions src/LiquipediaBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public function __construct(
parent::__construct($params, $queryParameters, $client);
}


/**
* Set the wikis you want to query. You can pass an array of wikis or a string.
* Multi-wiki calls can be done by pipe-separating (|) wiki names.
Expand Down Expand Up @@ -144,7 +143,7 @@ public function pagination(int|string $pagination): self
*
* @throws Exception
*/
public function orderBy(string $field, string $direction = 'ASC'): self
public function orderBy(string $orderBy, string $direction = 'ASC'): self
{

$direction = strtoupper($direction);
Expand All @@ -153,7 +152,7 @@ public function orderBy(string $field, string $direction = 'ASC'): self
throw new Exception('[LiquipediaBuilder] Direction '.$direction.' is not valid.');
}

$this->queryParameters->order = "{$field} ".$direction;
$this->queryParameters->order = "{$orderBy} ".$direction;

return $this;
}
Expand Down Expand Up @@ -260,123 +259,18 @@ private function avoidWikiDuplicates(): void
public function get(?string $endpoint = null): array
{


$customEndpoint = $endpoint ?? $this->endpoint;
$response = json_decode($this->client->get($customEndpoint, [
'query' => $this->queryParameters->toArray(),
])->getBody()->getContents(), false, 512, JSON_THROW_ON_ERROR);

/**
* @var object $response
*/
if (isset($response->error)) {
throw new Exception($response->error);
}


// $this->queryParameters = new QueryParameters();
return $response->result ?? [];
}
// /**
// * @return $this
// */
// public function rawConditions(string $conditions): self
// {
// $this->params['conditions'] = trim($this->params['conditions'].' '.$conditions);
//
// return $this;
// }
//
// /**
// * @return $this
// *
// * @throws Exception
// */
// public function andCondition(string $key, string $operator, string $value): self
// {
// // operator are : :: (equals), ::! (not equals), ::< (lower than) or ::> (greater than).
// if (! in_array($operator, ['::', '::!', '::<', '::>'])) {
// throw new Exception('Operator must be ::, ::!, ::< or ::>');
// }
//
// $this->params['conditions'] = trim($this->params['conditions'].' AND '."[[{$key}{$operator}{$value}]]");
//
// return $this;
// }
//
// /**
// * @param array<string> $values
// * @return $this
// *
// * @throws Exception
// */
// public function andConditions(string $key, string $operator, array $values): self
// {
// // operator are : :: (equals), ::! (not equals), ::< (lower than) or ::> (greater than).
// if (! in_array($operator, ['::', '::!', '::<', '::>'])) {
// throw new Exception('Operator must be ::, ::!, ::< or ::>');
// }
//
// $conditions = [];
// foreach ($values as $value) {
// $conditions[] = "[[{$key}{$operator}{$value}]]";
// }
//
// $this->params['conditions'] = trim($this->params['conditions'].' '.implode(' AND ', $conditions));
//
// return $this;
// }
//
// /**
// * @return $this
// *
// * @throws Exception
// */
// public function orCondition(string $key, string $operator, string $value): self
// {
// // operator are : :: (equals), ::! (not equals), ::< (lower than) or ::> (greater than).
// if (! in_array($operator, ['::', '::!', '::<', '::>'])) {
// throw new Exception('Operator must be ::, ::!, ::< or ::>');
// }
//
// $this->params['conditions'] = trim($this->params['conditions'].' OR '."[[{$key}{$operator}{$value}]]");
//
// return $this;
// }
//
// /**
// * @param array<string> $values
// * @return $this
// *
// * @throws Exception
// */
// public function orConditions(string $key, string $operator, array $values): self
// {
// // operator are : :: (equals), ::! (not equals), ::< (lower than) or ::> (greater than).
// if (! in_array($operator, ['::', '::!', '::<', '::>'])) {
// throw new Exception('Operator must be ::, ::!, ::< or ::>');
// }
//
// $conditions = [];
// foreach ($values as $value) {
// $conditions[] = "[[{$key}{$operator}{$value}]]";
// }
//
// $this->params['conditions'] = trim($this->params['conditions'].' OR '.implode(' OR ', $conditions));
// $this->params['conditions'] = trim(preg_replace('/^OR/', '', $this->params['conditions']));
//
// return $this;
// }
//
// public function get(?string $endpoint = null): array
// {
//
// $customEndpoint = $endpoint ?? $this->endpoint;
// $response = json_decode($this->client->get($customEndpoint, [
// 'query' => $this->params,
// ])->getBody()->getContents(), false, 512, JSON_THROW_ON_ERROR);
//
// if (isset($response->error)) {
// throw new Exception($response->error);
// }
//
// return $response->result ?? [];
// }
}
Loading

0 comments on commit 3bd0db4

Please sign in to comment.