From e3fbaa2a7ae8a6f042580932a646170731ca63eb Mon Sep 17 00:00:00 2001 From: nVuln Date: Tue, 26 Nov 2024 10:56:37 +0700 Subject: [PATCH] add: analytics api --- src/Client.php | 2 + src/Resources/Analytics.php | 83 +++++++++++++++++++++++++++++++ tests/Resources/AnalyticsTest.php | 77 ++++++++++++++++++++++++++++ 3 files changed, 162 insertions(+) create mode 100644 src/Resources/Analytics.php create mode 100644 tests/Resources/AnalyticsTest.php diff --git a/src/Client.php b/src/Client.php index 4e65c78..24bc09f 100644 --- a/src/Client.php +++ b/src/Client.php @@ -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; @@ -91,6 +92,7 @@ class Client AffiliateSeller::class, AffiliateCreator::class, AffiliatePartner::class, + Analytics::class, ]; public function __construct($app_key, $app_secret, $options = []) diff --git a/src/Resources/Analytics.php b/src/Resources/Analytics.php new file mode 100644 index 0000000..9209b46 --- /dev/null +++ b/src/Resources/Analytics.php @@ -0,0 +1,83 @@ + 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, + ]); + } +} diff --git a/tests/Resources/AnalyticsTest.php b/tests/Resources/AnalyticsTest.php new file mode 100644 index 0000000..8c4863c --- /dev/null +++ b/tests/Resources/AnalyticsTest.php @@ -0,0 +1,77 @@ + 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'); + } +}