diff --git a/README.md b/README.md index fed83cc..ef1859c 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ TRUSTPILOT_ACCESS_TOKEN= - Consumer Profile API - Invitation API - Private Products API -- Private Reviews API +- Product Reviews API -> Conversations, Invitation Link - Resources API - Service Reviews API - BUsiness Units API (Private Reviews) @@ -81,6 +81,48 @@ $reviews = Trustpilot::businessUnit() ->get() ->pluck('title'); +// Get the the first 10 product reviews of your business that are 4 or 5 stars for the specific products. +$productReviews = Trustpilot::businessUnit() + ->products()->reviews() + ->where('sku', [ + 'product_1_sku_here', + 'product_2_sku_here', + ]) + ->where('stars', [4, 5]) + ->get(); + +// Get the joined product review summary of the two specific products for your business. +$productReviewSummary = Trustpilot::businessUnit() + ->products() + ->reviewSummary([ + 'product_1_sku_here', + 'product_2_sku_here', + ]); + +// Get the joined product review summary of the two specific products for your business by URL. +$productReviewSummary = Trustpilot::businessUnit() + ->products() + ->reviewSummary([], [ + 'https://www.example.com/product_1', + 'https://www.example.com/product_2', + ]); + +// Get the aggregated product review summary of the two specific products for your business. +$aggregatedProductReviewSummaries = Trustpilot::businessUnit() + ->products() + ->reviewAggregatedSummaries([ + 'product_1_sku_here', + 'product_2_sku_here', + ]); + +// Get the batched product review summary of the two specific products for your business. +$productReviewSummaries = Trustpilot::businessUnit() + ->products() + ->reviewBatchSummaries([ + 'product_1_sku_here', + 'product_2_sku_here', + ]); + // Get the web links of your business. $webLinks = Trustpilot::businessUnit()->webLinks(); diff --git a/src/API/Api.php b/src/API/Api.php index e7036da..9d7981e 100644 --- a/src/API/Api.php +++ b/src/API/Api.php @@ -87,7 +87,7 @@ protected function request(string $method, string $path, array $query = [], arra { $response = $this->client->request($method, $this->endpoint . $this->path . $path, [ 'query' => $query, - 'form_params' => $params, + 'json' => $params, ]); $contents = (string) $response->getBody(); return json_decode($contents); diff --git a/src/API/BusinessUnit/BusinessUnit.php b/src/API/BusinessUnit/BusinessUnit.php index 5f142de..4ebeacc 100644 --- a/src/API/BusinessUnit/BusinessUnit.php +++ b/src/API/BusinessUnit/BusinessUnit.php @@ -1,6 +1,7 @@ id)); } + /** + * Get the products api. + * + * @return \McCaulay\Trustpilot\API\BusinessUnit\ProductApi + */ + public function products(): ProductApi + { + return new ProductApi($this->id); + } + /** * Load the business information. * diff --git a/src/API/BusinessUnit/ProductApi.php b/src/API/BusinessUnit/ProductApi.php new file mode 100644 index 0000000..1ef70b1 --- /dev/null +++ b/src/API/BusinessUnit/ProductApi.php @@ -0,0 +1,91 @@ +businessUnitId = $businessUnitId ?? config('trustpilot.unit_id'); + } + + /** + * Get the queried product reviews. + * + * @return \McCaulay\Trustpilot\Query\Builder + */ + public function reviews(): Builder + { + return new Builder(new Review\Product\ProductReviewApi($this->businessUnitId)); + } + + /** + * Get the joint products review summary. + * + * @param array $skus + * @param array $urls + * @return mixed + */ + public function reviewSummary(array $skus = [], array $urls = []) + { + $response = $this->get('/product-reviews/business-units/' . $this->businessUnitId, array_filter([ + 'sku' => $skus, + 'productUrl' => $urls, + ])); + + return (new ProductReviewSummary())->data($response); + } + + /** + * Get the aggregated business product review summaries. + * + * @param array $skus + * @param string $locale + * @return mixed + */ + public function reviewAggregatedSummaries(array $skus = [], string $locale = 'en-GB') + { + $response = $this->post('/product-reviews/business-units/' . $this->businessUnitId . '/attribute-summaries', [], array_filter([ + 'skus' => $skus, + 'locale' => $locale, + ])); + + return collect($response->summaries)->map(function ($summary) { + return (new ProductReviewSummary())->data($summary); + }); + } + + /** + * Get the business product review summaries. + * + * @param array $skus + * @return mixed + */ + public function reviewBatchSummaries(array $skus = []) + { + $response = $this->post('/product-reviews/business-units/' . $this->businessUnitId . '/batch-summaries', [], array_filter([ + 'skus' => $skus, + ])); + + return collect($response->summaries)->map(function ($summary) { + return (new ProductReviewSummary())->data($summary); + }); + } +} diff --git a/src/API/BusinessUnit/Review/Product/ProductReview.php b/src/API/BusinessUnit/Review/Product/ProductReview.php new file mode 100644 index 0000000..87948d2 --- /dev/null +++ b/src/API/BusinessUnit/Review/Product/ProductReview.php @@ -0,0 +1,9 @@ +businessUnitId = $businessUnitId ?? config('trustpilot.unit_id'); + $this->setPath('/product-reviews/business-units/' . $this->businessUnitId); + } + + /** + * Perform the query and get the results. + * + * @param array $query + * @param bool $search + * @return \Illuminate\Support\Collection; + */ + public function perform(array $query, bool $search = false): Collection + { + $response = $this->get('/reviews', $query); + return collect($response->productReviews)->map(function ($productReview) { + return (new ProductReview())->data($productReview); + }); + } +} diff --git a/src/API/BusinessUnit/Review/Product/ProductReviewSummary.php b/src/API/BusinessUnit/Review/Product/ProductReviewSummary.php new file mode 100644 index 0000000..d42af1e --- /dev/null +++ b/src/API/BusinessUnit/Review/Product/ProductReviewSummary.php @@ -0,0 +1,9 @@ +