Skip to content

Commit

Permalink
Merge pull request #551 from vadimkorchagin/feature/INDEP-337
Browse files Browse the repository at this point in the history
Feature/indep 337
  • Loading branch information
bessudnov authored Feb 29, 2024
2 parents 5ad922e + c7f269e commit 6a56bf2
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/AmoCRM/Client/AmoCRMApiRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class AmoCRMApiRequest
public const CONNECT_TIMEOUT = 5;
public const REQUEST_TIMEOUT = 20;
//TODO Do not forget to change this on each release
public const LIBRARY_VERSION = '1.5.0';
public const LIBRARY_VERSION = '1.5.1';
public const USER_AGENT = 'amoCRM-API-Library/' . self::LIBRARY_VERSION;

public const SUCCESS_STATUSES = [
Expand Down
35 changes: 33 additions & 2 deletions src/AmoCRM/Models/Sources/WebsiteButtonCreateRequestModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ class WebsiteButtonCreateRequestModel extends BaseApiModel
*/
private $trustedWebsites;

/**
* @var string|null $name
*/
private $name;

/**
* WebsiteButtonCreateRequestModel constructor.
*
Expand All @@ -38,11 +43,13 @@ class WebsiteButtonCreateRequestModel extends BaseApiModel
public function __construct(
int $pipelineId,
array $trustedWebsites = [],
bool $isUsedInApp = false
bool $isUsedInApp = false,
?string $name = null
) {
$this->pipelineId = $pipelineId;
$this->trustedWebsites = $trustedWebsites;
$this->isUsedInApp = $isUsedInApp;
$this->name = $name;
}

/**
Expand Down Expand Up @@ -99,16 +106,40 @@ public function setTrustedWebsites(array $trustedWebsites): void
$this->trustedWebsites = $trustedWebsites;
}

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

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

/**
* @return array
*/
public function toArray(): array
{
return [
$attributes = [
'pipeline_id' => $this->getPipelineId(),
'is_used_in_app' => $this->isUsedInApp(),
'trusted_websites' => $this->getTrustedWebsites(),
];

if (!empty($this->getName())) {
$attributes['name'] = $this->getName();
}

return $attributes;
}

/**
Expand Down
32 changes: 30 additions & 2 deletions src/AmoCRM/Models/Sources/WebsiteButtonCreateResponseModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,26 @@ class WebsiteButtonCreateResponseModel extends BaseApiModel
*/
private $trustedWebsites;

/**
* @var string|null
*/
private $name;

/**
* WebsiteButtonCreateResponseModel constructor.
*
* @param int $sourceId
* @param array $trustedWebsites
* @param string|null $name
*/
public function __construct(
int $sourceId,
array $trustedWebsites = []
array $trustedWebsites = [],
?string $name = null
) {
$this->sourceId = $sourceId;
$this->trustedWebsites = $trustedWebsites;
$this->name = $name;
}

/**
Expand Down Expand Up @@ -74,6 +82,24 @@ public function setTrustedWebsites(array $trustedWebsites): void
$this->trustedWebsites = $trustedWebsites;
}

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

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

/**
* @param array $websiteButtonCreateResponse
*
Expand All @@ -83,7 +109,8 @@ public static function fromArray(array $websiteButtonCreateResponse): WebsiteBut
{
return new WebsiteButtonCreateResponseModel(
(int) ($websiteButtonCreateResponse['source_id'] ?? 0),
(array) ($websiteButtonCreateResponse['trusted_websites'] ?? [])
(array) ($websiteButtonCreateResponse['trusted_websites'] ?? []),
(string) ($websiteButtonCreateResponse['name'] ?? '') ?: null
);
}

Expand All @@ -95,6 +122,7 @@ public function toArray(): array
return [
'source_id' => $this->getSourceId(),
'trusted_websites' => $this->getTrustedWebsites(),
'name' => $this->getName(),
];
}

Expand Down
53 changes: 46 additions & 7 deletions src/AmoCRM/Models/Sources/WebsiteButtonUpdateRequestModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace AmoCRM\Models\Sources;

use AmoCRM\Models\BaseApiModel;
use InvalidArgumentException;

/**
* Class WebsiteButtonUpdateRequestModel
Expand All @@ -23,6 +24,11 @@ class WebsiteButtonUpdateRequestModel extends BaseApiModel
*/
private $sourceId;

/**
* @var string|null
*/
private $name;

/**
* WebsiteButtonUpdateRequestModel constructor.
*
Expand All @@ -31,10 +37,12 @@ class WebsiteButtonUpdateRequestModel extends BaseApiModel
*/
public function __construct(
array $trustedWebsitesToAdd,
int $sourceId
int $sourceId,
?string $name = null
) {
$this->trustedWebsitesToAdd = $trustedWebsitesToAdd;
$this->sourceId = $sourceId;
$this->name = $name;
}

/**
Expand Down Expand Up @@ -73,25 +81,56 @@ public function setSourceId(int $sourceId): void
$this->sourceId = $sourceId;
}

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

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

/**
* @return array
*/
public function toArray(): array
{
return [
'trusted_websites' => [
'add' => $this->getTrustedWebsitesToAdd(),
],
];
$attributes = [];

if (!empty($this->getTrustedWebsitesToAdd())) {
$attributes['trusted_websites']['add'] = $this->getTrustedWebsitesToAdd();
}

if (!empty($this->getName())) {
$attributes['name'] = $this->getName();
}

return $attributes;
}

/**
* @param string|null $requestId
*
* @return array
* @throws InvalidArgumentException
*/
public function toApi(?string $requestId = '0'): array
{
return $this->toArray();
$data = $this->toArray();

if (empty($data)) {
throw new InvalidArgumentException('No attributes to update given');
}

return $data;
}
}

0 comments on commit 6a56bf2

Please sign in to comment.