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

Commit ba932db

Browse files
authored
Merge pull request #2 from Fortnite-API/api-keys
Enabling API-Key support
2 parents 8dade17 + 7991eef commit ba932db

File tree

8 files changed

+133
-99
lines changed

8 files changed

+133
-99
lines changed

src/Components/Endpoints/CosmeticsEndpoint.php

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,31 @@
22

33
namespace FortniteApi\Components\Endpoints;
44

5-
use FortniteApi\Components\HttpClient;
65
use FortniteApi\Components\Objects\Cosmetic;
76
use FortniteApi\Components\Tasks\CosmeticArrayTask;
87
use FortniteApi\Components\Tasks\CosmeticTask;
98
use FortniteApi\FortniteApi;
109
use FortniteApi\FortniteApiError;
1110

11+
use GuzzleHttp\Client;
12+
1213
/**
1314
* Provides access to the /cosmetics/ endpoint
1415
*/
1516
class CosmeticsEndpoint
1617
{
18+
/**
19+
* Undocumented variable
20+
*
21+
* @var Client
22+
*/
23+
private $httpClient;
24+
25+
public function __construct($httpClient)
26+
{
27+
$this->httpClient = $httpClient;
28+
}
29+
1730
/**
1831
* Returns the requested cosmetic.
1932
*
@@ -64,9 +77,9 @@ public function getAsync($cosmeticId, $language = null)
6477
}
6578

6679
if (count($query) == 0) {
67-
$promise = HttpClient::getInstance()->getAsync($path);
80+
$promise = $this->httpClient->getAsync($path);
6881
} else {
69-
$promise = HttpClient::getInstance()->getAsync($path, [
82+
$promise = $this->httpClient->getAsync($path, [
7083
"query" => $query
7184
]);
7285
}
@@ -116,9 +129,9 @@ public function getAllAsync($language = null)
116129
}
117130

118131
if (count($query) == 0) {
119-
$promise = HttpClient::getInstance()->getAsync($path);
132+
$promise = $this->httpClient->getAsync($path);
120133
} else {
121-
$promise = HttpClient::getInstance()->getAsync($path, [
134+
$promise = $this->httpClient->getAsync($path, [
122135
"query" => $query
123136
]);
124137
}
@@ -167,7 +180,7 @@ public function searchAsync($query, $language = null)
167180
$query["language"] = $language;
168181
}
169182

170-
$promise = HttpClient::getInstance()->getAsync($path, [
183+
$promise = $this->httpClient->getAsync($path, [
171184
"query" => $query
172185
]);
173186

@@ -215,7 +228,7 @@ public function searchAllAsync($query, $language = null)
215228
$query["language"] = $language;
216229
}
217230

218-
$promise = HttpClient::getInstance()->getAsync($path, [
231+
$promise = $this->httpClient->getAsync($path, [
219232
"query" => $query
220233
]);
221234

@@ -277,7 +290,7 @@ public function searchIdsAsync($ids, $language = null)
277290
$query["language"] = $language;
278291
}
279292

280-
$promise = HttpClient::getInstance()->getAsync($path, [
293+
$promise = $this->httpClient->getAsync($path, [
281294
"query" => $query
282295
]);
283296

src/Components/Endpoints/CreatorCodeEndpoint.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,29 @@
22

33
namespace FortniteApi\Components\Endpoints;
44

5-
use FortniteApi\Components\HttpClient;
65
use FortniteApi\Components\Tasks\CreatorCodeArrayTask;
76
use FortniteApi\Components\Tasks\CreatorCodeTask;
87
use FortniteApi\FortniteApiError;
98

9+
use GuzzleHttp\Client;
10+
1011
/**
1112
* Provides access to the /creatorcode endpoint.
1213
*/
1314
class CreatorCodeEndpoint
1415
{
16+
/**
17+
* Undocumented variable
18+
*
19+
* @var Client
20+
*/
21+
private $httpClient;
22+
23+
public function __construct($httpClient)
24+
{
25+
$this->httpClient = $httpClient;
26+
}
27+
1528
/**
1629
* Returns the creator code data for a given slug.
1730
*
@@ -51,7 +64,7 @@ public function getAsync($slug)
5164
"slug" => $slug
5265
];
5366

54-
$promise = HttpClient::getInstance()->getAsync($path, [
67+
$promise = $this->httpClient->getAsync($path, [
5568
"query" => $query
5669
]);
5770

@@ -97,7 +110,7 @@ public function searchAsync($slug)
97110
"slug" => $slug
98111
];
99112

100-
$promise = HttpClient::getInstance()->getAsync($path, [
113+
$promise = $this->httpClient->getAsync($path, [
101114
"query" => $query
102115
]);
103116

@@ -143,7 +156,7 @@ public function searchAllAsync($slug)
143156
"slug" => $slug
144157
];
145158

146-
$promise = HttpClient::getInstance()->getAsync($path, [
159+
$promise = $this->httpClient->getAsync($path, [
147160
"query" => $query
148161
]);
149162

src/Components/Endpoints/NewsEndpoint.php

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,30 @@
22

33
namespace FortniteApi\Components\Endpoints;
44

5-
use FortniteApi\Components\HttpClient;
65
use FortniteApi\Components\Tasks\NewsEntryTask;
76
use FortniteApi\Components\Tasks\NewsTask;
87
use FortniteApi\FortniteApi;
98
use FortniteApi\FortniteApiError;
109

10+
use GuzzleHttp\Client;
11+
1112
/**
1213
* Provides access to the /news/ endpoint.
1314
*/
1415
class NewsEndpoint
1516
{
17+
/**
18+
* Undocumented variable
19+
*
20+
* @var Client
21+
*/
22+
private $httpClient;
23+
24+
public function __construct($httpClient)
25+
{
26+
$this->httpClient = $httpClient;
27+
}
28+
1629
/**
1730
* Returns the data of the current battle royale, save the world and creative news.
1831
*
@@ -55,9 +68,9 @@ public function getAsync($language = null)
5568
}
5669

5770
if (count($query) == 0) {
58-
$promise = HttpClient::getInstance()->getAsync($path);
71+
$promise = $this->httpClient->getAsync($path);
5972
} else {
60-
$promise = HttpClient::getInstance()->getAsync($path, [
73+
$promise = $this->httpClient->getAsync($path, [
6174
"query" => $query
6275
]);
6376
}
@@ -168,9 +181,9 @@ private function internalGetAsync($section, $language = null)
168181
}
169182

170183
if (count($query) == 0) {
171-
$promise = HttpClient::getInstance()->getAsync($path);
184+
$promise = $this->httpClient->getAsync($path);
172185
} else {
173-
$promise = HttpClient::getInstance()->getAsync($path, [
186+
$promise = $this->httpClient->getAsync($path, [
174187
"query" => $query
175188
]);
176189
}

src/Components/Endpoints/ShopEndpoint.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,29 @@
22

33
namespace FortniteApi\Components\Endpoints;
44

5-
use FortniteApi\Components\HttpClient;
65
use FortniteApi\Components\Tasks\ShopTask;
76
use FortniteApi\FortniteApi;
87
use FortniteApi\FortniteApiError;
98

9+
use GuzzleHttp\Client;
10+
1011
/**
1112
* Provides access to the /shop/ endpoint.
1213
*/
1314
class ShopEndpoint
1415
{
16+
/**
17+
* Undocumented variable
18+
*
19+
* @var Client
20+
*/
21+
private $httpClient;
22+
23+
public function __construct($httpClient)
24+
{
25+
$this->httpClient = $httpClient;
26+
}
27+
1528
/**
1629
* Returns the current battle royale shop.
1730
*
@@ -54,9 +67,9 @@ public function getAsync($language = null)
5467
}
5568

5669
if (count($query) == 0) {
57-
$promise = HttpClient::getInstance()->getAsync($path);
70+
$promise = $this->httpClient->getAsync($path);
5871
} else {
59-
$promise = HttpClient::getInstance()->getAsync($path, [
72+
$promise = $this->httpClient->getAsync($path, [
6073
"query" => $query
6174
]);
6275
}

src/Components/HttpClient.php

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,8 @@
22

33
namespace FortniteApi\Components;
44

5-
use GuzzleHttp\Client;
6-
use FortniteApi\Config\Config;
7-
85
class HttpClient
96
{
10-
/**
11-
* Undocumented variable
12-
*
13-
* @var Client
14-
*/
15-
private static $_client;
16-
177
public static function isSuccess($statusCode)
188
{
199
if (empty($statusCode) || !is_int($statusCode)) {
@@ -22,18 +12,4 @@ public static function isSuccess($statusCode)
2212

2313
return $statusCode >= 200 && $statusCode < 400;
2414
}
25-
26-
/**
27-
* Undocumented function
28-
*
29-
* @return Client
30-
*/
31-
public static function getInstance()
32-
{
33-
if (empty(self::$_client)) {
34-
self::$_client = new Client(Config::getHttpClientConfig());
35-
}
36-
37-
return self::$_client;
38-
}
3915
}

src/Config/Config.php

Lines changed: 0 additions & 46 deletions
This file was deleted.

0 commit comments

Comments
 (0)