Skip to content

Commit

Permalink
feat(organization-webhooks): Added Organization webhook model and end…
Browse files Browse the repository at this point in the history
…points (#161)
  • Loading branch information
tchapuis authored Oct 18, 2023
1 parent b2e34a7 commit 35cdc78
Show file tree
Hide file tree
Showing 5 changed files with 594 additions and 2 deletions.
90 changes: 90 additions & 0 deletions src/CrowdinApiClient/Api/OrganizationWebhookApi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?php

namespace CrowdinApiClient\Api;

use CrowdinApiClient\Model\OrganizationWebhook;
use CrowdinApiClient\ModelCollection;

/**
* Webhooks allow you to collect information about events that happen in your Crowdin Enterprise organization.
* You can select the request type, content type, and add a custom payload, which allows you to create integrations with other systems on your own.
*
* @package Crowdin\Api
*/
class OrganizationWebhookApi extends AbstractApi
{
/**
* List Organization Webhooks
* @link https://developer.crowdin.com/api/v2/#operation/api.webhooks.getMany API Documentation
* @link https://developer.crowdin.com/enterprise/api/v2/#operation/api.webhooks.getMany API Documentation Enterprise
*
* @param array $params
* @return ModelCollection
*/
public function list(array $params = []): ModelCollection
{
return $this->_list('webhooks', OrganizationWebhook::class, $params);
}

/**
* Get Organization Webhook
* @link https://developer.crowdin.com/api/v2/#operation/api.webhooks.get API Documentation
* @link https://developer.crowdin.com/enterprise/api/v2/#operation/api.webhooks.get API Documentation Enterprise
*
* @param int $organizationWebhookId
* @return OrganizationWebhook
*/
public function get(int $organizationWebhookId): OrganizationWebhook
{
return $this->_get(sprintf('webhooks/%d', $organizationWebhookId), OrganizationWebhook::class);
}

/**
* Add Organization Webhook
* @link https://developer.crowdin.com/api/v2/#operation/api.webhooks.post API Documentation
* @link https://developer.crowdin.com/enterprise/api/v2/#operation/api.webhooks.post API Documentation Enterprise
*
* @param array $data
* string $data[name] required<br>
* string $data[url] required<br>
* string[] $data[events] required Enum: "project.created" "project.deleted" Enterprise onyl enum: "project.created" "project.deleted" "group.created" "group.deleted"<br>
* string $data[requestType] required Enum: "POST" "GET"<br>
* boolean $data[isActive]<br>
* boolean $data[batchingEnabled]<br>
* string $data[contentType] Default: "application/json" Enum: "multipart/form-data" "application/json" "application/x-www-form-urlencoded"<br>
* array $data[headers]<br>
* array $data[payload]
*
* @return OrganizationWebhook|null
*/
public function create(array $data): ?OrganizationWebhook
{
return $this->_create('webhooks', OrganizationWebhook::class, $data);
}

/**
* Update Organization Webhook
* @link https://developer.crowdin.com/api/v2/#operation/api.webhooks.patch API Documentation
* @link https://developer.crowdin.com/enterprise/api/v2/#operation/api.webhooks.patch API Documentation Enterprise
*
* @param OrganizationWebhook $organizationWebhook
* @return OrganizationWebhook|null
*/
public function update(OrganizationWebhook $organizationWebhook): ?OrganizationWebhook
{
return $this->_update(sprintf('webhooks/%d', $organizationWebhook->getId()), $organizationWebhook);
}

/**
* Delete Organization Webhook
* @link https://developer.crowdin.com/api/v2/#operation/api.webhooks.delete API Documentation
* @link https://developer.crowdin.com/enterprise/api/v2/#operation/api.webhooks.delete API Documentation Enterprise
*
* @param int $organizationWebhookId
* @return mixed
*/
public function delete(int $organizationWebhookId)
{
return $this->_delete(sprintf('webhooks/%d', $organizationWebhookId));
}
}
7 changes: 5 additions & 2 deletions src/CrowdinApiClient/Crowdin.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
* @property \CrowdinApiClient\Api\Enterprise\TeamMemberApi teamMember
* @property \CrowdinApiClient\Api\BundleApi bundle
* @property \CrowdinApiClient\Api\NotificationApi|\CrowdinApiClient\Api\Enterprise\NotificationApi notification
* @property \CrowdinApiClient\Api\OrganizationWebhookApi organizationWebhook
*/
class Crowdin
{
Expand Down Expand Up @@ -110,7 +111,8 @@ class Crowdin
'translationStatus',
'distribution',
'bundle',
'notification'
'notification',
'organizationWebhook'
];

protected $servicesEnterprise = [
Expand Down Expand Up @@ -145,7 +147,8 @@ class Crowdin
'team',
'teamMember',
'bundle',
'notification'
'notification',
'organizationWebhook'
];

/**
Expand Down
244 changes: 244 additions & 0 deletions src/CrowdinApiClient/Model/OrganizationWebhook.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,244 @@
<?php

namespace CrowdinApiClient\Model;

/**
* @package Crowdin\Model
*/
class OrganizationWebhook extends BaseModel
{
/**
* @var string
*/
protected $id;
/**
* @var string
*/
protected $name;
/**
* @var string
*/
protected $url;
/**
* @var array
*/
protected $events;
/**
* @var array
*/
protected $headers;
/**
* @var array
*/
protected $payload;
/**
* @var bool
*/
protected $isActive;
/**
* @var bool
*/
protected $batchingEnabled;
/**
* @var string
*/
protected $requestType;
/**
* @var string
*/
protected $contentType;
/**
* @var string
*/
protected $createdAt;
/**
* @var string
*/
protected $updatedAt;

public function __construct(array $data = [])
{
parent::__construct($data);
$this->id = (string)$this->getDataProperty('id');
$this->name = (string)$this->getDataProperty('name');
$this->url = (string)$this->getDataProperty('url');
$this->events = (array)$this->getDataProperty('events');
$this->headers = (array)$this->getDataProperty('headers');
$this->payload = (array)$this->getDataProperty('payload');
$this->isActive = (bool)$this->getDataProperty('isActive');
$this->batchingEnabled = (bool)$this->getDataProperty('batchingEnabled');
$this->requestType = (string)$this->getDataProperty('requestType');
$this->contentType = (string)$this->getDataProperty('contentType');
$this->createdAt = (string)$this->getDataProperty('createdAt');
$this->updatedAt = (string)$this->getDataProperty('updatedAt');

}

/**
* @return string
*/
public function getId(): string
{
return $this->id;
}

/**
* @return string
*/
public function getName(): string
{
return $this->name;
}

/**
* @param string $name
*/
public function setName(string $name): void
{
$this->name = $name;
}

/**
* @return string
*/
public function getUrl(): string
{
return $this->url;
}

/**
* @param string $url
*/
public function setUrl(string $url): void
{
$this->url = $url;
}

/**
* @return array
*/
public function getEvents(): array
{
return $this->events;
}

/**
* @param array $events
*/
public function setEvents(array $events): void
{
$this->events = $events;
}

/**
* @return array
*/
public function getHeaders(): array
{
return $this->headers;
}

/**
* @param array $headers
*/
public function setHeaders(array $headers): void
{
$this->headers = $headers;
}

/**
* @return array
*/
public function getPayload(): array
{
return $this->payload;
}

/**
* @param array $payload
*/
public function setPayload(array $payload): void
{
$this->payload = $payload;
}

/**
* @return bool
*/
public function isActive(): bool
{
return $this->isActive;
}

/**
* @param bool $isActive
*/
public function setIsActive(bool $isActive): void
{
$this->isActive = $isActive;
}

/**
* @return bool
*/
public function isBatchingEnabled(): bool
{
return $this->batchingEnabled;
}

/**
* @param bool $batchingEnabled
*/
public function setBatchingEnabled(bool $batchingEnabled): void
{
$this->batchingEnabled = $batchingEnabled;
}

/**
* @return string
*/
public function getRequestType(): string
{
return $this->requestType;
}

/**
* @param string $requestType
*/
public function setRequestType(string $requestType): void
{
$this->requestType = $requestType;
}

/**
* @return string
*/
public function getContentType(): string
{
return $this->contentType;
}

/**
* @param string $contentType
*/
public function setContentType(string $contentType): void
{
$this->contentType = $contentType;
}

/**
* @return string
*/
public function getCreatedAt(): string
{
return $this->createdAt;
}

/**
* @return string
*/
public function getUpdatedAt(): string
{
return $this->updatedAt;
}
}
Loading

0 comments on commit 35cdc78

Please sign in to comment.