PHP code example of swe / space-sdk

1. Go to this page and download the library: Download swe/space-sdk library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

swe / space-sdk example snippets


final class Blog extends AbstractApi
{
    /**
     * Permissions that may be checked: Article.View
     *
     * @param array $request
     * @param array $response
     * @return array
     * @throws GuzzleException
     */
    final public function getAllBlogPosts(array $request = [], array $response = []): array
    {
        $uri = 'blog';

        return $this->client->get($this->buildUrl($uri), $request, $response);
    }
}

use Swe\SpaceSDK\HttpClient;
use Swe\SpaceSDK\Space;

$clientId = 'Your Client ID Here';
$clientSecret = 'Your Client Secret Here';
$url = 'Your Space URL';

$space = new Space(new HttpClient($url, $clientId, $clientSecret));

// Let's create a project.
$projectInformation = $space->projects()->createProject([
    'key' => [
        'key' => 'MY_PROJECT',
    ],
    'name' => 'My Project',
]);

// Create a new channel if not exist.
if ($space->chats()->channels()->isNameFree(['name' => 'General'])) {
    $channel = $space->chats()->channels()->addNewChannel([
        'name' => 'General',
        'description' => 'No specific topic..',
        'private' => false,
    ]);
}