Skip to content

Commit

Permalink
Merge pull request #33 from sitkoru/#32_add_service_keywordBids
Browse files Browse the repository at this point in the history
#32 add service keyword bids
  • Loading branch information
SonicGD authored Jun 20, 2018
2 parents b599000 + 979956a commit 6901360
Show file tree
Hide file tree
Showing 17 changed files with 591 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/DirectApiService.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
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;
Expand Down Expand Up @@ -70,6 +71,11 @@ class DirectApiService
*/
private $bidsService;

/**
* @var KeywordBidsService
*/
private $keywordBidsService;

/**
* @var CampaignsService
*/
Expand Down Expand Up @@ -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
*/
Expand Down
85 changes: 85 additions & 0 deletions src/services/keywordbids/KeywordBidsService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php

namespace directapi\services\keywordbids;


use directapi\common\criterias\LimitOffset;
use directapi\services\BaseService;
use directapi\services\keywordbids\criterias\KeywordBidsSelectionCriteria;
use directapi\services\keywordbids\enum\KeywordBidFieldEnum;
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 string[] $SearchFieldNames
* @param string[] $NetworkFieldNames
* @param LimitOffset $Page
* @return KeywordBidGetItem[]
*/
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 KeywordBidSetItem[] $Bids
*
* @return KeywordBidActionResult[]
*/
public function set(array $Bids)
{
$params = [
'KeywordBids' => $Bids
];
$result = $this->call('set', $params);
return $this->mapArray($result->SetResults, KeywordBidActionResult::class);
}

/**
* @param KeywordBidSetAutoItem[] $Bids
*
* @return KeywordBidActionResult[]
*/
public function setAuto(array $Bids)
{
$params = [
'KeywordBids' => $Bids
];
$result = $this->call('setAuto', $params);
return $this->mapArray($result->SetAutoResults, KeywordBidActionResult::class);
}

protected function getName()
{
return 'keywordbids';
}

/**
* @param array $entities
* @throws \ErrorException
*/
public function toUpdateEntities(array $entities)
{
throw new \ErrorException('Not implemented');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

namespace directapi\services\keywordbids\criterias;


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;

class KeywordBidsSelectionCriteria extends Model implements ICallbackValidation
{
/**
* @var int[]
* @Assert\Count(
* max="10000"
* )
*/
public $KeywordIds;

/**
* @var int[]
* @Assert\Count(
* max="1000"
* )
*/
public $AdGroupIds;

/**
* @var int[]
* @Assert\Count(
* max="10"
* )
*/
public $CampaignIds;

/**
* @var AdGroupStatusEnum[]
*/
public $ServingStatuses;

/**
* @Assert\Callback()
* @param ExecutionContextInterface $context
*/
public function isValid(ExecutionContextInterface $context)
{
if (!$this->CampaignIds && !$this->AdGroupIds && !$this->KeywordIds) {
$context->buildViolation('Должно быть указано одно из следующих значений: CampaignIds, AdGroupIds, KeywordIds')
->atPath('CampaignIds')
->atPath('AdGroupIds')
->atPath('KeywordIds')
->addViolation();
}
}
}
22 changes: 22 additions & 0 deletions src/services/keywordbids/enum/KeywordBidFieldEnum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace directapi\services\keywordbids\enum;


use directapi\components\Enum;

class KeywordBidFieldEnum extends Enum
{
const KEYWORD_ID = 'KeywordId';
const AD_GROUP_ID = 'AdGroupId';
const CAMPAIGN_ID = 'CampaignId';
const BID = 'Bid';
const CONTEXT_BID = 'ContextBid';
const STRATEGY_PRIORITY = 'StrategyPriority';
const COMPETITORS_BIDS = 'CompetitorsBids';
const SEARCH_PRICES = 'SearchPrices';
const CONTEXT_COVERAGE = 'ContextCoverage';
const MIN_SEARCH_PRICE = 'MinSearchPrice';
const CURRENT_SEARCH_PRICE = 'CurrentSearchPrice';
const AUCTION_BIDS = 'AuctionBids';
}
10 changes: 10 additions & 0 deletions src/services/keywordbids/enum/ServingStatusEnum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace directapi\services\keywordbids\enum;


class ServingStatusEnum
{
const ELIGIBLE = 'ELIGIBLE';
const RARELY_SERVED = 'RARELY_SERVED';
}
25 changes: 25 additions & 0 deletions src/services/keywordbids/models/AuctionKeywordBidItem.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace directapi\services\keywordbids\models;


use directapi\components\Model;
use Symfony\Component\Validator\Constraints as Assert;

class AuctionKeywordBidItem extends Model
{
/**
* @var int Объем трафика.
*/
public $TrafficVolume;

/**
* @var int Минимальная ставка за указанную позицию.
*/
public $Bid;

/**
* @var int Списываемая цена для указанной позиции.
*/
public $Price;
}
37 changes: 37 additions & 0 deletions src/services/keywordbids/models/BiddingRuleItem.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace directapi\services\keywordbids\models;


use directapi\components\Model;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
use Symfony\Component\Validator\Constraints as Assert;

class BiddingRuleItem extends Model
{
/**
* @Assert\Valid()
* @var SearchByTrafficVolume
*/
public $SearchByTrafficVolume;

/**
* @Assert\Valid()
* @var NetworkByCoverage
*/
public $NetworkByCoverage;

/**
* @Assert\Callback()
* @param ExecutionContextInterface $context
*/
public function isValid(ExecutionContextInterface $context)
{
if (!$this->SearchByTrafficVolume && !$this->NetworkByCoverage) {
$context->buildViolation('Должно быть указано одно из следующих значений: SearchByTrafficVolume, NetworkByCoverage')
->atPath('SearchByTrafficVolume')
->atPath('NetworkByCoverage')
->addViolation();
}
}
}
16 changes: 16 additions & 0 deletions src/services/keywordbids/models/CoverageItem.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace directapi\services\keywordbids\models;


use directapi\components\Model;
use Symfony\Component\Validator\Constraints as Assert;

class CoverageItem extends Model
{
/**
* @Assert\Valid()
* @var NetworkCoverageItem[]
*/
public $CoverageItems;
}
34 changes: 34 additions & 0 deletions src/services/keywordbids/models/KeywordBidActionResult.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace directapi\services\keywordbids\models;

use directapi\components\Model;
use Symfony\Component\Validator\Constraints as Assert;

class KeywordBidActionResult extends Model
{
/**
* @var \directapi\common\results\ExceptionNotification[]
*/
public $Warnings;

/**
* @var \directapi\common\results\ExceptionNotification[]
*/
public $Errors;

/**
* @var int
*/
public $CampaignId;

/**
* @var int
*/
public $AdGroupId;

/**
* @var int
*/
public $KeywordId;
}
47 changes: 47 additions & 0 deletions src/services/keywordbids/models/KeywordBidGetItem.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace directapi\services\keywordbids\models;

use directapi\common\enum\PriorityEnum;
use directapi\components\Model;
use directapi\services\keywordbids\enum\ServingStatusEnum;
use Symfony\Component\Validator\Constraints as Assert;

class KeywordBidGetItem extends Model
{
/**
* @var int
*/
public $CampaignId;

/**
* @var int
*/
public $AdGroupId;

/**
* @var int
*/
public $KeywordId;

/**
* @var ServingStatusEnum
*/
public $ServingStatus;

/**
* @var PriorityEnum
*/
public $StrategyPriority;

/**
* @var SearchItem
*/
public $Search;

/**
* @var NetworkItem
* @Assert\Valid()
*/
public $Network;
}
Loading

0 comments on commit 6901360

Please sign in to comment.