Skip to content

Commit

Permalink
Version 2.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
a.pushkarev committed May 30, 2022
1 parent 761505d commit 2e44053
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
3. [Ответ](#Ответ)
+ [Чистые данные](#Чистые-данные)
+ [Отформатированные данные](#Отформатированные-данные)
+ [Свой формат данных](#Свой-формат-данных)
4. [Автор](#Автор)
5. [Лицензия](#Лицензия)

Expand Down Expand Up @@ -54,6 +55,7 @@ $metrika = new YaMetrika($client);
+ [Данные о посещаемости](https://github.com/axp-dev/ya-metrika/blob/master/example/visitors.php)
+ [Логирование запросов](https://github.com/axp-dev/ya-metrika/blob/master/example/logger.php)
+ [Использование Proxy](https://github.com/axp-dev/ya-metrika/blob/master/example/proxy.php)
+ [Использование custom format](https://github.com/axp-dev/ya-metrika/blob/master/example/format.php)

## Использование
### Данные по посещаемости
Expand Down Expand Up @@ -242,6 +244,12 @@ public function rawData(): array
public function formatData(): array
```

### Свой формат данных
Возвращает отформатированные данные. Будут переименованы поля, удалены ненужные префиксы.
```php
public function customFormat(callable $callback): array
```

## Автор
[Alexander Pushkarev](https://github.com/axp-dev), e-mail: [[email protected]](mailto:[email protected])

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Yandex Metrika API Library",
"homepage": "https://github.com/axp-dev/ya-metrika",
"keywords": ["yandex", "metrika", "api"],
"version": "2.0.0",
"version": "2.1.0",
"license": "MIT",
"authors": [
{
Expand Down
17 changes: 17 additions & 0 deletions example/format.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

use AXP\YaMetrika\Client;
use AXP\YaMetrika\YaMetrika;

$token = getenv('TOKEN');
$counterId = getenv('COUNTER_ID');

$client = new Client($token, $counterId);
$metrika = new YaMetrika($client);

$visitors = $metrika->getVisitors();
$totals = $visitors->customFormat(function ($data) {
return $data['totals'];
});

print_r($totals);
5 changes: 5 additions & 0 deletions src/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ public function rawData(): array
return $this->data;
}

public function customFormat(callable $callback): array
{
return $callback($this->data);
}

private function combineData(string $column, array $array): array
{
$queryColumn = array_map(function($key) {
Expand Down

0 comments on commit 2e44053

Please sign in to comment.