Skip to content

Commit e1d178e

Browse files
committed
Create WS URL method
1 parent ecdbf95 commit e1d178e

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/ApiSettings.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
final class ApiSettings
88
{
99
/**
10+
* Create Pusher compatible version
11+
*
1012
* @param string $version
1113
* @return string
1214
*/
@@ -24,4 +26,24 @@ public static function getVersion(string $version = ''): string
2426

2527
return $version;
2628
}
29+
30+
/**
31+
* Create WebSocket URL for given App ID
32+
*
33+
* @param string $appId
34+
* @return string
35+
*/
36+
public static function createUrl(string $appId): string
37+
{
38+
$query = [
39+
'client' => 'api-clients/pusher (https://php-api-clients.org/clients/pusher)',
40+
'protocol' => 7,
41+
'version' => ApiSettings::getVersion(),
42+
];
43+
44+
return 'wss://ws.pusherapp.com/app/' .
45+
$appId .
46+
'?' . http_build_query($query)
47+
;
48+
}
2749
}

tests/ApiSettingsTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,11 @@ public function testGetVersionDefault()
3333
{
3434
$this->assertTrue(strlen(ApiSettings::getVersion()) > 0);
3535
}
36+
37+
public function testCreateUrl()
38+
{
39+
$expectedUrl = 'wss://ws.pusherapp.com/app/barBaz?client=api-clients%2Fpusher+%28https%3A%2F%2Fphp-api-clients.org%2Fclients%2Fpusher%29&protocol=7&version=' . ApiSettings::getVersion();
40+
41+
$this->assertSame($expectedUrl, ApiSettings::createUrl('barBaz'));
42+
}
3643
}

0 commit comments

Comments
 (0)