buddy-works/buddy-works-php-api

Buddy Works SDK for PHP

1.4.0 2021-08-26 08:05 UTC

README

Minimum PHP Version buddy branch Latest Stable Version GitHub

Official PHP client library for Buddy Build Server with CI.

Installation

This library is distributed on packagist and is working with composer. In order to add it as a dependency, run the following command:

composer require buddy-works/buddy-works-php-api

Compatibility

Usage of OAUTH

First you need to add application in your Buddy ID.

You will then obtain clientId & clientSecret to execute this code:

$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

state should be an unguessable random string. It is used to protect against cross-site request forgery attacks.

redirectUrl is optional more

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)

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:

$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.

Usage of direct tokens

You can also use API Tokens.

That functionality is provided for testing purposes and will only work for individual tokens generated per user.

All requests will be called on behalf of the user who provided token.

API's

For detailed info what send for which method, error codes, rates & limits - check Buddy documentation

To start using api you should pass to Buddy constructor acquired access token.

$buddy = new Buddy\Buddy([
  'accessToken' => 'your access token'
]);

Workspaces

Get workspaces

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

    $buddy->getApiWorkspaces()->getWorkspace($domain, [$accessToken]);

Webhooks

Get webhooks

    $buddy->getApiWebhooks()->getWebhooks($domain, [$accessToken]);

Add webhook

    $buddy->getApiWebhooks()->addWebhook($data, $domain, [$accessToken]);

Get webhook

    $buddy->getApiWebhooks()->getWebhook($domain, $webhookId, [$accessToken]);

Edit webhook

    $buddy->getApiWebhooks()->editWebhook($data, $domain, $webhookId, [$accessToken]);

Delete webhook

    $buddy->getApiWebhooks()->deleteWebhook($domain, $webhookId, [$accessToken]);

Tags

Get tags

    $buddy->getApiTags()->getTags($domain, $projectName, [$accessToken]);

Get tag

    $buddy->getApiTags()->getTag($domain, $projectName, $name, [$accessToken]);

Ssh Keys

Get keys

    $buddy->getApiSshKeys()->getKeys([$accessToken]);

Add key

    $buddy->getApiSshKeys()->addKey($data, [$accessToken]);

Delete key

    $buddy->getApiSshKeys()->deleteKey($keyId, [$accessToken]);

Get key

    $buddy->getApiSshKeys()->getKey($keyId, [$accessToken]);

Source

Get contents

    $buddy->getApiSource()->getContents($domain, $projectName, [$path], [$filters], [$accessToken]);

Add file

    $buddy->getApiSource()->addFile($data, $domain, $projectName, [$accessToken]);

Edit file

    $buddy->getApiSource()->editFile($data, $domain, $projectName, $path, [$accessToken]);

Delete file

    $buddy->getApiSource()->deleteFile($data, $domain, $projectName, $path, [$accessToken]);

Projects

Get projects

    $buddy->getApiProjects()->getProjects($domain, [$filters], [$accessToken]);

Add project

    $buddy->getApiProjects()->addProject($data, $domain, [$accessToken]);

Get projects

    $buddy->getApiProjects()->getProject($domain, $projectName, [$accessToken]);

Edit project

    $buddy->getApiProjects()->editProject($data, $domain, $projectName, [$accessToken]);

Delete project

    $buddy->getApiProjects()->deleteProject($domain, $projectName, [$accessToken]);

Get project members

    $buddy->getApiProjects()->getProjectMembers($domain, $projectName, [$filters], [$accessToken]);

Add project member

    $buddy->getApiProjects()->addProjectMember($domain, $projectName, $userId, $permissionId, [$accessToken]);

Get project member

    $buddy->getApiProjects()->getProjectMember($domain, $projectName, $userId, [$accessToken]);

Edit project member

    $buddy->getApiProjects()->editProjectMember($domain, $projectName, $userId, $permissionId, [$accessToken]);

Delete project member

    $buddy->getApiProjects()->deleteProjectMember($domain, $projectName, $userId, [$accessToken]);

Profile

Get user

    $buddy->getApiProfile()->getAuthenticatedUser([$accessToken]);

Edit user

    $buddy->getApiProfile()->editAuthenticatedUser($data, [$accessToken]);

Pipelines

Get pipelines

    $buddy->getApiPipelines()->getPipelines($domain, $projectName, [$filters], [$accessToken]);

Add pipeline

    $buddy->getApiPipelines()->addPipeline($data, $domain, $projectName, [$accessToken]);

Get pipeline

    $buddy->getApiPipelines()->getPipeline($domain, $projectName, $pipelineId, [$accessToken]);

Edit pipeline

    $buddy->getApiPipelines()->editPipeline($data, $domain, $projectName, $pipelineId, [$accessToken]);

Delete pipeline

    $buddy->getApiPipelines()->deletePipeline($domain, $projectName, $pipelineId, [$accessToken]);

Get pipeline actions

    $buddy->getApiPipelines()->getPipelineActions($domain, $projectName, $pipelineId, [$accessToken]);

