Webador / sendcloud

Provides a PHP client to interact with the SendCloud API in an object-oriented way.
MIT License
16 stars 15 forks source link

Suggestion : moving service point methods to new class #34

Closed AlexisPPLIN closed 8 months ago

AlexisPPLIN commented 8 months ago

As I stated in my PR #33, service points endpoints uses a different url : https://servicepoints.sendcloud.sc/api/v2/.

This can quite a bit confusing to use :

use JouwWeb\Sendcloud\Client;

$client = new Client('your_public_key', 'your_secret_key');
$client->getUser(); // HTTP 200 OK
$client->searchServicePoints('NL'); // HTTP 404 NOT FOUND

$client_2 = new Client('your_public_key', 'your_secret_key', null, 'https://servicepoints.sendcloud.sc/api/v2/');
$client_2->getUser(); // HTTP 404 NOT FOUND
$client_2->searchServicePoints('NL'); // HTTP 200

So I suggest something like this :

So now :

use JouwWeb\Sendcloud\Client;
use JouwWeb\Sendcloud\ServicePointsClient;

$client = new Client('your_public_key', 'your_secret_key');
$client->getUser(); // HTTP 200 OK
$client->searchServicePoints('NL'); // Method does not exist

$client_2 = new ServicePointsClient('your_public_key', 'your_secret_key');
$client_2->getUser(); // Method does not exist
$client_2->searchServicePoints('NL'); // HTTP 200 OK

Is this a good idea ?