mirror of
https://github.com/cubixle/trustpilot-api-wrapper.git
synced 2026-04-24 23:44:47 +01:00
Updates.
Updated the review transformer to collect the author and removed setters as they are pointless here. Added new methods to the reviews controller and some sensible logic, so the API is not hit more than it needs to be.
This commit is contained in:
@@ -12,6 +12,11 @@ class Reviews
|
||||
*/
|
||||
private $client;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $responses = [];
|
||||
|
||||
/**
|
||||
* @param ApiWrapper $client
|
||||
*/
|
||||
@@ -51,15 +56,7 @@ class Reviews
|
||||
*/
|
||||
public function getTrustScore($queryParams = [])
|
||||
{
|
||||
$url = '/v1/business-units/' . $this->client->getBusinessUnitId();
|
||||
|
||||
$ratings = $this->client->getClient()->request(
|
||||
'GET',
|
||||
$url,
|
||||
array_merge($this->client->getDefaultHeaders(), ['query' => $queryParams])
|
||||
);
|
||||
|
||||
$data = json_decode($ratings->getBody()->getContents(), true);
|
||||
$data = $this->getBusinessUnit($queryParams);
|
||||
|
||||
return $data['trustScore'];
|
||||
}
|
||||
@@ -71,16 +68,45 @@ class Reviews
|
||||
*/
|
||||
public function getStarRating($queryParams = [])
|
||||
{
|
||||
$url = '/v1/business-units/' . $this->client->getBusinessUnitId();
|
||||
|
||||
$ratings = $this->client->getClient()->request(
|
||||
'GET',
|
||||
$url,
|
||||
array_merge($this->client->getDefaultHeaders(), ['query' => $queryParams])
|
||||
);
|
||||
|
||||
$data = json_decode($ratings->getBody()->getContents(), true);
|
||||
$data = $this->getBusinessUnit($queryParams);
|
||||
|
||||
return $data['stars'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $queryParams
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getTotalNumberOfReviews($queryParams = [])
|
||||
{
|
||||
$data = $this->getBusinessUnit($queryParams);
|
||||
|
||||
return $data['numberOfReviews']['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $queryParams
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
private function getBusinessUnit($queryParams = [])
|
||||
{
|
||||
if (isset($this->responses['business_units'])) {
|
||||
$response = $this->responses['business_units'];
|
||||
} else {
|
||||
$url = '/v1/business-units/' . $this->client->getBusinessUnitId();
|
||||
|
||||
$ratings = $this->client->getClient()->request(
|
||||
'GET',
|
||||
$url,
|
||||
array_merge($this->client->getDefaultHeaders(), ['query' => $queryParams])
|
||||
);
|
||||
|
||||
$response = $ratings->getBody()->getContents();
|
||||
$this->responses['business_units'] = $response;
|
||||
}
|
||||
|
||||
return json_decode($response, true);
|
||||
}
|
||||
}
|
||||
@@ -29,6 +29,11 @@ class ReviewTransformer
|
||||
*/
|
||||
private $rating;
|
||||
|
||||
/**
|
||||
* @var
|
||||
*/
|
||||
private $author;
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
@@ -37,14 +42,6 @@ class ReviewTransformer
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $review
|
||||
*/
|
||||
public function setTitle($title)
|
||||
{
|
||||
$this->title = $title;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
@@ -53,14 +50,6 @@ class ReviewTransformer
|
||||
return $this->review;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $review
|
||||
*/
|
||||
public function setReview($review)
|
||||
{
|
||||
$this->review = $review;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
@@ -69,14 +58,6 @@ class ReviewTransformer
|
||||
return $this->companyReply;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $companyReply
|
||||
*/
|
||||
public function setCompanyReply($companyReply)
|
||||
{
|
||||
$this->companyReply = $companyReply;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
@@ -85,14 +66,6 @@ class ReviewTransformer
|
||||
return $this->createdAt;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $createdAt
|
||||
*/
|
||||
public function setCreatedAt($createdAt)
|
||||
{
|
||||
$this->createdAt = $createdAt;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
@@ -101,14 +74,6 @@ class ReviewTransformer
|
||||
return $this->reviewLink;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $reviewLink
|
||||
*/
|
||||
public function setReviewLink($reviewLink)
|
||||
{
|
||||
$this->reviewLink = $reviewLink;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
@@ -118,11 +83,11 @@ class ReviewTransformer
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $rating
|
||||
* @return mixed
|
||||
*/
|
||||
public function setRating($rating)
|
||||
public function getAuthor()
|
||||
{
|
||||
$this->rating = $rating;
|
||||
return $this->author;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -148,12 +113,13 @@ class ReviewTransformer
|
||||
*/
|
||||
public function transform($review)
|
||||
{
|
||||
$reviewObj = new self;
|
||||
$reviewObj->setTitle($review['title']);
|
||||
$reviewObj->setReview($review['text']);
|
||||
$reviewObj->setCompanyReply($review['companyReply']['text']);
|
||||
$reviewObj->setRating($review['stars']);
|
||||
$reviewObj->setCreatedAt($review['createdAt']);
|
||||
$reviewObj = new self;
|
||||
$reviewObj->title = $review['title'];
|
||||
$reviewObj->review = $review['text'];
|
||||
$reviewObj->companyReply = $review['companyReply']['text'];
|
||||
$reviewObj->rating = $review['stars'];
|
||||
$reviewObj->createdAt = $review['createdAt'];
|
||||
$reviewObj->author = trim($review['consumer']['displayName']);
|
||||
|
||||
return $reviewObj;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user