Skip to content

Commit

Permalink
Update to current dependency versions
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan-Simon Winkelmann committed Oct 15, 2020
1 parent b0bb214 commit a8889a4
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 66 deletions.
9 changes: 4 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@
}
],
"require": {
"guzzlehttp/guzzle": "^6.1",
"nesbot/carbon": "~1.20 || ^2.0"
},
"require-dev": {
"phpunit/phpunit": "4.0.*"
"php": "^7.1",
"ext-json": "*",
"guzzlehttp/guzzle": "^7.2",
"nesbot/carbon": "^2.0"
},
"autoload": {
"psr-4": {"TrustPilot\\": "src/TrustPilot"}
Expand Down
21 changes: 3 additions & 18 deletions src/TrustPilot/Adapter/AdapterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,19 @@ interface AdapterInterface
* @param string $url
* @param array $options
*
* @throws HttpException
*
* @return string
*/
public function get($url, $options = []);

/**
* @param string $url
* @return mixed
*/
public function delete($url);
public function get(string $url, array $options = []);

/**
* @param string $url
* @param string $content
* @return mixed
*/
public function put($url, $content = '');

/**
* @param string $url
* @param string $content
* @return mixed
*/
public function post($url, $content = '');
public function post(string $url, array $content = []);

/**
* @return string[]|null
*/
public function getLatestResponseHeaders();
}
}
53 changes: 13 additions & 40 deletions src/TrustPilot/Adapter/GuzzleHttpAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
use GuzzleHttp\Client;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Message\ResponseInterface;
use GuzzleHttp\Psr7\Response;

class GuzzleHttpAdapter implements AdapterInterface
{
Expand All @@ -40,11 +38,11 @@ class GuzzleHttpAdapter implements AdapterInterface
/**
* guzzle_http_adapter constructor.
*
* @param $headers
* @param array $headers
* @param string $endpoint
* @param ClientInterface|NULL $client
*/
public function __construct($headers, $endpoint = '', ClientInterface $client = null)
public function __construct(array $headers, string $endpoint = '', ?ClientInterface $client = null)
{

$this->endpoint = $endpoint;
Expand All @@ -55,41 +53,13 @@ public function __construct($headers, $endpoint = '', ClientInterface $client =
/**
* {@inheritdoc}
*/
public function get($url, $options = array())
public function get(string $url, array $options = [])
{
try {
$this->response = $this->client->get($this->endpoint.$url,$options);

} catch (RequestException $e) {
$this->response = $e->getResponse();
$this->handleError();
}

return $this->response->getBody();
}

/**
* {@inheritdoc}
*/
public function delete($url)
{
try {
$this->response = $this->client->delete($this->endpoint.$url);
} catch (RequestException $e) {
$this->response = $e->getResponse();
$this->handleError();
}

return $this->response->getBody();
}

/**
* {@inheritdoc}
*/
public function put($url, $content = '')
{
try {
$this->response = $this->client->put($this->endpoint.$url, $content);
$this->response = $this->client->get(
$this->endpoint . $url,
$options
);
} catch (RequestException $e) {
$this->response = $e->getResponse();
$this->handleError();
Expand All @@ -101,10 +71,13 @@ public function put($url, $content = '')
/**
* {@inheritdoc}
*/
public function post($url, $content = '')
public function post(string $url, array $content = [])
{
try {
$this->response = $this->client->post($this->endpoint.$url, $content);
$this->response = $this->client->post(
$this->endpoint . $url,
$content
);
} catch (RequestException $e) {
$this->response = $e->getResponse();
$this->handleError();
Expand Down Expand Up @@ -142,4 +115,4 @@ protected function handleError()

throw new HttpException(isset($content) ? print_r($content,true) : 'Request not processed.', $code);
}
}
}
6 changes: 3 additions & 3 deletions src/TrustPilot/Api/Authorize.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ protected function createToken($type,$data)

return $response = json_decode($this->api->post(
'oauth/oauth-business-users-for-applications/accesstoken',
array(
[
'form_params' => $fullBody
)
]
));
}

Expand Down Expand Up @@ -171,4 +171,4 @@ public function isValidToken()

}

}
}

0 comments on commit a8889a4

Please sign in to comment.