File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change 7
7
final class ApiSettings
8
8
{
9
9
/**
10
+ * Create Pusher compatible version
11
+ *
10
12
* @param string $version
11
13
* @return string
12
14
*/
@@ -24,4 +26,24 @@ public static function getVersion(string $version = ''): string
24
26
25
27
return $ version ;
26
28
}
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
+ }
27
49
}
Original file line number Diff line number Diff line change @@ -33,4 +33,11 @@ public function testGetVersionDefault()
33
33
{
34
34
$ this ->assertTrue (strlen (ApiSettings::getVersion ()) > 0 );
35
35
}
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
+ }
36
43
}
You can’t perform that action at this time.
0 commit comments