Skip to content

Commit

Permalink
Update examples, extend response by units_used_login
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry Gladyshev committed Jan 6, 2021
1 parent 4a29b82 commit b0ef3f5
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 17 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ $ composer require gladyshev/yandex-direct-client

```php
$credentials = \Gladyshev\Yandex\Direct\Credentials::client(
getenv('__LOGIN__'),
getenv('__TOKEN__')
getenv('_TOKEN_')
);

$httpClient = new \GuzzleHttp\Client();
Expand All @@ -37,13 +36,14 @@ $response = $client->campaigns->get(
);

print_r($response);

// [
// 'request_id' => 1234567890,
// 'request_id' => 8695244274068608439,
// 'units_used_login' => 'ttt-agency',
// 'units' => [
// 'debit' => 10,
// 'limit' => 50,
// 'rest' => 100500
// 'rest' => 20828,
// 'limit' => 64000
// ],
// 'result' => [...]
// ]
Expand Down
3 changes: 1 addition & 2 deletions examples/agency_clients.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
require '../vendor/autoload.php';

$credentials = \Gladyshev\Yandex\Direct\Credentials::agencySandbox(
getenv('_TOKEN_'),
getenv('_MASTER_TOKEN_')
getenv('_TOKEN_')
);

$client = new \Gladyshev\Yandex\Direct\Client(
Expand Down
3 changes: 1 addition & 2 deletions examples/reports.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
require '../vendor/autoload.php';

$credentials = \Gladyshev\Yandex\Direct\Credentials::clientSandbox(
getenv('_TOKEN_'),
getenv('_MASTER_TOKEN_')
getenv('_TOKEN_')
);

$httpClient = new \GuzzleHttp\Client;
Expand Down
3 changes: 1 addition & 2 deletions examples/simple.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
require '../vendor/autoload.php';

$credentials = \Gladyshev\Yandex\Direct\Credentials::clientSandbox(
getenv('_TOKEN_'),
getenv('_MASTER_TOKEN_')
getenv('_TOKEN_')
);

$client = new \Gladyshev\Yandex\Direct\Client(
Expand Down
3 changes: 3 additions & 0 deletions src/AbstractService.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ protected function handleResponse(
);
}

$unitsUsedLogin = current($response->getHeader('Units-Used-Login'));

$requestId = current($response->getHeader('RequestId'));

[$debit, $rest, $limit] = explode('/', current($response->getHeader('Units')));
Expand All @@ -143,6 +145,7 @@ protected function handleResponse(
'rest' => $rest,
'limit' => $limit
],
'units_used_login' => $unitsUsedLogin,
'result' => $parsedBody
];
}
Expand Down
10 changes: 5 additions & 5 deletions src/Credentials.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ final class Credentials implements \Gladyshev\Yandex\Direct\CredentialsInterface
{
private $token;
private $masterToken;
private $login;
private $clientLogin;
private $useOperatorUnits;
private $isAgency;
private $language;
Expand Down Expand Up @@ -36,7 +36,7 @@ public function __construct(
) {
$this->token = $token;
$this->masterToken = $masterToken;
$this->login = $clientLogin;
$this->clientLogin = $clientLogin;
$this->useOperatorUnits = $useOperatorUnits;
$this->language = $language;
$this->baseUrl = $baseUrl;
Expand All @@ -46,14 +46,14 @@ public function __construct(
public static function agency(
string $token,
?string $masterToken = null,
?string $login = null,
?string $clientLogin = null,
bool $useOperatorUnits = true,
string $language = self::LANGUAGE_RU
): self {
return new self(
$token,
$masterToken,
$login,
$clientLogin,
$useOperatorUnits,
true,
$language,
Expand Down Expand Up @@ -132,7 +132,7 @@ public function getMasterToken(): ?string
*/
public function getClientLogin(): ?string
{
return $this->login;
return $this->clientLogin;
}

/**
Expand Down

0 comments on commit b0ef3f5

Please sign in to comment.