-
Notifications
You must be signed in to change notification settings - Fork 90
Add missing code snippets for documentation #125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a0fa4e8
Add new batch of code snippets from documentation
jakub-grzesiowski 37a8144
Remove faulty test declaration
jakub-grzesiowski b353dd6
Test remove subscribing snippets test file
jakub-grzesiowski 51a8479
Fixes for failing tests
jakub-grzesiowski 5dc37ab
More test fixes
jakub-grzesiowski 23787bc
Even more test fixes
jakub-grzesiowski 52dcc05
Cryptor setup snippet fix
jakub-grzesiowski 1c5a2e0
Linter fixes
jakub-grzesiowski bb1defb
Edit ParseToken snippet
jakub-grzesiowski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| <?php | ||
|
|
||
| require_once(__DIR__ . '/../vendor/autoload.php'); | ||
|
|
||
| use PubNub\PubNub; | ||
| use PubNub\PNConfiguration; | ||
|
|
||
| // snippet.setup | ||
| $config = new PNConfiguration(); | ||
| $config->setSecretKey(getenv('SECRET_KEY') ?: 'demo'); | ||
| $config->setPublishKey(getenv('PUBLISH_KEY') ?: 'demo'); | ||
| $config->setSubscribeKey(getenv('SUBSCRIBE_KEY') ?: 'demo'); | ||
| $config->setUserId('example'); | ||
|
|
||
| $pubnub = new PubNub($config); | ||
| // snippet.end | ||
|
|
||
| // snippet.grant_channel_authkey | ||
| $channels = ["ch1", "ch2"]; | ||
| $auth_key = "blah"; | ||
| $read = true; | ||
| $write = false; | ||
| $ttl_mins = 15; | ||
| try { | ||
| $result = $pubnub->grant() | ||
| ->channels($channels) | ||
| ->authKeys($auth_key) | ||
| ->read($read) | ||
| ->write($write) | ||
| ->ttl($ttl_mins) | ||
| ->sync(); | ||
| print("Grant successful\n"); | ||
| } catch (\PubNub\Exceptions\PubNubServerException $exception) { | ||
| print_r("Message: " . $exception->getMessage() . "\n"); | ||
| print_r("Status: " . $exception->getStatusCode() . "\n"); | ||
| echo "Original message: "; | ||
| print_r($exception->getBody()); | ||
| } catch (\PubNub\Exceptions\PubNubException $exception) { | ||
| print_r("Message: " . $exception->getMessage()); | ||
| } | ||
| // snippet.end | ||
|
|
||
| // snippet.grant_all_channels | ||
| $pubnub->grant() | ||
| ->read(true) | ||
| ->write(true) | ||
| ->sync(); | ||
| // snippet.end | ||
|
|
||
| // snippet.grant_specific_channel | ||
| $pubnub->grant() | ||
| ->channels("my_channel") | ||
| ->read(true) | ||
| ->write(true) | ||
| ->sync(); | ||
| // snippet.end | ||
|
|
||
| // snippet.grant_channel_with_authkey | ||
| $pubnub->grant() | ||
| ->channels("my_channel") | ||
| ->read(true) | ||
| ->write(false) | ||
| ->authKeys("my_ro_authkey") | ||
| ->ttl(5) | ||
| ->sync(); | ||
| // snippet.end | ||
|
|
||
| // snippet.grant_presence_channel | ||
| $pubnub->grant() | ||
| ->channels("my_channel-pnpres") | ||
| ->read(true) | ||
| ->write(true) | ||
| ->sync(); | ||
| // snippet.end | ||
|
|
||
| // snippet.grant_channel_group | ||
| $result = $pubnub->grant() | ||
| ->channelGroups(["cg1", "cg2", "cg3"]) | ||
| ->authKeys(["key1", "key2", "auth3"]) | ||
| ->read(true) | ||
| ->write(true) | ||
| ->manage(true) | ||
| ->ttl(12237) | ||
| ->sync(); | ||
| // snippet.end | ||
|
|
||
| // snippet.grant_application_level | ||
| try { | ||
| $result = $pubnub->grant() | ||
| ->read(true) | ||
| ->write(true) | ||
| ->sync(); | ||
|
|
||
| print_r($result); | ||
| } catch (\PubNub\Exceptions\PubNubServerException $exception) { | ||
| print_r($exception->getMessage() . "\n"); | ||
| print_r($exception->getStatusCode() . "\n"); | ||
| print_r($exception->getBody()); | ||
| } catch (\PubNub\Exceptions\PubNubException $exception) { | ||
| print_r($exception->getMessage()); | ||
| } | ||
| // snippet.end | ||
|
|
||
| // snippet.grant_channel_level | ||
| $result = $pubnub->grant() | ||
| ->channels("my_channel") | ||
| ->read(true) | ||
| ->write(true) | ||
| ->sync(); | ||
| // snippet.end | ||
|
|
||
| // snippet.grant_user_level | ||
| $result = $pubnub->grant() | ||
| ->channels("my_channel") | ||
| ->authKeys("my_authkey") | ||
| ->read(true) | ||
| ->write(true) | ||
| ->ttl(5) | ||
| ->sync(); | ||
| // snippet.end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| <?php | ||
|
|
||
| require_once(__DIR__ . '/../vendor/autoload.php'); | ||
|
|
||
| use PubNub\PNConfiguration; | ||
| use PubNub\PubNub; | ||
| use PubNub\Exceptions\PubNubServerException; | ||
|
|
||
| // snippet.setup | ||
| // Create configuration | ||
| $pnConfig = new PNConfiguration(); | ||
| $pnConfig->setSubscribeKey(getenv("SUBSCRIBE_KEY") ?? "demo"); | ||
| $pnConfig->setPublishKey(getenv("PUBLISH_KEY") ?? "demo"); | ||
| $pnConfig->setUserId("php-channel-group-demo"); | ||
|
|
||
| // Initialize PubNub instance | ||
| $pubnub = new PubNub($pnConfig); | ||
| // snippet.end | ||
|
|
||
| // snippet.add_channels | ||
| $result = $pubnub->addChannelToChannelGroup() | ||
| ->channels(["news", "sports"]) | ||
| ->channelGroup("my-group") | ||
| ->sync(); | ||
|
|
||
| echo "Channels added to group successfully!" . PHP_EOL; | ||
| // snippet.end | ||
|
|
||
| // snippet.list_channels | ||
| $result = $pubnub->listChannelsInChannelGroup() | ||
| ->channelGroup("cg1") | ||
| ->sync(); | ||
| // snippet.end | ||
|
|
||
| // snippet.remove_channels | ||
| $pubnub->removeChannelFromChannelGroup() | ||
| ->channels("son") | ||
| ->channelGroup("family") | ||
| ->sync(); | ||
| // snippet.end | ||
|
|
||
| // snippet.delete_channel_group | ||
| $pubnub->removeChannelGroup() | ||
| ->channelGroup("family") | ||
| ->sync(); | ||
| // snippet.end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.