Skip to content

Commit

Permalink
add: custom http request method from client
Browse files Browse the repository at this point in the history
  • Loading branch information
nVuln committed Jul 17, 2024
1 parent 85c2c38 commit 49e6f47
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@

namespace EcomPHP\TiktokShop;

use EcomPHP\TiktokShop\Errors\ResponseException;
use EcomPHP\TiktokShop\Resources\AffiliateCreator;
use EcomPHP\TiktokShop\Resources\AffiliateSeller;
use EcomPHP\TiktokShop\Resources\CustomerService;
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Client as GuzzleHttpClient;
use GuzzleHttp\Middleware;
Expand Down Expand Up @@ -265,4 +267,32 @@ public function __get($resourceName)
return $resource;
}

public function call($method, $uri, $params = [])
{
try {
$response = $this->httpClient()->request($method, $uri, $params);
} catch (GuzzleException $e) {
throw new ResponseException($e->getMessage(), $e->getCode(), $e);
}

$json = json_decode((string) $response->getBody(), true);

if ($json === null) {
throw new ResponseException('Unable to parse response string as JSON');
}

return $json;
}

public function get($uri)
{
return $this->call('GET', $uri);
}

public function post($uri, $data)
{
return $this->call('POST', $uri, [
RequestOptions::JSON => $data,
]);
}
}

0 comments on commit 49e6f47

Please sign in to comment.