Buddy Works APIs PHP SDK
, (*1)
Official PHP client library for Buddy Build Server with CI., (*2)
Installation
This library is distributed on packagist and is working with composer. In order to add it as a dependency, run the following command:, (*3)
``` sh
composer require buddy-works/buddy-works-php-api, (*4)
### Compatibility
| PHP version | SDK version |
| --------------- | ---------------------- |
| ^8.0 | 1.4 |
| ^7.3 | 1.3 |
| ^7.2 | 1.2 |
| 5.5 | 1.1 |
## Usage of OAUTH
First you need to add application in your [Buddy ID](https://app.buddy.works/my-apps).
You will then obtain clientId & clientSecret to execute this code:
```php
$buddy = new Buddy\Buddy([
'clientId' => 'your-client-id',
'clientSecret' => 'your-client-secret'
]);
try {
$url = $buddy->getOAuth()->getAuthorizeUrl([
Buddy\BuddyOAuth::SCOPE_MANAGE_EMAILS
], 'state', 'redirectUrl');
} catch(Buddy\Exceptions\BuddySDKException $e) {
echo 'Buddy SDK return an error: ' . $e->getMessage();
exit;
}
scopes are arrays of strings - help, (*5)
state should be an unguessable random string. It is used to protect against cross-site request forgery attacks., (*6)
redirectUrl is optional more, (*7)
You should redirect the user to the created URL. Upon authorization, the user should get back to your page (configured in application or passed to the method), (*8)
query params will get you the code & state. State should be the same as you passed before. Code is used in next step to exchange for access token:, (*9)
$buddy = new Buddy\Buddy([
'clientId' => 'your-client-id',
'clientSecret' => 'your-client-secret'
]);
try {
$auth = $buddy->getOAuth()->getAccessToken('state');
} catch(Buddy\Exceptions\BuddyResponseException $e) {
echo 'Buddy API return an error: ' . $e->getMessage();
exit;
} catch(Buddy\Exceptions\BuddySDKException $e) {
echo 'Buddy SDK return an error: ' . $e->getMessage();
exit;
}
var_dump($auth);
State should be the same as in getAuthorizeUrl method., (*10)
Usage of direct tokens
You can also use API Tokens., (*11)
That functionality is provided for testing purposes and will only work for individual tokens generated per user., (*12)
All requests will be called on behalf of the user who provided token., (*13)
API's
For detailed info what send for which method, error codes, rates & limits - check Buddy documentation, (*14)
To start using api you should pass to Buddy constructor acquired access token., (*15)
$buddy = new Buddy\Buddy([
'accessToken' => 'your access token'
]);
Workspaces
Get workspaces, (*16)
try {
$resp = $buddy->getApiWorkspaces()->getWorkspaces([$accessToken]);
var_dump($resp);
exit;
} catch (Buddy\Exceptions\BuddyResponseException $e) {
echo $e->getMessage();
exit;
} catch (Buddy\Exceptions\BuddySDKException $e) {
echo $e->getMessage();
exit;
}
Get workspace, (*17)
$buddy->getApiWorkspaces()->getWorkspace($domain, [$accessToken]);
Webhooks
Get webhooks, (*18)
$buddy->getApiWebhooks()->getWebhooks($domain, [$accessToken]);
Add webhook, (*19)
$buddy->getApiWebhooks()->addWebhook($data, $domain, [$accessToken]);
Get webhook, (*20)
$buddy->getApiWebhooks()->getWebhook($domain, $webhookId, [$accessToken]);
Edit webhook, (*21)
$buddy->getApiWebhooks()->editWebhook($data, $domain, $webhookId, [$accessToken]);
Delete webhook, (*22)
$buddy->getApiWebhooks()->deleteWebhook($domain, $webhookId, [$accessToken]);
Get tags, (*23)
$buddy->getApiTags()->getTags($domain, $projectName, [$accessToken]);
Get tag, (*24)
$buddy->getApiTags()->getTag($domain, $projectName, $name, [$accessToken]);
Ssh Keys
Get keys, (*25)
$buddy->getApiSshKeys()->getKeys([$accessToken]);
Add key, (*26)
$buddy->getApiSshKeys()->addKey($data, [$accessToken]);
Delete key, (*27)
$buddy->getApiSshKeys()->deleteKey($keyId, [$accessToken]);
Get key, (*28)
$buddy->getApiSshKeys()->getKey($keyId, [$accessToken]);
Source
Get contents, (*29)
$buddy->getApiSource()->getContents($domain, $projectName, [$path], [$filters], [$accessToken]);
Add file, (*30)
$buddy->getApiSource()->addFile($data, $domain, $projectName, [$accessToken]);
Edit file, (*31)
$buddy->getApiSource()->editFile($data, $domain, $projectName, $path, [$accessToken]);
Delete file, (*32)
$buddy->getApiSource()->deleteFile($data, $domain, $projectName, $path, [$accessToken]);
Projects
Get projects, (*33)
$buddy->getApiProjects()->getProjects($domain, [$filters], [$accessToken]);
Add project, (*34)
$buddy->getApiProjects()->addProject($data, $domain, [$accessToken]);
Get projects, (*35)
$buddy->getApiProjects()->getProject($domain, $projectName, [$accessToken]);
Edit project, (*36)
$buddy->getApiProjects()->editProject($data, $domain, $projectName, [$accessToken]);
Delete project, (*37)
$buddy->getApiProjects()->deleteProject($domain, $projectName, [$accessToken]);
Get project members, (*38)
$buddy->getApiProjects()->getProjectMembers($domain, $projectName, [$filters], [$accessToken]);
Add project member, (*39)
$buddy->getApiProjects()->addProjectMember($domain, $projectName, $userId, $permissionId, [$accessToken]);
Get project member, (*40)
$buddy->getApiProjects()->getProjectMember($domain, $projectName, $userId, [$accessToken]);
Edit project member, (*41)
$buddy->getApiProjects()->editProjectMember($domain, $projectName, $userId, $permissionId, [$accessToken]);
Delete project member, (*42)
$buddy->getApiProjects()->deleteProjectMember($domain, $projectName, $userId, [$accessToken]);
Profile
Get user, (*43)
$buddy->getApiProfile()->getAuthenticatedUser([$accessToken]);
Edit user, (*44)
$buddy->getApiProfile()->editAuthenticatedUser($data, [$accessToken]);
Pipelines
Get pipelines, (*45)
$buddy->getApiPipelines()->getPipelines($domain, $projectName, [$filters], [$accessToken]);
Add pipeline, (*46)
$buddy->getApiPipelines()->addPipeline($data, $domain, $projectName, [$accessToken]);
Get pipeline, (*47)
$buddy->getApiPipelines()->getPipeline($domain, $projectName, $pipelineId, [$accessToken]);
Edit pipeline, (*48)
$buddy->getApiPipelines()->editPipeline($data, $domain, $projectName, $pipelineId, [$accessToken]);
Delete pipeline, (*49)
$buddy->getApiPipelines()->deletePipeline($domain, $projectName, $pipelineId, [$accessToken]);
Get pipeline actions, (*50)
$buddy->getApiPipelines()->getPipelineActions($domain, $projectName, $pipelineId, [$accessToken]);
Add pipeline action, (*51)
$buddy->getApiPipelines()->addPipelineAction($data, $domain, $projectName, $pipelineId, [$accessToken]);
Get pipeline action, (*52)
$buddy->getApiPipelines()->getPipelineAction($domain, $projectName, $pipelineId, $actionId, [$accessToken]);
Edit pipeline action, (*53)
$buddy->getApiPipelines()->editPipelineAction($data, $domain, $projectName, $pipelineId, $actionId, [$accessToken]);
Delete pipeline action, (*54)
$buddy->getApiPipelines()->deletePipelineAction($domain, $projectName, $pipelineId, $actionId, [$accessToken]);
Permissions
Get permissions, (*55)
$buddy->getApiPermissions()->getWorkspacePermissions($domain, [$accessToken]);
Add permission, (*56)
$buddy->getApiPermissions()->addWorkspacePermission($data, $domain, [$accessToken]);
Get permission, (*57)
$buddy->getApiPermissions()->getWorkspacePermission($domain, $permissionId, [$accessToken]);
Edit permission, (*58)
$buddy->getApiPermissions()->editWorkspacePermission($data, $domain, $permissionId, [$accessToken]);
Delete permission, (*59)
$buddy->getApiPermissions()->deleteWorkspacePermission($domain, $permissionId, [$accessToken]);
Members
Get members, (*60)
$buddy->getApiMembers()->getWorkspaceMembers($domain, [$filters], [$accessToken]);
Add member, (*61)
$buddy->getApiMembers()->addWorkspaceMember($domain, $email, [$accessToken]);
Get member, (*62)
$buddy->getApiMembers()->getWorkspaceMember($domain, $userId, [$accessToken]);
Edit member, (*63)
$buddy->getApiMembers()->editWorkspaceMember($domain, $userId, $isAdmin, [$accessToken]);
Delete member, (*64)
$buddy->getApiMembers()->deleteWorkspaceMember($domain, $userId, [$accessToken]);
Get member projects, (*65)
$buddy->getApiMembers()->getWorkspaceMemberProjects($domain, $userId, [$filters], [$accessToken]);
Integrations
Get integrations, (*66)
$buddy->getApiIntegrations()->getIntegrations([$accessToken]);
Get integration, (*67)
$buddy->getApiIntegrations()->getIntegration($integrationId, [$accessToken]);
Groups
Get groups, (*68)
$buddy->getApiGroups()->getGroups($domain, [$accessToken]);
Add group, (*69)
$buddy->getApiGroups()->addGroup($data, $domain, [$accessToken]);
Get group, (*70)
$buddy->getApiGroups()->getGroup($domain, $groupId, [$accessToken]);
Edit group, (*71)
$buddy->getApiGroups()->editGroup($data, $domain, $groupId, [$accessToken]);
Delete group, (*72)
$buddy->getApiGroups()->deleteGroup($domain, $groupId, [$accessToken]);
Get group members, (*73)
$buddy->getApiGroups()->getGroupMembers($domain, $groupId, [$accessToken]);
Add group member, (*74)
$buddy->getApiGroups()->addGroupMember($domain, $groupId, $userId, [$accessToken]);
Get group member, (*75)
$buddy->getApiGroups()->getGroupMember($domain, $groupId, $userId, [$accessToken]);
Delete group member, (*76)
$buddy->getApiGroups()->deleteGroupMember($domain, $groupId, $userId, [$accessToken]);
Executions
Get executions, (*77)
$buddy->getApiExecutions()->getExecutions($domain, $projectName, $pipelineId, [$filters], [$accessToken]);
Run execution, (*78)
$buddy->getApiExecutions()->runExecution($data, $domain, $projectName, $pipelineId, [$accessToken]);
Get execution, (*79)
$buddy->getApiExecutions()->getExecution($domain, $projectName, $pipelineId, $executionId, [$accessToken]);
Cancel execution, (*80)
$buddy->getApiExecutions()->cancelExecution($domain, $projectName, $pipelineId, $executionId, [$accessToken]);
Retry execution, (*81)
$buddy->getApiExecutions()->retryRelease($domain, $projectName, $pipelineId, $executionId, [$accessToken]);
Emails
Get emails, (*82)
$buddy->getApiEmails()->getAuthenticatedUserEmails([$accessToken]);
Add email, (*83)
$buddy->getApiEmails()->addAuthenticatedUserEmail($email, [$accessToken]);
Delete email, (*84)
$buddy->getApiEmails()->deleteAuthenticatedUserEmail($email, [$accessToken]);
Commits
Get commits, (*85)
$buddy->getApiCommits()->getCommits($domain, $projectName, [$filters], [$accessToken]);
Get commit, (*86)
$buddy->getApiCommits()->getCommit($domain, $projectName, $revision, [$accessToken]);
Compare commits, (*87)
$buddy->getApiCommits()->getCompare($domain, $projectName, $base, $head, [$filters], [$accessToken]);
Branches
Get branches, (*88)
$buddy->getApiBranches()->getBranches($domain, $projectName, [$accessToken]);
Get branch, (*89)
$buddy->getApiBranches()->getBranch($domain, $projectName, $name, [$accessToken]);
Add branch, (*90)
$buddy->getApiBranches()->addBranch($data, $domain, $projectName, [$accessToken]);
Delete branch, (*91)
$buddy->getApiBranches()->deleteBranch($domain, $projectName, $name, [$force], [$accessToken]);
License
Please see the license file for more information., (*92)