Skip to content

Commit 6309cc5

Browse files
committed
Add option to set environment in client.
1 parent d17e1d1 commit 6309cc5

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/XIVAPI/Guzzle/Guzzle.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88

99
class Guzzle
1010
{
11-
const ENDPOINT_PROD = 'https://xivapi.com';
12-
const ENDPOINT_DEV = 'https://xivapi.local';
1311
const TIMEOUT = 10.0;
1412
const VERIFY = false;
1513

1614
/** @var Client */
1715
private static $client = null;
1816
/** @var bool */
1917
private static $async = false;
18+
/** @var string */
19+
private static $environment = null;
2020
/** @var array */
2121
private static $options = [];
2222

@@ -27,12 +27,17 @@ private static function setClient()
2727
{
2828
if (self::$client === null) {
2929
self::$client = new Client([
30-
'base_uri' => self::ENDPOINT_PROD,
30+
'base_uri' => self::$environment,
3131
'timeout' => self::TIMEOUT,
3232
'verify' => self::VERIFY,
3333
]);
3434
}
3535
}
36+
37+
public static function setEnvironment(string $environment): void
38+
{
39+
self::$environment = $environment;
40+
}
3641

3742
public static function query($method, $apiEndpoint, $options = [])
3843
{

src/XIVAPI/XIVAPI.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717

1818
class XIVAPI
1919
{
20+
const PROD = 'https://xivapi.com';
21+
const STAGING = 'https://staging.xivapi.com';
22+
const DEV = 'https://xivapi.local';
23+
2024
/** @var Environment */
2125
public $environment;
2226
/** @var Search */
@@ -38,8 +42,11 @@ class XIVAPI
3842
/** @var PatchList */
3943
public $patchlist;
4044

41-
public function __construct()
45+
public function __construct(string $environment = self::PROD)
4246
{
47+
// set environment to use
48+
Guzzle::setEnvironment($environment);
49+
4350
$this->environment = new Environment();
4451
$this->search = new Search();
4552
$this->content = new Content();

0 commit comments

Comments
 (0)