From f9f472a5abcad50d0394769b6293bf8c266ed9ca Mon Sep 17 00:00:00 2001 From: brainsrage Date: Fri, 8 Jun 2018 11:49:31 +0500 Subject: [PATCH 1/5] #32 start add new service --- .../keywordbids/KeywordBidsService.php | 72 ++++++++++++++++ .../KeywordBidsSelectionCriteria.php | 51 +++++++++++ .../keywordbids/enum/CalculateByEnum.php | 11 +++ .../keywordbids/enum/KeywordBidFieldEnum.php | 22 +++++ .../keywordbids/enum/PositionEnum.php | 13 +++ src/services/keywordbids/enum/ScopeEnum.php | 12 +++ .../models/AuctionKeywordBidItem.php | 26 ++++++ .../keywordbids/models/ContextCoverage.php | 14 ++++ .../models/ContextCoverageItem.php | 19 +++++ .../models/KeywordBidActionResult.php | 33 ++++++++ .../keywordbids/models/KeywordBidGetItem.php | 68 +++++++++++++++ .../models/KeywordBidSetAutoItem.php | 84 +++++++++++++++++++ .../keywordbids/models/KeywordBidSetItem.php | 65 ++++++++++++++ .../keywordbids/models/SearchPrices.php | 17 ++++ 14 files changed, 507 insertions(+) create mode 100644 src/services/keywordbids/KeywordBidsService.php create mode 100644 src/services/keywordbids/criterias/KeywordBidsSelectionCriteria.php create mode 100644 src/services/keywordbids/enum/CalculateByEnum.php create mode 100644 src/services/keywordbids/enum/KeywordBidFieldEnum.php create mode 100644 src/services/keywordbids/enum/PositionEnum.php create mode 100644 src/services/keywordbids/enum/ScopeEnum.php create mode 100644 src/services/keywordbids/models/AuctionKeywordBidItem.php create mode 100644 src/services/keywordbids/models/ContextCoverage.php create mode 100644 src/services/keywordbids/models/ContextCoverageItem.php create mode 100644 src/services/keywordbids/models/KeywordBidActionResult.php create mode 100644 src/services/keywordbids/models/KeywordBidGetItem.php create mode 100644 src/services/keywordbids/models/KeywordBidSetAutoItem.php create mode 100644 src/services/keywordbids/models/KeywordBidSetItem.php create mode 100644 src/services/keywordbids/models/SearchPrices.php diff --git a/src/services/keywordbids/KeywordBidsService.php b/src/services/keywordbids/KeywordBidsService.php new file mode 100644 index 0000000..ee9e083 --- /dev/null +++ b/src/services/keywordbids/KeywordBidsService.php @@ -0,0 +1,72 @@ + $SelectionCriteria, + 'FieldNames' => $FieldNames + ]; + return $this->doGet($params, 'KeywordBids', KeywordBidGetItem::class); + } + + /** + * @param KeywordBidGetItem[] $Bids + * + * @return KeywordBidActionResult[] + */ + public function set(array $Bids) + { + $params = [ + 'Bids' => $Bids + ]; + $result = $this->call('set', $params); + return $this->mapArray($result->SetResults, ActionResult::class); + } + + /** + * @param KeywordBidSetAutoItem[] $Bids + * + * @return KeywordBidActionResult[] + */ + public function setAuto(array $Bids) + { + $params = [ + 'Bids' => $Bids + ]; + $result = $this->call('setAuto', $params); + return $this->mapArray($result->SetAutoResults, KeywordBidActionResult::class); + } + + protected function getName() + { + return 'bids'; + } + + /** + * @param array $entities + * @throws \ErrorException + */ + public function toUpdateEntities(array $entities) + { + throw new \ErrorException('Not implemented'); + } +} \ No newline at end of file diff --git a/src/services/keywordbids/criterias/KeywordBidsSelectionCriteria.php b/src/services/keywordbids/criterias/KeywordBidsSelectionCriteria.php new file mode 100644 index 0000000..77d517c --- /dev/null +++ b/src/services/keywordbids/criterias/KeywordBidsSelectionCriteria.php @@ -0,0 +1,51 @@ +CampaignIds && !$this->AdGroupIds && !$this->KeywordIds) { + $context->buildViolation('Должно быть указано одно из следующих значений: CampaignIds, AdGroupIds, KeywordIds') + ->atPath('CampaignIds') + ->atPath('AdGroupIds') + ->atPath('KeywordIds') + ->addViolation(); + } + } +} \ No newline at end of file diff --git a/src/services/keywordbids/enum/CalculateByEnum.php b/src/services/keywordbids/enum/CalculateByEnum.php new file mode 100644 index 0000000..43a3843 --- /dev/null +++ b/src/services/keywordbids/enum/CalculateByEnum.php @@ -0,0 +1,11 @@ +CampaignId && !$this->AdGroupId && !$this->KeywordId) { + $context->buildViolation('Должно быть указано одно из следующих значений: CampaignId, AdGroupId, KeywordId') + ->atPath('CampaignId') + ->atPath('AdGroupId') + ->atPath('KeywordId') + ->addViolation(); + } + } +} \ No newline at end of file diff --git a/src/services/keywordbids/models/KeywordBidSetItem.php b/src/services/keywordbids/models/KeywordBidSetItem.php new file mode 100644 index 0000000..658864f --- /dev/null +++ b/src/services/keywordbids/models/KeywordBidSetItem.php @@ -0,0 +1,65 @@ +CampaignId && !$this->AdGroupId && !$this->KeywordId) { + $context->buildViolation('Должно быть указано одно из следующих значений: CampaignId, AdGroupId, KeywordId') + ->atPath('CampaignId') + ->atPath('AdGroupId') + ->atPath('KeywordId') + ->addViolation(); + } + if (!$this->Bid && !$this->ContextBid && !$this->StrategyPriority) { + $context->buildViolation('Должно быть указано одно из следующих значений: Bid, ContextBid, StrategyPriority') + ->atPath('Bid') + ->atPath('ContextBid') + ->atPath('StrategyPriority') + ->addViolation(); + } + } +} \ No newline at end of file diff --git a/src/services/keywordbids/models/SearchPrices.php b/src/services/keywordbids/models/SearchPrices.php new file mode 100644 index 0000000..881af71 --- /dev/null +++ b/src/services/keywordbids/models/SearchPrices.php @@ -0,0 +1,17 @@ + Date: Fri, 8 Jun 2018 15:28:10 +0500 Subject: [PATCH 2/5] #32 added all models for KeywordBids service --- .../keywordbids/KeywordBidsService.php | 28 +++++++++---- .../KeywordBidsSelectionCriteria.php | 6 +++ .../keywordbids/enum/ServingStatusEnum.php | 10 +++++ .../models/AuctionKeywordBidItem.php | 6 +-- .../keywordbids/models/BiddingRuleItem.php | 36 ++++++++++++++++ .../keywordbids/models/ContextCoverage.php | 14 ------- .../models/ContextCoverageItem.php | 19 --------- .../keywordbids/models/CoverageItem.php | 15 +++++++ .../keywordbids/models/KeywordBidGetItem.php | 42 +++++-------------- .../models/KeywordBidSetAutoItem.php | 39 ++--------------- .../keywordbids/models/KeywordBidSetItem.php | 13 +++--- .../keywordbids/models/NetworkByCoverage.php | 27 ++++++++++++ .../models/NetworkCoverageItem.php | 22 ++++++++++ .../keywordbids/models/NetworkItem.php | 20 +++++++++ .../models/SearchByTrafficVolume.php | 27 ++++++++++++ .../keywordbids/models/SearchItem.php | 18 ++++++++ .../keywordbids/models/SearchPrices.php | 17 -------- 17 files changed, 223 insertions(+), 136 deletions(-) create mode 100644 src/services/keywordbids/enum/ServingStatusEnum.php create mode 100644 src/services/keywordbids/models/BiddingRuleItem.php delete mode 100644 src/services/keywordbids/models/ContextCoverage.php delete mode 100644 src/services/keywordbids/models/ContextCoverageItem.php create mode 100644 src/services/keywordbids/models/CoverageItem.php create mode 100644 src/services/keywordbids/models/NetworkByCoverage.php create mode 100644 src/services/keywordbids/models/NetworkCoverageItem.php create mode 100644 src/services/keywordbids/models/NetworkItem.php create mode 100644 src/services/keywordbids/models/SearchByTrafficVolume.php create mode 100644 src/services/keywordbids/models/SearchItem.php delete mode 100644 src/services/keywordbids/models/SearchPrices.php diff --git a/src/services/keywordbids/KeywordBidsService.php b/src/services/keywordbids/KeywordBidsService.php index ee9e083..4965e6e 100644 --- a/src/services/keywordbids/KeywordBidsService.php +++ b/src/services/keywordbids/KeywordBidsService.php @@ -3,6 +3,7 @@ namespace directapi\services\bids; +use directapi\common\criterias\LimitOffset; use directapi\common\results\ActionResult; use directapi\services\BaseService; use directapi\services\keywordbids\criterias\KeywordBidsSelectionCriteria; @@ -10,36 +11,49 @@ use directapi\services\keywordbids\models\KeywordBidActionResult; use directapi\services\keywordbids\models\KeywordBidGetItem; use directapi\services\keywordbids\models\KeywordBidSetAutoItem; +use directapi\services\keywordbids\models\KeywordBidSetItem; class KeywordBidsService extends BaseService { /** * @param KeywordBidsSelectionCriteria $SelectionCriteria - * @param KeywordBidFieldEnum[] $FieldNames + * @param KeywordBidFieldEnum[] $FieldNames * + * @param string[] $SearchFieldNames + * @param string[] $NetworkFieldNames + * @param LimitOffset $Page * @return KeywordBidGetItem[] */ - public function get(KeywordBidsSelectionCriteria $SelectionCriteria, array $FieldNames) + public function get(KeywordBidsSelectionCriteria $SelectionCriteria, array $FieldNames, array $SearchFieldNames = [], array $NetworkFieldNames = [], LimitOffset $Page = null) { $params = [ 'SelectionCriteria' => $SelectionCriteria, 'FieldNames' => $FieldNames ]; + if ($SearchFieldNames) { + $params['SearchFieldNames'] = $Page; + } + if ($NetworkFieldNames) { + $params['NetworkFieldNames'] = $Page; + } + if ($Page) { + $params['Page'] = $Page; + } return $this->doGet($params, 'KeywordBids', KeywordBidGetItem::class); } /** - * @param KeywordBidGetItem[] $Bids + * @param KeywordBidSetItem[] $Bids * * @return KeywordBidActionResult[] */ public function set(array $Bids) { $params = [ - 'Bids' => $Bids + 'KeywordBids' => $Bids ]; $result = $this->call('set', $params); - return $this->mapArray($result->SetResults, ActionResult::class); + return $this->mapArray($result->SetResults, KeywordBidActionResult::class); } /** @@ -50,7 +64,7 @@ public function set(array $Bids) public function setAuto(array $Bids) { $params = [ - 'Bids' => $Bids + 'KeywordBids' => $Bids ]; $result = $this->call('setAuto', $params); return $this->mapArray($result->SetAutoResults, KeywordBidActionResult::class); @@ -58,7 +72,7 @@ public function setAuto(array $Bids) protected function getName() { - return 'bids'; + return 'keywordbids'; } /** diff --git a/src/services/keywordbids/criterias/KeywordBidsSelectionCriteria.php b/src/services/keywordbids/criterias/KeywordBidsSelectionCriteria.php index 77d517c..c0fd7e6 100644 --- a/src/services/keywordbids/criterias/KeywordBidsSelectionCriteria.php +++ b/src/services/keywordbids/criterias/KeywordBidsSelectionCriteria.php @@ -5,6 +5,7 @@ use directapi\components\interfaces\ICallbackValidation; use directapi\components\Model; +use directapi\services\adgroups\enum\AdGroupStatusEnum; use Symfony\Component\Validator\Constraints as Assert; use Symfony\Component\Validator\Context\ExecutionContextInterface; @@ -34,6 +35,11 @@ class KeywordBidsSelectionCriteria extends Model implements ICallbackValidation */ public $CampaignIds; + /** + * @var AdGroupStatusEnum[] + */ + public $ServingStatuses; + /** * @Assert\Callback() * @param ExecutionContextInterface $context diff --git a/src/services/keywordbids/enum/ServingStatusEnum.php b/src/services/keywordbids/enum/ServingStatusEnum.php new file mode 100644 index 0000000..1378ed1 --- /dev/null +++ b/src/services/keywordbids/enum/ServingStatusEnum.php @@ -0,0 +1,10 @@ +SearchByTrafficVolume && !$this->NetworkByCoverage) { + $context->buildViolation('Должно быть указано одно из следующих значений: SearchByTrafficVolume, NetworkByCoverage') + ->atPath('SearchByTrafficVolume') + ->atPath('NetworkByCoverage') + ->addViolation(); + } + } +} \ No newline at end of file diff --git a/src/services/keywordbids/models/ContextCoverage.php b/src/services/keywordbids/models/ContextCoverage.php deleted file mode 100644 index 57197ba..0000000 --- a/src/services/keywordbids/models/ContextCoverage.php +++ /dev/null @@ -1,14 +0,0 @@ -atPath('KeywordId') ->addViolation(); } - if (!$this->Bid && !$this->ContextBid && !$this->StrategyPriority) { - $context->buildViolation('Должно быть указано одно из следующих значений: Bid, ContextBid, StrategyPriority') - ->atPath('Bid') - ->atPath('ContextBid') + if (!$this->SearchBid && !$this->NetworkBid && !$this->StrategyPriority) { + $context->buildViolation('Должно быть указано одно из следующих значений: SearchBid, NetworkBid, StrategyPriority') + ->atPath('SearchBid') + ->atPath('NetworkBid') ->atPath('StrategyPriority') ->addViolation(); } diff --git a/src/services/keywordbids/models/NetworkByCoverage.php b/src/services/keywordbids/models/NetworkByCoverage.php new file mode 100644 index 0000000..9fa067a --- /dev/null +++ b/src/services/keywordbids/models/NetworkByCoverage.php @@ -0,0 +1,27 @@ + Date: Fri, 8 Jun 2018 15:54:52 +0500 Subject: [PATCH 3/5] #32 add KeywordBids service to main class --- src/DirectApiService.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/DirectApiService.php b/src/DirectApiService.php index 8aae2d0..2dfbb60 100644 --- a/src/DirectApiService.php +++ b/src/DirectApiService.php @@ -15,6 +15,7 @@ use directapi\services\audiencetargets\AudienceTargetsService; use directapi\services\bidmodifiers\BidModifiersService; use directapi\services\bids\BidsService; +use directapi\services\bids\KeywordBidsService; use directapi\services\campaigns\CampaignsService; use directapi\services\changes\ChangesService; use directapi\services\clients\ClientsService; @@ -70,6 +71,11 @@ class DirectApiService */ private $bidsService; + /** + * @var KeywordBidsService + */ + private $keywordBidsService; + /** * @var CampaignsService */ @@ -192,6 +198,17 @@ public function getBidsService() return $this->bidsService; } + /** + * @return KeywordBidsService + */ + public function getKeywordBidsService() + { + if (!$this->keywordBidsService) { + $this->keywordBidsService = new KeywordBidsService($this); + } + return $this->keywordBidsService; + } + /** * @return CampaignsService */ From d6ba2dce5eff9c5630fa102656e128e4ed427e00 Mon Sep 17 00:00:00 2001 From: brainsrage Date: Fri, 8 Jun 2018 16:09:43 +0500 Subject: [PATCH 4/5] #32 delete unused enums --- src/services/keywordbids/enum/CalculateByEnum.php | 11 ----------- src/services/keywordbids/enum/PositionEnum.php | 13 ------------- src/services/keywordbids/enum/ScopeEnum.php | 12 ------------ 3 files changed, 36 deletions(-) delete mode 100644 src/services/keywordbids/enum/CalculateByEnum.php delete mode 100644 src/services/keywordbids/enum/PositionEnum.php delete mode 100644 src/services/keywordbids/enum/ScopeEnum.php diff --git a/src/services/keywordbids/enum/CalculateByEnum.php b/src/services/keywordbids/enum/CalculateByEnum.php deleted file mode 100644 index 43a3843..0000000 --- a/src/services/keywordbids/enum/CalculateByEnum.php +++ /dev/null @@ -1,11 +0,0 @@ - Date: Sat, 9 Jun 2018 14:31:14 +0500 Subject: [PATCH 5/5] #32 fix namespaces, add use statements for validation, fix models --- src/DirectApiService.php | 2 +- src/services/keywordbids/KeywordBidsService.php | 3 +-- src/services/keywordbids/models/AuctionKeywordBidItem.php | 1 + src/services/keywordbids/models/BiddingRuleItem.php | 1 + src/services/keywordbids/models/CoverageItem.php | 1 + src/services/keywordbids/models/KeywordBidActionResult.php | 1 + src/services/keywordbids/models/KeywordBidGetItem.php | 1 + src/services/keywordbids/models/KeywordBidSetAutoItem.php | 6 +----- src/services/keywordbids/models/NetworkByCoverage.php | 6 ++++++ src/services/keywordbids/models/NetworkCoverageItem.php | 1 + src/services/keywordbids/models/NetworkItem.php | 1 + src/services/keywordbids/models/SearchByTrafficVolume.php | 6 ++++++ src/services/keywordbids/models/SearchItem.php | 2 ++ 13 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/DirectApiService.php b/src/DirectApiService.php index 2dfbb60..5fa1ddb 100644 --- a/src/DirectApiService.php +++ b/src/DirectApiService.php @@ -15,10 +15,10 @@ use directapi\services\audiencetargets\AudienceTargetsService; use directapi\services\bidmodifiers\BidModifiersService; use directapi\services\bids\BidsService; -use directapi\services\bids\KeywordBidsService; use directapi\services\campaigns\CampaignsService; use directapi\services\changes\ChangesService; use directapi\services\clients\ClientsService; +use directapi\services\keywordbids\KeywordBidsService; use directapi\services\keywords\KeywordsService; use directapi\services\reports\ReportsService; use directapi\services\retargetinglists\RetargetingListsService; diff --git a/src/services/keywordbids/KeywordBidsService.php b/src/services/keywordbids/KeywordBidsService.php index 4965e6e..820214b 100644 --- a/src/services/keywordbids/KeywordBidsService.php +++ b/src/services/keywordbids/KeywordBidsService.php @@ -1,10 +1,9 @@