Skip to content
This repository has been archived by the owner on Apr 9, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2 from Fortnite-API/api-keys
Browse files Browse the repository at this point in the history
Enabling API-Key support
  • Loading branch information
michel-pi authored Dec 18, 2019
2 parents 8dade17 + 7991eef commit ba932db
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 99 deletions.
29 changes: 21 additions & 8 deletions src/Components/Endpoints/CosmeticsEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,31 @@

namespace FortniteApi\Components\Endpoints;

use FortniteApi\Components\HttpClient;
use FortniteApi\Components\Objects\Cosmetic;
use FortniteApi\Components\Tasks\CosmeticArrayTask;
use FortniteApi\Components\Tasks\CosmeticTask;
use FortniteApi\FortniteApi;
use FortniteApi\FortniteApiError;

use GuzzleHttp\Client;

/**
* Provides access to the /cosmetics/ endpoint
*/
class CosmeticsEndpoint
{
/**
* Undocumented variable
*
* @var Client
*/
private $httpClient;

public function __construct($httpClient)
{
$this->httpClient = $httpClient;
}

/**
* Returns the requested cosmetic.
*
Expand Down Expand Up @@ -64,9 +77,9 @@ public function getAsync($cosmeticId, $language = null)
}

if (count($query) == 0) {
$promise = HttpClient::getInstance()->getAsync($path);
$promise = $this->httpClient->getAsync($path);
} else {
$promise = HttpClient::getInstance()->getAsync($path, [
$promise = $this->httpClient->getAsync($path, [
"query" => $query
]);
}
Expand Down Expand Up @@ -116,9 +129,9 @@ public function getAllAsync($language = null)
}

if (count($query) == 0) {
$promise = HttpClient::getInstance()->getAsync($path);
$promise = $this->httpClient->getAsync($path);
} else {
$promise = HttpClient::getInstance()->getAsync($path, [
$promise = $this->httpClient->getAsync($path, [
"query" => $query
]);
}
Expand Down Expand Up @@ -167,7 +180,7 @@ public function searchAsync($query, $language = null)
$query["language"] = $language;
}

$promise = HttpClient::getInstance()->getAsync($path, [
$promise = $this->httpClient->getAsync($path, [
"query" => $query
]);

Expand Down Expand Up @@ -215,7 +228,7 @@ public function searchAllAsync($query, $language = null)
$query["language"] = $language;
}

$promise = HttpClient::getInstance()->getAsync($path, [
$promise = $this->httpClient->getAsync($path, [
"query" => $query
]);

Expand Down Expand Up @@ -277,7 +290,7 @@ public function searchIdsAsync($ids, $language = null)
$query["language"] = $language;
}

$promise = HttpClient::getInstance()->getAsync($path, [
$promise = $this->httpClient->getAsync($path, [
"query" => $query
]);

Expand Down
21 changes: 17 additions & 4 deletions src/Components/Endpoints/CreatorCodeEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,29 @@

namespace FortniteApi\Components\Endpoints;

use FortniteApi\Components\HttpClient;
use FortniteApi\Components\Tasks\CreatorCodeArrayTask;
use FortniteApi\Components\Tasks\CreatorCodeTask;
use FortniteApi\FortniteApiError;

use GuzzleHttp\Client;

/**
* Provides access to the /creatorcode endpoint.
*/
class CreatorCodeEndpoint
{
/**
* Undocumented variable
*
* @var Client
*/
private $httpClient;

public function __construct($httpClient)
{
$this->httpClient = $httpClient;
}

/**
* Returns the creator code data for a given slug.
*
Expand Down Expand Up @@ -51,7 +64,7 @@ public function getAsync($slug)
"slug" => $slug
];

$promise = HttpClient::getInstance()->getAsync($path, [
$promise = $this->httpClient->getAsync($path, [
"query" => $query
]);

Expand Down Expand Up @@ -97,7 +110,7 @@ public function searchAsync($slug)
"slug" => $slug
];

$promise = HttpClient::getInstance()->getAsync($path, [
$promise = $this->httpClient->getAsync($path, [
"query" => $query
]);

Expand Down Expand Up @@ -143,7 +156,7 @@ public function searchAllAsync($slug)
"slug" => $slug
];

$promise = HttpClient::getInstance()->getAsync($path, [
$promise = $this->httpClient->getAsync($path, [
"query" => $query
]);

Expand Down
23 changes: 18 additions & 5 deletions src/Components/Endpoints/NewsEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,30 @@

namespace FortniteApi\Components\Endpoints;

use FortniteApi\Components\HttpClient;
use FortniteApi\Components\Tasks\NewsEntryTask;
use FortniteApi\Components\Tasks\NewsTask;
use FortniteApi\FortniteApi;
use FortniteApi\FortniteApiError;

use GuzzleHttp\Client;

/**
* Provides access to the /news/ endpoint.
*/
class NewsEndpoint
{
/**
* Undocumented variable
*
* @var Client
*/
private $httpClient;

public function __construct($httpClient)
{
$this->httpClient = $httpClient;
}

/**
* Returns the data of the current battle royale, save the world and creative news.
*
Expand Down Expand Up @@ -55,9 +68,9 @@ public function getAsync($language = null)
}

if (count($query) == 0) {
$promise = HttpClient::getInstance()->getAsync($path);
$promise = $this->httpClient->getAsync($path);
} else {
$promise = HttpClient::getInstance()->getAsync($path, [
$promise = $this->httpClient->getAsync($path, [
"query" => $query
]);
}
Expand Down Expand Up @@ -168,9 +181,9 @@ private function internalGetAsync($section, $language = null)
}

if (count($query) == 0) {
$promise = HttpClient::getInstance()->getAsync($path);
$promise = $this->httpClient->getAsync($path);
} else {
$promise = HttpClient::getInstance()->getAsync($path, [
$promise = $this->httpClient->getAsync($path, [
"query" => $query
]);
}
Expand Down
19 changes: 16 additions & 3 deletions src/Components/Endpoints/ShopEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,29 @@

namespace FortniteApi\Components\Endpoints;

use FortniteApi\Components\HttpClient;
use FortniteApi\Components\Tasks\ShopTask;
use FortniteApi\FortniteApi;
use FortniteApi\FortniteApiError;

use GuzzleHttp\Client;

/**
* Provides access to the /shop/ endpoint.
*/
class ShopEndpoint
{
/**
* Undocumented variable
*
* @var Client
*/
private $httpClient;

public function __construct($httpClient)
{
$this->httpClient = $httpClient;
}

/**
* Returns the current battle royale shop.
*
Expand Down Expand Up @@ -54,9 +67,9 @@ public function getAsync($language = null)
}

if (count($query) == 0) {
$promise = HttpClient::getInstance()->getAsync($path);
$promise = $this->httpClient->getAsync($path);
} else {
$promise = HttpClient::getInstance()->getAsync($path, [
$promise = $this->httpClient->getAsync($path, [
"query" => $query
]);
}
Expand Down
24 changes: 0 additions & 24 deletions src/Components/HttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,8 @@

namespace FortniteApi\Components;

use GuzzleHttp\Client;
use FortniteApi\Config\Config;

class HttpClient
{
/**
* Undocumented variable
*
* @var Client
*/
private static $_client;

public static function isSuccess($statusCode)
{
if (empty($statusCode) || !is_int($statusCode)) {
Expand All @@ -22,18 +12,4 @@ public static function isSuccess($statusCode)

return $statusCode >= 200 && $statusCode < 400;
}

/**
* Undocumented function
*
* @return Client
*/
public static function getInstance()
{
if (empty(self::$_client)) {
self::$_client = new Client(Config::getHttpClientConfig());
}

return self::$_client;
}
}
46 changes: 0 additions & 46 deletions src/Config/Config.php

This file was deleted.

Loading

0 comments on commit ba932db

Please sign in to comment.