Skip to content

Commit c21ecf0

Browse files
author
Steve Kirkland
committed
Set default endpoints based on API key
1 parent fcb1ece commit c21ecf0

1 file changed

Lines changed: 43 additions & 7 deletions

File tree

src/Configuration.php

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,35 @@
88
class Configuration implements FeatureDataStore
99
{
1010
/**
11-
* The default endpoint for event notifications.
11+
* The default endpoint for event notifications with Bugsnag.
1212
*/
1313
const NOTIFY_ENDPOINT = 'https://notify.bugsnag.com';
1414

1515
/**
16-
* The default endpoint for session tracking.
16+
* The default endpoint for session tracking with Bugsnag.
1717
*/
1818
const SESSION_ENDPOINT = 'https://sessions.bugsnag.com';
1919

2020
/**
21-
* The default endpoint for build notifications.
21+
* The default endpoint for build notifications with Bugsnag.
2222
*/
2323
const BUILD_ENDPOINT = 'https://build.bugsnag.com';
2424

25+
/**
26+
* The default endpoint for event notifications with InsightHub.
27+
*/
28+
const HUB_NOTIFY_ENDPOINT = 'https://notify.insighthub.smartbear.com';
29+
30+
/**
31+
* The default endpoint for session tracking with InsightHub.
32+
*/
33+
const HUB_SESSION_ENDPOINT = 'https://sessions.insighthub.smartbear.com';
34+
35+
/**
36+
* The default endpoint for build notifications with InsightHub.
37+
*/
38+
const HUB_BUILD_ENDPOINT = 'https://build.insighthub.smartbear.com';
39+
2540
/**
2641
* @var string
2742
*/
@@ -150,17 +165,17 @@ class Configuration implements FeatureDataStore
150165
/**
151166
* @var string
152167
*/
153-
protected $notifyEndpoint = self::NOTIFY_ENDPOINT;
168+
protected $notifyEndpoint;
154169

155170
/**
156171
* @var string
157172
*/
158-
protected $sessionEndpoint = self::SESSION_ENDPOINT;
173+
protected $sessionEndpoint;
159174

160175
/**
161176
* @var string
162177
*/
163-
protected $buildEndpoint = self::BUILD_ENDPOINT;
178+
protected $buildEndpoint;
164179

165180
/**
166181
* The amount to increase the memory_limit to handle an OOM.
@@ -201,15 +216,36 @@ public function __construct($apiKey)
201216
if (!is_string($apiKey)) {
202217
throw new InvalidArgumentException('Invalid API key');
203218
}
204-
205219
$this->apiKey = $apiKey;
220+
221+
if ($this->isHubApiKey()) {
222+
$this->notifyEndpoint = self::HUB_NOTIFY_ENDPOINT;
223+
$this->sessionEndpoint = self::HUB_SESSION_ENDPOINT;
224+
$this->buildEndpoint = self::HUB_BUILD_ENDPOINT;
225+
} else {
226+
$this->notifyEndpoint = self::NOTIFY_ENDPOINT;
227+
$this->sessionEndpoint = self::SESSION_ENDPOINT;
228+
$this->buildEndpoint = self::BUILD_ENDPOINT;
229+
}
230+
206231
$this->fallbackType = php_sapi_name();
207232
$this->featureFlags = new FeatureFlagDelegate();
208233

209234
// Add PHP runtime version to device data
210235
$this->mergeDeviceData(['runtimeVersions' => ['php' => phpversion()]]);
211236
}
212237

238+
/**
239+
* Checks if the API Key is associated with the InsightHub instance.
240+
*
241+
* @return bool
242+
*/
243+
public function isHubApiKey()
244+
{
245+
// Does the API key start with 00000
246+
return strpos($this->apiKey, '00000') === 0;
247+
}
248+
213249
/**
214250
* Get the Bugsnag API Key.
215251
*

0 commit comments

Comments
 (0)