Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Analyzer #38

Merged
merged 4 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Generator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
phpClientWriter.GenerateClientClass(typeof(Searcher), new[] { "Search", "Predict", "Batch" });
phpClientWriter.GenerateClientClass(typeof(Recommender), new[] { "Recommend" });
phpClientWriter.GenerateClientClass(typeof(SearchAdministrator), new[] { "Delete", "Save", "Load" });
phpClientWriter.GenerateClientClass(typeof(Analyzer), new[] { "Analyze" });

if (phpWriter.MissingTypeDefinitions.Count > 0)
{
Expand Down
24 changes: 24 additions & 0 deletions src/Analyzer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php declare(strict_types=1);

namespace Relewise;

use Relewise\Infrastructure\HttpClient\Response;
use Relewise\Models\ProductPerformanceRequest;
use Relewise\Models\ProductPerformanceResponse;

class Analyzer extends RelewiseClient
{
public function __construct(private string $datasetId, private string $apiKey, private int $timeout = 120)
{
parent::__construct($datasetId, $apiKey, $timeout);
}
public function productPerformance(ProductPerformanceRequest $request) : ?ProductPerformanceResponse
KSGRelewise marked this conversation as resolved.
Show resolved Hide resolved
{
$response = $this->requestAndValidate("ProductPerformanceRequest", $request);
if ($response == Null)
{
return Null;
}
return ProductPerformanceResponse::hydrate($response);
}
}
40 changes: 40 additions & 0 deletions tests/php/integration/ProductPerformanceTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php


namespace Relewise\Tests\Integration;

use Relewise\Analyzer;
use Relewise\Models\ProductPerformanceRequest;
use Relewise\Models\ProductPerformanceRequestOrderByOptions;
use Relewise\Models\stringstringKeyValuePair;
use Relewise\Models\ProductPerformanceResult;
use Relewise\Tests\Integration\BaseTestCase;

class ProductPerformanceTest extends BaseTestCase
{
public function testProductPerformanceRequest(): void
{
$analyzer = new Analyzer($this->DATASET_ID(), $this->API_KEY());

$request = ProductPerformanceRequest::create(
language: null,
currency: null,
byVariant: false,
numberOfResultsPerRequest: 10,
skipNumberOfResults: 0
)->setOrderBy(ProductPerformanceRequestOrderByOptions::RankBySales)
->setFromUnixTimeSeconds(time() - 60 * 60 * 24 * 30)
->setToUnixTimeSeconds(time())
->addToClassifications(stringstringKeyValuePair::create("Country", "DK"));

$response = $analyzer->productPerformance($request);

self::assertNotNull($response);
/** @var ProductPerformanceResult $first */
$first = $response->results[0];
/** @var ProductPerformanceResult $second */
$fifth = $response->results[4]; // This might be flaky. It is just to check that some element lower down has a smaller

self::assertTrue($first->classifications[0]->sales->orders > $fifth->classifications[0]->sales->orders);
}
}
Loading