-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
McCaulay Hudson
committed
Mar 20, 2020
1 parent
4de164a
commit 0972961
Showing
10 changed files
with
211 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<?php | ||
namespace McCaulay\Trustpilot\API\BusinessUnit; | ||
|
||
use McCaulay\Trustpilot\Api; | ||
use McCaulay\Trustpilot\API\BusinessUnit\Review\Product\ProductReviewSummary; | ||
use McCaulay\Trustpilot\Query\Builder; | ||
|
||
class ProductApi extends Api | ||
{ | ||
/** | ||
* The business unit id. | ||
* | ||
* @var int | ||
*/ | ||
public $businessUnitId = null; | ||
|
||
/** | ||
* Initialise the business unit product reviews with an optional business unit id. | ||
* If no business unit id is given, it uses the business unit from the config. | ||
* | ||
* @param null|string $businessUnitId | ||
*/ | ||
public function __construct(?string $businessUnitId = null) | ||
{ | ||
parent::__construct(); | ||
$this->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); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
namespace McCaulay\Trustpilot\API\BusinessUnit\Review\Product; | ||
|
||
use McCaulay\Trustpilot\API\Resource; | ||
|
||
class ProductReview extends Resource | ||
{ | ||
// | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
namespace McCaulay\Trustpilot\API\BusinessUnit\Review\Product; | ||
|
||
use Illuminate\Support\Collection; | ||
use McCaulay\Trustpilot\API\BusinessUnit\Review; | ||
use McCaulay\Trustpilot\API\ResourceApi; | ||
|
||
class ProductReviewApi extends ResourceApi | ||
{ | ||
/** | ||
* The business unit id. | ||
* | ||
* @var int | ||
*/ | ||
public $businessUnitId = null; | ||
|
||
/** | ||
* Initialise the business unit product reviews with an optional business unit id. | ||
* If no business unit id is given, it uses the business unit from the config. | ||
* | ||
* @param null|string $businessUnitId | ||
*/ | ||
public function __construct(?string $businessUnitId = null) | ||
{ | ||
parent::__construct(); | ||
$this->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); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
namespace McCaulay\Trustpilot\API\BusinessUnit\Review\Product; | ||
|
||
use McCaulay\Trustpilot\API\Resource; | ||
|
||
class ProductReviewSummary extends Resource | ||
{ | ||
// | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters