Skip to content

Commit d3f6769

Browse files
authored
Merge pull request #21 from WebDecoy/chore/cleanup-hygiene
chore: SDK User-Agent hygiene (#1)
2 parents 8b98580 + 9b1cb21 commit d3f6769

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

‎sdk/src/Client.php‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,17 @@ class Client
1717
private const DEFAULT_BASE_URL = 'https://api.webdecoy.com';
1818
private const DEFAULT_INGEST_URL = 'https://ingest.webdecoy.com';
1919
private const DEFAULT_TIMEOUT = 10;
20-
private const USER_AGENT = 'WebDecoy-PHP-SDK/1.0';
20+
21+
/**
22+
* Build the User-Agent string. Derives the version from the bundling
23+
* plugin's WEBDECOY_VERSION constant when present so it never goes stale;
24+
* falls back to a generic marker for standalone SDK use.
25+
*/
26+
private static function userAgent(): string
27+
{
28+
$version = defined('WEBDECOY_VERSION') ? WEBDECOY_VERSION : '2.x';
29+
return 'WebDecoy-PHP-SDK/' . $version;
30+
}
2131

2232
private string $apiKey;
2333
private string $baseUrl;
@@ -363,7 +373,7 @@ private function requestWithWordPress(string $method, string $url, array $data,
363373
$headers = [
364374
'Content-Type' => 'application/json',
365375
'Accept' => 'application/json',
366-
'User-Agent' => self::USER_AGENT,
376+
'User-Agent' => self::userAgent(),
367377
];
368378

369379
if ($authenticated) {
@@ -414,7 +424,7 @@ private function requestWithCurl(string $method, string $url, array $data, bool
414424
$headers = [
415425
'Content-Type: application/json',
416426
'Accept: application/json',
417-
'User-Agent: ' . self::USER_AGENT,
427+
'User-Agent: ' . self::userAgent(),
418428
];
419429

420430
if ($authenticated) {

0 commit comments

Comments
 (0)