Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
4rthem committed Oct 13, 2023
1 parent 065f1a1 commit 9deb131
Show file tree
Hide file tree
Showing 10 changed files with 265 additions and 20 deletions.
5 changes: 5 additions & 0 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,11 @@ services:
- SECRETS_PUBLIC_KEY=${DATABOX_SECRETS_PUBLIC_KEY}
- SECRETS_SECRET_KEY=${DATABOX_SECRETS_SECRET_KEY}
- ALLOWED_FILE_TYPES=${UPLOADER_ALLOWED_FILE_TYPES}
- MATOMO_BASE_URL
- MATOMO_SITE_ID=${EXPOSE_MATOMO_SITE_ID}
- MATOMO_AUTH_TOKEN
- PHRASEANET_APP_OAUTH_TOKEN
- PHRASEANET_BASE_URL
working_dir: /var/workspace
volumes:
- ./:/var/workspace
Expand Down
5 changes: 5 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,11 @@ services:
- CLOUD_FRONT_PRIVATE_KEY=${EXPOSE_CLOUD_FRONT_PRIVATE_KEY}
- CLOUD_FRONT_KEY_PAIR_ID=${EXPOSE_CLOUD_FRONT_KEY_PAIR_ID}
- CLOUD_FRONT_TTL=${EXPOSE_CLOUD_FRONT_TTL}
- MATOMO_BASE_URL
- MATOMO_SITE_ID=${EXPOSE_MATOMO_SITE_ID}
- MATOMO_AUTH_TOKEN
- PHRASEANET_APP_OAUTH_TOKEN
- PHRASEANET_BASE_URL
extra_hosts:
- zippy-svc.${PHRASEA_DOMAIN}:${PS_GATEWAY_IP}

Expand Down
3 changes: 2 additions & 1 deletion expose/api/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@
"alchemy/storage-bundle": "@dev",
"api-platform/core": "2.6.8",
"arthem/rabbit-bundle": "dev-master",
"php-amqplib/rabbitmq-bundle": "dev-master as 2.11.0",
"composer/package-versions-deprecated": "1.11.99.3",
"doctrine/annotations": "^1.0",
"doctrine/common": "^3.4.3",
Expand All @@ -98,6 +97,7 @@
"exercise/htmlpurifier-bundle": "^2.0",
"lcobucci/jwt": "^4.1",
"nelmio/cors-bundle": "^1.5",
"php-amqplib/rabbitmq-bundle": "dev-master as 2.11.0",
"phpdocumentor/reflection-docblock": "^5.2",
"predis/predis": "^1.1",
"ramsey/uuid-doctrine": "^1.5",
Expand All @@ -108,6 +108,7 @@
"symfony/expression-language": "^4.4",
"symfony/flex": "^1.3.1",
"symfony/framework-bundle": "^4.4",
"symfony/http-client": "^4.4",
"symfony/property-access": "^4.4",
"symfony/property-info": "^4.4",
"symfony/psr-http-message-bridge": "^2.1.4",
Expand Down
106 changes: 94 additions & 12 deletions expose/api/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions expose/api/config/packages/framework.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,12 @@ framework:
version: v1
base_urls:
- '%env(EXPOSE_API_BASE_URL)%'

http_client:
default_options:
verify_peer: '%env(bool:VERIFY_SSL)%'
scoped_clients:
matomo.client:
base_uri: '%env(MATOMO_BASE_URL)%'
phraseanet.client:
base_uri: '%env(PHRASEANET_BASE_URL)%'
3 changes: 3 additions & 0 deletions expose/api/config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ services:
autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
bind:
$zippyBaseUrl: '%env(ZIPPY_BASE_URL)%'
string $matomoSiteId: '%env(MATOMO_SITE_ID)%'
string $matomoAuthToken: '%env(MATOMO_AUTH_TOKEN)%'
string $phraseanetAuthToken: '%env(PHRASEANET_APP_OAUTH_TOKEN)%'
# makes classes in src/ available to be used as services
# this creates a service per class whose id is the fully-qualified class name
App\:
Expand Down
44 changes: 44 additions & 0 deletions expose/api/src/Matomo/MatomoClient.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

declare(strict_types=1);

namespace App\Matomo;

use Symfony\Contracts\HttpClient\HttpClientInterface;

final class MatomoClient
{
private HttpClientInterface $client;
private string $matomoSiteId;
private string $authToken;

public function __construct(
HttpClientInterface $matomoClient,
string $matomoSiteId,
string $matomoAuthToken
)
{
$this->client = $matomoClient;
$this->matomoSiteId = $matomoSiteId;
$this->authToken = $matomoAuthToken;
}

public function getStats(int $offset = 0, int $limit = 100): array
{
$response = $this->client->request('GET', '/', [
'query' => [
'module' => 'API',
'idSite' => $this->matomoSiteId,
'method' => 'MediaAnalytics.getGroupedVideoResources',
'format' => 'JSON',
'token_auth' => $this->authToken,
'date' => '2000-01-01,'.date('Y-m-d'),
'period' => 'range',
'filter_offset' => $offset,
'filter_limit' => $limit,
]
]);

return $response->toArray();
}
}
45 changes: 45 additions & 0 deletions expose/api/src/Matomo/PhraseanetClient.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

declare(strict_types=1);

namespace App\Matomo;

use Symfony\Contracts\HttpClient\HttpClientInterface;

final class PhraseanetClient
{
private HttpClientInterface $client;
private string $authToken;

public function __construct(
HttpClientInterface $phraseanetClient,
string $phraseanetAuthToken
)
{
$this->client = $phraseanetClient;
$this->authToken = $phraseanetAuthToken;
}

public function patchField(array $stat): void
{
if (0 === preg_match('#^(?:\./)?\w+_(\d+)_(\d+)$#', $stat['label'], $regs)) {
return;
}

list(, $baseId, $recordId) = $regs;

unset($stat['label']);
unset($stat['idsubdatatable']);

$this->client->request('GET', sprintf('/records/%s/%s', $baseId, $recordId), [
'json' => [
'metadatas' => [
[
'field_name' => 'matomo_media_metrics',
'value' => \GuzzleHttp\json_encode($stat)
]
]
]
]);
}
}
Loading

0 comments on commit 9deb131

Please sign in to comment.