Skip to content

Commit

Permalink
Replace Guzzle with Guzzle Adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
Quetzacoalt91 committed Jul 13, 2023
1 parent df67b5b commit 3435b7f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 18 deletions.
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
],
"homepage": "https://developers.facebook.com/",
"require": {
"php": ">=8.0",
"guzzlehttp/guzzle": "^6.5 || ^7.0"
"prestashop/module-lib-guzzle-adapter": "^0.5"
},
"require-dev": {
"phpunit/phpunit": "~9",
Expand Down
24 changes: 10 additions & 14 deletions src/FacebookAds/Object/ServerSide/AsyncClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,21 @@

use FacebookAds\Api;

use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Handler\CurlHandler;
use Prestashop\ModuleLibGuzzleAdapter\ClientFactory;
use Psr\Http\Client\ClientInterface;

class AsyncClient extends Singleton {
/**
* @var ClientInterface
*/
protected $client = null;

public function __construct() {
$handler_stack = HandlerStack::create(new CurlHandler([
'options' => [
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_TIMEOUT => 60,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HEADER => true,
CURLOPT_CAINFO => Api::instance()->getHttpClient()->getCaBundlePath(),
]
]));

$this->client = new Client(['handler' => $handler_stack]);
$this->client = (new ClientFactory())->getClient([
'connect_timeout' => 10,
'timeout' => 60,
'verify' => Api::instance()->getHttpClient()->getCaBundlePath(),
]);
}

public function getClient() {
Expand Down
4 changes: 2 additions & 2 deletions src/FacebookAds/Object/ServerSide/EventRequestAsync.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ private function eventPromise($pixel_id, array $params = array()) {

$url = $base_url.'/'.$pixel_id.'/events';

$events_json = \GuzzleHttp\json_encode($params['data']);
$events_json = json_encode($params['data']);
$multipart_contents = [
[
'name' => 'access_token',
Expand Down Expand Up @@ -107,6 +107,6 @@ private function eventPromise($pixel_id, array $params = array()) {
$request = new Request('POST', $url, $headers, $body);

$client = AsyncClient::getInstance()->getClient();
return $client->sendAsync($request);
return $client->sendRequest($request);
}
}

0 comments on commit 3435b7f

Please sign in to comment.