Skip to content

Commit

Permalink
add: analytics api
Browse files Browse the repository at this point in the history
  • Loading branch information
nVuln committed Nov 26, 2024
1 parent 79800cc commit e3fbaa2
Show file tree
Hide file tree
Showing 3 changed files with 162 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use EcomPHP\TiktokShop\Resources\AffiliateCreator;
use EcomPHP\TiktokShop\Resources\AffiliatePartner;
use EcomPHP\TiktokShop\Resources\AffiliateSeller;
use EcomPHP\TiktokShop\Resources\Analytics;
use EcomPHP\TiktokShop\Resources\CustomerService;
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\HandlerStack;
Expand Down Expand Up @@ -91,6 +92,7 @@ class Client
AffiliateSeller::class,
AffiliateCreator::class,
AffiliatePartner::class,
Analytics::class,
];

public function __construct($app_key, $app_secret, $options = [])
Expand Down
83 changes: 83 additions & 0 deletions src/Resources/Analytics.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php
/*
* This file is part of tiktokshop-php.
*
* Copyright (c) 2024 Jin <j@sax.vn> All rights reserved.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace EcomPHP\TiktokShop\Resources;

use EcomPHP\TiktokShop\Resource;
use GuzzleHttp\RequestOptions;

class Analytics extends Resource
{
protected $category = 'analytics';
protected $minimum_version = 202405;

public function getShopPerformance($params = [])
{
return $this->call('GET', 'shop/performance', [
RequestOptions::QUERY => $params,
]);
}

public function getShopProductPerformance($product_id, $params = [])
{
return $this->call('GET', 'shop_products/'. $product_id .'/performance', [
RequestOptions::QUERY => $params,
]);
}

public function getShopProductPerformanceList($params = [])
{
return $this->call('GET', 'shop_products/performance', [
RequestOptions::QUERY => $params,
]);
}

public function getShopSkuPerformance($sku_id, $params = [])
{
return $this->call('GET', 'shop_skus/'. $sku_id .'/performance', [
RequestOptions::QUERY => $params,
]);
}

public function getShopSkuPerformanceList($params = [])
{
return $this->call('GET', 'shop_skus/performance', [
RequestOptions::QUERY => $params,
]);
}

public function getShopVideoPerformanceList($params = [])
{
return $this->call('GET', 'shop_videos/performance', [
RequestOptions::QUERY => $params,
]);
}

public function getShopVideoPerformanceOverview($params = [])
{
return $this->call('GET', 'shop_videos/overview_performance', [
RequestOptions::QUERY => $params,
]);
}

public function getShopVideoPerformance($video_id, $params = [])
{
return $this->call('GET', 'shop_videos/'. $video_id .'/performance', [
RequestOptions::QUERY => $params,
]);
}

public function getShopVideoProductPerformanceList($video_id, $params = [])
{
return $this->call('GET', 'shop_videos/'. $video_id .'/products/performance', [
RequestOptions::QUERY => $params,
]);
}
}
77 changes: 77 additions & 0 deletions tests/Resources/AnalyticsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php
/*
* This file is part of tiktokshop-php.
*
* Copyright (c) 2024 Jin <j@sax.vn> All rights reserved.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace EcomPHP\TiktokShop\Tests\Resources;

use EcomPHP\TiktokShop\Resources\Analytics;
use EcomPHP\TiktokShop\Tests\TestResource;

/**
* @property-read \EcomPHP\TiktokShop\Resources\Analytics $caller
*/
class AnalyticsTest extends TestResource
{
public const TEST_API_VERSION = 202405;

public function testGetShopPerformance()
{
$this->caller->getShopPerformance();
$this->assertPreviousRequest('GET', 'analytics/'.self::TEST_API_VERSION.'/shop/performance');
}

public function testGetShopProductPerformance()
{
$this->caller->getShopProductPerformance(123);
$this->assertPreviousRequest('GET', 'analytics/'.self::TEST_API_VERSION.'/shop_products/123/performance');
}

public function testGetShopProductPerformanceList()
{
$this->caller->getShopProductPerformanceList();
$this->assertPreviousRequest('GET', 'analytics/'.self::TEST_API_VERSION.'/shop_products/performance');
}

public function testGetShopSkuPerformance()
{
$this->caller->getShopSkuPerformance(123);
$this->assertPreviousRequest('GET', 'analytics/'.self::TEST_API_VERSION.'/shop_skus/123/performance');
}

public function testGetShopSkuPerformanceList()
{
$this->caller->getShopSkuPerformanceList();
$this->assertPreviousRequest('GET', 'analytics/'.self::TEST_API_VERSION.'/shop_skus/performance');
}

public function testGetShopVideoPerformance()
{
$this->caller->getShopVideoPerformance(123);
$this->assertPreviousRequest('GET', 'analytics/'.self::TEST_API_VERSION.'/shop_videos/123/performance');

}

public function testGetShopVideoPerformanceList()
{
$this->caller->getShopVideoPerformanceList();
$this->assertPreviousRequest('GET', 'analytics/'.self::TEST_API_VERSION.'/shop_videos/performance');
}

public function testGetShopVideoPerformanceOverview()
{
$this->caller->getShopVideoPerformanceOverview();
$this->assertPreviousRequest('GET', 'analytics/'.self::TEST_API_VERSION.'/shop_videos/overview_performance');
}

public function testGetShopVideoProductPerformanceList()
{
$this->caller->getShopVideoProductPerformanceList(123);
$this->assertPreviousRequest('GET', 'analytics/'.self::TEST_API_VERSION.'/shop_videos/123/products/performance');
}
}

0 comments on commit e3fbaa2

Please sign in to comment.