Skip to content

Commit

Permalink
handle report headers (#21)
Browse files Browse the repository at this point in the history
Co-authored-by: d.kuznetsov <[email protected]>
  • Loading branch information
den-kuz and d.kuznetsov authored Jul 5, 2021
1 parent fa598f0 commit 7e88d31
Showing 1 changed file with 27 additions and 20 deletions.
47 changes: 27 additions & 20 deletions src/Service/Reports.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

final class Reports extends \Gladyshev\Yandex\Direct\AbstractService
{
private $skipReportHeader = false;
private $skipReportSummary = false;
private $headers = [];

/**
Expand Down Expand Up @@ -78,46 +76,64 @@ public function setProcessingMode($processingMode): self
* @return $this
* @see https://tech.yandex.ru/direct/doc/reports/headers-docpage/
*/
public function setReturnMoneyInMicros($returnMoneyInMicros): self
public function setReturnMoneyInMicros($returnMoneyInMicros = true): self
{
if (is_numeric($returnMoneyInMicros) || is_bool($returnMoneyInMicros)) {
$returnMoneyInMicros = $returnMoneyInMicros ? 'true' : 'false';
}
$this->headers['returnMoneyInMicros'] = $returnMoneyInMicros;

return $this;
}

/**
* Не выводить в отчете строку с названием отчета и диапазоном дат.
*
* @param $skipReportHeader
* @return $this
* @see https://tech.yandex.ru/direct/doc/reports/headers-docpage/
*/
public function setSkipReportHeader(): self
public function setSkipReportHeader($skipReportHeader = true): self
{
$this->headers['skipReportHeader'] = 'true';
if (is_numeric($skipReportHeader) || is_bool($skipReportHeader)) {
$skipReportHeader = $skipReportHeader ? 'true' : 'false';
}
$this->headers['skipReportHeader'] = $skipReportHeader;

return $this;
}

/**
* Не выводить в отчете строку с названиями полей.
*
* @param bool $skipColumnHeader
* @return $this
* @see https://tech.yandex.ru/direct/doc/reports/headers-docpage/
*/
public function setSkipColumnHeader(): self
public function setSkipColumnHeader($skipColumnHeader = true): self
{
$this->headers['skipColumnHeader'] = 'true';
if (is_numeric($skipColumnHeader) || is_bool($skipColumnHeader)) {
$skipColumnHeader = $skipColumnHeader ? 'true' : 'false';
}
$this->headers['skipColumnHeader'] = $skipColumnHeader;

return $this;
}

/**
* Не выводить в отчете строку с количеством строк статистики.
*
* @param bool $skipReportSummary
* @return $this
* @see https://tech.yandex.ru/direct/doc/reports/headers-docpage/
*/
public function setSkipReportSummary(): self
public function setSkipReportSummary($skipReportSummary = true): self
{
$this->skipReportSummary = true;
if (is_numeric($skipReportSummary) || is_bool($skipReportSummary)) {
$skipReportSummary = $skipReportSummary ? 'true' : 'false';
}
$this->headers['skipReportSummary'] = $skipReportSummary;

return $this;
}

Expand Down Expand Up @@ -156,6 +172,7 @@ protected function handleResponse(
|| $response->getStatusCode() == 202
) {
$result['retryIn'] = current($response->getHeader('retryIn'));
$result['reportsInQueue'] = current($response->getHeader('reportsInQueue'));

return $result;
}
Expand All @@ -167,16 +184,6 @@ protected function handleResponse(

protected function getHeaders(): array
{
$headers = parent::getHeaders();

if ($this->skipReportHeader) {
$headers['skipReportHeader'] = 'true';
}

if ($this->skipReportSummary) {
$headers['skipReportSummary'] = 'true';
}

return $headers;
return $this->headers + parent::getHeaders();
}
}

0 comments on commit 7e88d31

Please sign in to comment.