Skip to content

Replace snippet usernames with workspaces #45

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 2 commits into from
Jun 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Api/Snippets.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace Bitbucket\Api;

use Bitbucket\Api\Snippets\Users as SnippetsUsers;
use Bitbucket\Api\Snippets\Workspaces as SnippetsUsers;
use Bitbucket\HttpClient\Message\FileResource;
use Http\Message\MultipartStream\MultipartStreamBuilder;

Expand Down Expand Up @@ -57,7 +57,7 @@ public function create(FileResource $file)
/**
* @param string $username
*
* @return \Bitbucket\Api\Snippets\Users
* @return \Bitbucket\Api\Snippets\Workspaces
*/
public function users(string $username)
{
Expand Down
10 changes: 5 additions & 5 deletions src/Api/Snippets/AbstractSnippetsApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,21 @@
abstract class AbstractSnippetsApi extends AbstractApi
{
/**
* The username.
* The workspace.
*
* @var string
*/
protected $username;
protected $workspace;

/**
* Create a new api instance.
*
* @param \Http\Client\Common\HttpMethodsClientInterface $client
* @param string $username
* @param string $workspace
*/
public function __construct(HttpMethodsClientInterface $client, string $username)
public function __construct(HttpMethodsClientInterface $client, string $workspace)
{
parent::__construct($client);
$this->username = $username;
$this->workspace = $workspace;
}
}
64 changes: 32 additions & 32 deletions src/Api/Snippets/Users.php → src/Api/Snippets/Workspaces.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@

namespace Bitbucket\Api\Snippets;

use Bitbucket\Api\Snippets\Users\Comments;
use Bitbucket\Api\Snippets\Users\Commits;
use Bitbucket\Api\Snippets\Users\Diffs;
use Bitbucket\Api\Snippets\Users\Files;
use Bitbucket\Api\Snippets\Users\Patches;
use Bitbucket\Api\Snippets\Users\Watchers;
use Bitbucket\Api\Snippets\Users\Watching;
use Bitbucket\Api\Snippets\Workspaces\Comments;
use Bitbucket\Api\Snippets\Workspaces\Commits;
use Bitbucket\Api\Snippets\Workspaces\Diffs;
use Bitbucket\Api\Snippets\Workspaces\Files;
use Bitbucket\Api\Snippets\Workspaces\Patches;
use Bitbucket\Api\Snippets\Workspaces\Watchers;
use Bitbucket\Api\Snippets\Workspaces\Watching;
use Bitbucket\HttpClient\Message\FileResource;
use Http\Message\MultipartStream\MultipartStreamBuilder;

/**
* The users api class.
* The workspaces api class.
*
* @author Graham Campbell <[email protected]>
*/
class Users extends AbstractSnippetsApi
class Workspaces extends AbstractSnippetsApi
{
/**
* @param array $params
Expand All @@ -39,7 +39,7 @@ class Users extends AbstractSnippetsApi
*/
public function list(array $params = [])
{
$path = $this->buildUsersPath();
$path = $this->buildWorkspacesPath();

return $this->get($path, $params);
}
Expand All @@ -53,7 +53,7 @@ public function list(array $params = [])
*/
public function create(FileResource $file)
{
$path = $this->buildUsersPath();
$path = $this->buildWorkspacesPath();
$builder = (new MultipartStreamBuilder())->addResource($file->getName(), $file->getResource(), $file->getOptions());
$headers = ['Content-Type' => sprintf('multipart/form-data; boundary="%s"', $builder->getBoundary())];

Expand All @@ -70,7 +70,7 @@ public function create(FileResource $file)
*/
public function show(string $snippet, array $params = [])
{
$path = $this->buildUsersPath($snippet);
$path = $this->buildWorkspacesPath($snippet);

return $this->get($path, $params);
}
Expand All @@ -85,7 +85,7 @@ public function show(string $snippet, array $params = [])
*/
public function update(string $snippet, array $params = [])
{
$path = $this->buildUsersPath($snippet);
$path = $this->buildWorkspacesPath($snippet);

return $this->post($path, $params);
}
Expand All @@ -100,7 +100,7 @@ public function update(string $snippet, array $params = [])
*/
public function updateFiles(string $snippet, array $files)
{
$path = $this->buildUsersPath($snippet);
$path = $this->buildWorkspacesPath($snippet);

$builder = new MultipartStreamBuilder();

Expand All @@ -123,92 +123,92 @@ public function updateFiles(string $snippet, array $files)
*/
public function remove(string $snippet, array $params = [])
{
$path = $this->buildUsersPath($snippet);
$path = $this->buildWorkspacesPath($snippet);

return $this->delete($path, $params);
}

/**
* @param string $snippet
*
* @return \Bitbucket\Api\Snippets\Users\Comments
* @return \Bitbucket\Api\Snippets\Workspaces\Comments
*/
public function comments(string $snippet)
{
return new Comments($this->getHttpClient(), $this->username, $snippet);
return new Comments($this->getHttpClient(), $this->workspace, $snippet);
}

/**
* @param string $snippet
*
* @return \Bitbucket\Api\Snippets\Users\Commits
* @return \Bitbucket\Api\Snippets\Workspaces\Commits
*/
public function commits(string $snippet)
{
return new Commits($this->getHttpClient(), $this->username, $snippet);
return new Commits($this->getHttpClient(), $this->workspace, $snippet);
}

/**
* @param string $snippet
*
* @return \Bitbucket\Api\Snippets\Users\Diffs
* @return \Bitbucket\Api\Snippets\Workspaces\Diffs
*/
public function diffs(string $snippet)
{
return new Diffs($this->getHttpClient(), $this->username, $snippet);
return new Diffs($this->getHttpClient(), $this->workspace, $snippet);
}

/**
* @param string $snippet
*
* @return \Bitbucket\Api\Snippets\Users\Files
* @return \Bitbucket\Api\Snippets\Workspaces\Files
*/
public function files(string $snippet)
{
return new Files($this->getHttpClient(), $this->username, $snippet);
return new Files($this->getHttpClient(), $this->workspace, $snippet);
}

/**
* @param string $snippet
*
* @return \Bitbucket\Api\Snippets\Users\Patches
* @return \Bitbucket\Api\Snippets\Workspaces\Patches
*/
public function patches(string $snippet)
{
return new Patches($this->getHttpClient(), $this->username, $snippet);
return new Patches($this->getHttpClient(), $this->workspace, $snippet);
}

/**
* @param string $snippet
*
* @return \Bitbucket\Api\Snippets\Users\Watchers
* @return \Bitbucket\Api\Snippets\Workspaces\Watchers
*/
public function watchers(string $snippet)
{
return new Watchers($this->getHttpClient(), $this->username, $snippet);
return new Watchers($this->getHttpClient(), $this->workspace, $snippet);
}

/**
* @param string $snippet
*
* @return \Bitbucket\Api\Snippets\Users\Watching
* @return \Bitbucket\Api\Snippets\Workspaces\Watching
*/
public function watching(string $snippet)
{
return new Watching($this->getHttpClient(), $this->username, $snippet);
return new Watching($this->getHttpClient(), $this->workspace, $snippet);
}

/**
* Build the users path from the given parts.
* Build the workspaces path from the given parts.
*
* @param string[] $parts
*
* @throws \Bitbucket\Exception\InvalidArgumentException
*
* @return string
*/
protected function buildUsersPath(string ...$parts)
protected function buildWorkspacesPath(string ...$parts)
{
return static::buildPath('snippets', $this->username, ...$parts);
return static::buildPath('snippets', $this->workspace, ...$parts);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@
* file that was distributed with this source code.
*/

namespace Bitbucket\Api\Snippets\Users;
namespace Bitbucket\Api\Snippets\Workspaces;

use Bitbucket\Api\Snippets\AbstractSnippetsApi;
use Http\Client\Common\HttpMethodsClientInterface;

/**
* The abstract users api class.
* The abstract workspaces api class.
*
* @author Graham Campbell <[email protected]>
*/
abstract class AbstractUsersApi extends AbstractSnippetsApi
abstract class AbstractWorkspacesApi extends AbstractSnippetsApi
{
/**
* The snippet.
Expand All @@ -34,12 +34,12 @@ abstract class AbstractUsersApi extends AbstractSnippetsApi
* Create a new api instance.
*
* @param \Http\Client\Common\HttpMethodsClientInterface $client
* @param string $username
* @param string $workspace
* @param string $snippet
*/
public function __construct(HttpMethodsClientInterface $client, string $username, string $snippet)
public function __construct(HttpMethodsClientInterface $client, string $workspace, string $snippet)
{
parent::__construct($client, $username);
parent::__construct($client, $workspace);
$this->snippet = $snippet;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
* file that was distributed with this source code.
*/

namespace Bitbucket\Api\Snippets\Users;
namespace Bitbucket\Api\Snippets\Workspaces;

/**
* The comments api class.
*
* @author Graham Campbell <[email protected]>
*/
class Comments extends AbstractUsersApi
class Comments extends AbstractWorkspacesApi
{
/**
* @param array $params
Expand Down Expand Up @@ -104,6 +104,6 @@ public function remove(string $comment, array $params = [])
*/
protected function buildCommentsPath(string ...$parts)
{
return static::buildPath('snippets', $this->username, $this->snippet, 'comments', ...$parts);
return static::buildPath('snippets', $this->workspace, $this->snippet, 'comments', ...$parts);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
* file that was distributed with this source code.
*/

namespace Bitbucket\Api\Snippets\Users;
namespace Bitbucket\Api\Snippets\Workspaces;

/**
* The commits api class.
*
* @author Graham Campbell <[email protected]>
*/
class Commits extends AbstractUsersApi
class Commits extends AbstractWorkspacesApi
{
/**
* @param array $params
Expand Down Expand Up @@ -60,6 +60,6 @@ public function show(string $commit, array $params = [])
*/
protected function buildCommitsPath(string ...$parts)
{
return static::buildPath('snippets', $this->username, $this->snippet, 'commits', ...$parts);
return static::buildPath('snippets', $this->workspace, $this->snippet, 'commits', ...$parts);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
* file that was distributed with this source code.
*/

namespace Bitbucket\Api\Snippets\Users;
namespace Bitbucket\Api\Snippets\Workspaces;

/**
* The diffs api class.
*
* @author Graham Campbell <[email protected]>
*/
class Diffs extends AbstractUsersApi
class Diffs extends AbstractWorkspacesApi
{
/**
* @param string $commit
Expand Down Expand Up @@ -46,6 +46,6 @@ public function download(string $commit, array $params = [])
*/
protected function buildDiffsPath(string ...$parts)
{
return static::buildPath('snippets', $this->username, $this->snippet, ...$parts);
return static::buildPath('snippets', $this->workspace, $this->snippet, ...$parts);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* file that was distributed with this source code.
*/

namespace Bitbucket\Api\Snippets\Users;
namespace Bitbucket\Api\Snippets\Workspaces;

use Http\Message\MultipartStream\MultipartStreamBuilder;

Expand All @@ -20,7 +20,7 @@
*
* @author Graham Campbell <[email protected]>
*/
class Files extends AbstractUsersApi
class Files extends AbstractWorkspacesApi
{
/**
* @param string $commit
Expand Down Expand Up @@ -117,6 +117,6 @@ public function remove(string $commit, array $params = [])
*/
protected function buildFilesPath(string ...$parts)
{
return static::buildPath('snippets', $this->username, $this->snippet, ...$parts);
return static::buildPath('snippets', $this->workspace, $this->snippet, ...$parts);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
* file that was distributed with this source code.
*/

namespace Bitbucket\Api\Snippets\Users;
namespace Bitbucket\Api\Snippets\Workspaces;

/**
* The patches api class.
*
* @author Graham Campbell <[email protected]>
*/
class Patches extends AbstractUsersApi
class Patches extends AbstractWorkspacesApi
{
/**
* @param string $commit
Expand Down Expand Up @@ -46,6 +46,6 @@ public function download(string $commit, array $params = [])
*/
protected function buildPatchesPath(string ...$parts)
{
return static::buildPath('snippets', $this->username, $this->snippet, ...$parts);
return static::buildPath('snippets', $this->workspace, $this->snippet, ...$parts);
}
}
Loading