Add pipeline action

    $buddy->getApiPipelines()->addPipelineAction($data, $domain, $projectName, $pipelineId, [$accessToken]);

Get pipeline action

    $buddy->getApiPipelines()->getPipelineAction($domain, $projectName, $pipelineId, $actionId, [$accessToken]);

Edit pipeline action

    $buddy->getApiPipelines()->editPipelineAction($data, $domain, $projectName, $pipelineId, $actionId, [$accessToken]);

Delete pipeline action

    $buddy->getApiPipelines()->deletePipelineAction($domain, $projectName, $pipelineId, $actionId, [$accessToken]);

Permissions

Get permissions

    $buddy->getApiPermissions()->getWorkspacePermissions($domain, [$accessToken]);

Add permission

    $buddy->getApiPermissions()->addWorkspacePermission($data, $domain, [$accessToken]);

Get permission

    $buddy->getApiPermissions()->getWorkspacePermission($domain, $permissionId, [$accessToken]);

Edit permission

    $buddy->getApiPermissions()->editWorkspacePermission($data, $domain, $permissionId, [$accessToken]);

Delete permission

    $buddy->getApiPermissions()->deleteWorkspacePermission($domain, $permissionId, [$accessToken]);

Members

Get members

    $buddy->getApiMembers()->getWorkspaceMembers($domain, [$filters], [$accessToken]);

Add member

    $buddy->getApiMembers()->addWorkspaceMember($domain, $email, [$accessToken]);

Get member

    $buddy->getApiMembers()->getWorkspaceMember($domain, $userId, [$accessToken]);

Edit member

    $buddy->getApiMembers()->editWorkspaceMember($domain, $userId, $isAdmin, [$accessToken]);

Delete member

    $buddy->getApiMembers()->deleteWorkspaceMember($domain, $userId, [$accessToken]);

Get member projects

    $buddy->getApiMembers()->getWorkspaceMemberProjects($domain, $userId, [$filters], [$accessToken]);

Integrations

Get integrations

    $buddy->getApiIntegrations()->getIntegrations([$accessToken]);

Get integration

    $buddy->getApiIntegrations()->getIntegration($integrationId, [$accessToken]);

Groups

Get groups

    $buddy->getApiGroups()->getGroups($domain, [$accessToken]);

Add group

    $buddy->getApiGroups()->addGroup($data, $domain, [$accessToken]);

Get group

    $buddy->getApiGroups()->getGroup($domain, $groupId, [$accessToken]);

Edit group

    $buddy->getApiGroups()->editGroup($data, $domain, $groupId, [$accessToken]);

Delete group

    $buddy->getApiGroups()->deleteGroup($domain, $groupId, [$accessToken]);

Get group members

    $buddy->getApiGroups()->getGroupMembers($domain, $groupId, [$accessToken]);

Add group member

    $buddy->getApiGroups()->addGroupMember($domain, $groupId, $userId, [$accessToken]);

Get group member

    $buddy->getApiGroups()->getGroupMember($domain, $groupId, $userId, [$accessToken]);

Delete group member

    $buddy->getApiGroups()->deleteGroupMember($domain, $groupId, $userId, [$accessToken]);

Executions

Get executions

    $buddy->getApiExecutions()->getExecutions($domain, $projectName, $pipelineId, [$filters], [$accessToken]);

Run execution

    $buddy->getApiExecutions()->runExecution($data, $domain, $projectName, $pipelineId, [$accessToken]);

Get execution

    $buddy->getApiExecutions()->getExecution($domain, $projectName, $pipelineId, $executionId, [$accessToken]);

Cancel execution

    $buddy->getApiExecutions()->cancelExecution($domain, $projectName, $pipelineId, $executionId, [$accessToken]);

Retry execution

    $buddy->getApiExecutions()->retryRelease($domain, $projectName, $pipelineId, $executionId, [$accessToken]);

Emails

Get emails

    $buddy->getApiEmails()->getAuthenticatedUserEmails([$accessToken]);

Add email

    $buddy->getApiEmails()->addAuthenticatedUserEmail($email, [$accessToken]);

Delete email

    $buddy->getApiEmails()->deleteAuthenticatedUserEmail($email, [$accessToken]);  

Commits

Get commits

    $buddy->getApiCommits()->getCommits($domain, $projectName, [$filters], [$accessToken]);

Get commit

    $buddy->getApiCommits()->getCommit($domain, $projectName, $revision, [$accessToken]);

Compare commits

    $buddy->getApiCommits()->getCompare($domain, $projectName, $base, $head, [$filters], [$accessToken]);

Branches

Get branches

    $buddy->getApiBranches()->getBranches($domain, $projectName, [$accessToken]);

Get branch

    $buddy->getApiBranches()->getBranch($domain, $projectName, $name, [$accessToken]);

Add branch

    $buddy->getApiBranches()->addBranch($data, $domain, $projectName, [$accessToken]);

Delete branch

    $buddy->getApiBranches()->deleteBranch($domain, $projectName, $name, [$force], [$accessToken]);

License

Please see the license file for more information.