-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: client instance
- Loading branch information
Showing
5 changed files
with
157 additions
and
191 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
namespace Npldevfr\Liquipedia\Interfaces; | ||
|
||
interface LiquipediaBuilderInterface | ||
{ | ||
/** | ||
* 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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
namespace Npldevfr\Liquipedia; | ||
|
||
use GuzzleHttp\Client; | ||
|
||
final class Liquipedia | ||
{ | ||
private readonly string $apiKey; | ||
|
||
private readonly LiquipediaBuilder $builder; | ||
|
||
public function __construct( | ||
string $apiKey, | ||
?LiquipediaBuilder $builder = null | ||
) { | ||
|
||
if ($apiKey === '') { | ||
throw new \InvalidArgumentException('[Liquipedia] Api key is required'); | ||
} | ||
|
||
$this->apiKey = $apiKey; | ||
$this->builder = $builder ?? new LiquipediaBuilder( | ||
params: [], | ||
client: new Client([ | ||
'base_uri' => 'https://api.liquipedia.net/api/v3/', | ||
'headers' => [ | ||
'Authorization' => "Apikey {$this->apiKey}", | ||
], | ||
] | ||
)); | ||
|
||
} | ||
|
||
public function query(): LiquipediaBuilder | ||
{ | ||
return (new self($this->apiKey))->builder; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.