Skip to content

Commit

Permalink
Rename SendCloud => Sendcloud (rebranding)
Browse files Browse the repository at this point in the history
  • Loading branch information
villermen committed Jul 4, 2023
1 parent 65529ad commit 2b82a52
Show file tree
Hide file tree
Showing 19 changed files with 127 additions and 128 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ please request it through a GitHub issue or pull request.
## Example

```php
use JouwWeb\SendCloud\Client;
use JouwWeb\SendCloud\Model\Address;
use JouwWeb\SendCloud\Model\Parcel;
use JouwWeb\SendCloud\Model\ParcelItem;
use JouwWeb\SendCloud\Model\WebhookEvent;
use JouwWeb\SendCloud\Exception\SendCloudRequestException;
use JouwWeb\Sendcloud\Client;
use JouwWeb\Sendcloud\Model\Address;
use JouwWeb\Sendcloud\Model\Parcel;
use JouwWeb\Sendcloud\Model\ParcelItem;
use JouwWeb\Sendcloud\Model\WebhookEvent;
use JouwWeb\Sendcloud\Exception\SendcloudRequestException;

$client = new Client('your_public_key', 'your_secret_key');

Expand Down Expand Up @@ -52,7 +52,7 @@ try {
$pdf = $client->getLabelPdf($parcel, Parcel::LABEL_FORMAT_A4_BOTTOM_RIGHT);

var_dump($parcel, $pdf);
} catch (SendCloudRequestException $exception) {
} catch (SendcloudRequestException $exception) {
echo $exception->getMessage();
}

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
},
"autoload": {
"psr-4": {
"JouwWeb\\SendCloud\\": "src"
"JouwWeb\\Sendcloud\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"Test\\JouwWeb\\SendCloud\\": "test"
"Test\\JouwWeb\\Sendcloud\\": "test"
}
},
"config": {
Expand Down
83 changes: 41 additions & 42 deletions src/Client.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
<?php

namespace JouwWeb\SendCloud;
namespace JouwWeb\Sendcloud;

use GuzzleHttp\Exception\ConnectException;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Exception\TransferException;
use GuzzleHttp\Utils;
use JouwWeb\SendCloud\Exception\SendCloudClientException;
use JouwWeb\SendCloud\Exception\SendCloudRequestException;
use JouwWeb\SendCloud\Exception\SendCloudStateException;
use JouwWeb\SendCloud\Exception\SendCloudWebhookException;
use JouwWeb\SendCloud\Model\Address;
use JouwWeb\SendCloud\Model\Parcel;
use JouwWeb\SendCloud\Model\ParcelItem;
use JouwWeb\SendCloud\Model\SenderAddress;
use JouwWeb\SendCloud\Model\ShippingMethod;
use JouwWeb\SendCloud\Model\User;
use JouwWeb\SendCloud\Model\WebhookEvent;
use JouwWeb\Sendcloud\Exception\SendcloudClientException;
use JouwWeb\Sendcloud\Exception\SendcloudRequestException;
use JouwWeb\Sendcloud\Exception\SendcloudStateException;
use JouwWeb\Sendcloud\Exception\SendcloudWebhookException;
use JouwWeb\Sendcloud\Model\Address;
use JouwWeb\Sendcloud\Model\Parcel;
use JouwWeb\Sendcloud\Model\ParcelItem;
use JouwWeb\Sendcloud\Model\SenderAddress;
use JouwWeb\Sendcloud\Model\ShippingMethod;
use JouwWeb\Sendcloud\Model\User;
use JouwWeb\Sendcloud\Model\WebhookEvent;
use Psr\Http\Message\RequestInterface;

/**
Expand Down Expand Up @@ -58,7 +58,7 @@ public function __construct(
/**
* Fetches basic details about the Sendcloud account.
*
* @throws SendCloudRequestException
* @throws SendcloudRequestException
*/
public function getUser(): User
{
Expand All @@ -77,7 +77,7 @@ public function getUser(): User
* account's sender addresses will be retrieved when null.
* @param bool $returnMethodsOnly When true, methods for making a return are returned instead.
* @return ShippingMethod[]
* @throws SendCloudClientException
* @throws SendcloudClientException
*/
public function getShippingMethods(
?int $servicePointId = null,
Expand Down Expand Up @@ -151,7 +151,7 @@ public function getShippingMethods(
* @param ?ShippingMethod $shippingMethod
* @param string|null $errors One of {@see Parcel::ERRORS_VERBOSE}.
* @return Parcel
* @throws SendCloudRequestException
* @throws SendcloudRequestException
*/
public function createParcel(
Address $shippingAddress,
Expand Down Expand Up @@ -212,7 +212,7 @@ public function createParcel(
* @param int $quantity Number of parcels to generate for multi-collo shipment.
* @param string|null $errors One of {@see Parcel::ERRORS_VERBOSE}.
* @return Parcel[]
* @throws SendCloudRequestException
* @throws SendcloudRequestException
*/
public function createMultiParcel(
Address $shippingAddress,
Expand Down Expand Up @@ -282,7 +282,7 @@ public function createMultiParcel(
/**
* Update details of an existing parcel.
*
* @throws SendCloudRequestException
* @throws SendcloudRequestException
*/
public function updateParcel(Parcel|int $parcel, Address $shippingAddress): Parcel
{
Expand Down Expand Up @@ -310,16 +310,15 @@ public function updateParcel(Parcel|int $parcel, Address $shippingAddress): Parc

return Parcel::fromData(json_decode((string)$response->getBody(), true)['parcel']);
} catch (TransferException $exception) {
throw $this->parseGuzzleException($exception, 'Could not update parcel in SendCloud.');
throw $this->parseGuzzleException($exception, 'Could not update parcel in Sendcloud.');
}
}

/**
* Request a label for an existing parcel.
* @param SenderAddress|Address|int|null $senderAddress Passing null will pick Sendcloud's default. An Address will
* @param SenderAddress|Address|int|null $senderAddress Passing null will pick Sendcloud's default. An Address will
* use undocumented behavior that will disable branding personalizations.
* @throws SendCloudRequestException
* @throws SendcloudRequestException
*/
public function createLabel(Parcel|int $parcel, ShippingMethod|int $shippingMethod, SenderAddress|Address|int|null $senderAddress): Parcel
{
Expand Down Expand Up @@ -354,7 +353,7 @@ public function createLabel(Parcel|int $parcel, ShippingMethod|int $shippingMeth
/**
* Cancels or deletes a parcel (depending on status). Returns whether the parcel was successfully cancelled.
*
* @throws SendCloudRequestException
* @throws SendcloudRequestException
*/
public function cancelParcel(Parcel|int $parcel): bool
{
Expand All @@ -381,7 +380,7 @@ public function cancelParcel(Parcel|int $parcel): bool
*
* @param int $format `Parcel::LABEL_FORMATS`
* @return string PDF data.
* @throws SendCloudClientException
* @throws SendcloudClientException
*/
public function getLabelPdf(Parcel|int $parcel, int $format): string
{
Expand All @@ -398,7 +397,7 @@ public function getLabelPdf(Parcel|int $parcel, int $format): string
$labelUrl = $parcel->getLabelUrl($format);

if (!$labelUrl) {
throw new SendCloudStateException('SendCloud parcel does not have any labels.');
throw new SendcloudStateException('Sendcloud parcel does not have any labels.');
}

try {
Expand All @@ -415,7 +414,7 @@ public function getLabelPdf(Parcel|int $parcel, int $format): string
* @param array<Parcel|int> $parcels
* @param int $format One of `Parcel::LABEL_FORMATS`. The A4 formats will contain up to 4 labels per page.
* @return string PDF data.
* @throws SendCloudClientException
* @throws SendcloudClientException
*/
public function getBulkLabelPdf(array $parcels, int $format): string
{
Expand Down Expand Up @@ -445,7 +444,7 @@ public function getBulkLabelPdf(array $parcels, int $format): string
$labelData = json_decode((string)$response->getBody(), true);
$labelUrl = Utility::getLabelUrlFromData($labelData, $format);
if (!$labelUrl) {
throw new SendCloudStateException('No label URL could be obtained from the response.');
throw new SendcloudStateException('No label URL could be obtained from the response.');
}

try {
Expand All @@ -456,10 +455,10 @@ public function getBulkLabelPdf(array $parcels, int $format): string
}

/**
* Fetches the sender addresses configured in SendCloud.
* Fetches the sender addresses configured in Sendcloud.
*
* @return SenderAddress[]
* @throws SendCloudRequestException
* @throws SendcloudRequestException
*/
public function getSenderAddresses(): array
{
Expand All @@ -476,9 +475,9 @@ public function getSenderAddresses(): array
}

/**
* Retrieves current parcel data from SendCloud.
* Retrieves current parcel data from Sendcloud.
*
* @throws SendCloudClientException
* @throws SendcloudClientException
*/
public function getParcel(Parcel|int $parcel): Parcel
{
Expand All @@ -493,7 +492,7 @@ public function getParcel(Parcel|int $parcel): Parcel
/**
* Parse a webhook event using the client's secret key. See {@see Utility::parseWebhookRequest()} for specifics.
*
* @throws SendCloudWebhookException
* @throws SendcloudWebhookException
*/
public function parseWebhookRequest(RequestInterface $request): WebhookEvent
{
Expand Down Expand Up @@ -523,10 +522,10 @@ public function getReturnPortalUrl(Parcel|int $parcel): ?string
}

/**
* Returns the given arguments as data in SendCloud parcel format.
* Returns the given arguments as data in Sendcloud parcel format.
*
* @param ShippingMethod|int|null $shippingMethod Required if requesting a label.
* @param SenderAddress|Address|int|null $senderAddress Passing null will pick SendCloud's default. An Address will
* @param SenderAddress|Address|int|null $senderAddress Passing null will pick Sendcloud's default. An Address will
* use undocumented behavior that will disable branding personalizations.
* @param int|null $customsShipmentType One of {@see Parcel::CUSTOMS_SHIPMENT_TYPES}.
*/
Expand Down Expand Up @@ -678,9 +677,9 @@ protected function getParcelData(
protected function parseGuzzleException(
TransferException $exception,
string $defaultMessage
): SendCloudRequestException {
): SendcloudRequestException {
$message = $defaultMessage;
$code = SendCloudRequestException::CODE_UNKNOWN;
$code = SendcloudRequestException::CODE_UNKNOWN;

$responseCode = null;
$responseMessage = null;
Expand All @@ -691,25 +690,25 @@ protected function parseGuzzleException(
}

if ($exception instanceof ConnectException) {
$message = 'Could not contact SendCloud API.';
$code = SendCloudRequestException::CODE_CONNECTION_FAILED;
$message = 'Could not contact Sendcloud API.';
$code = SendcloudRequestException::CODE_CONNECTION_FAILED;
}

// Precondition failed, parse response message to determine code of exception
if ($exception->getCode() === 401) {
$message = 'Invalid public/secret key combination.';
$code = SendCloudRequestException::CODE_UNAUTHORIZED;
$code = SendcloudRequestException::CODE_UNAUTHORIZED;
} elseif ($exception->getCode() === 412) {
$message = 'SendCloud account is not fully configured yet.';
$message = 'Sendcloud account is not fully configured yet.';

if (stripos($responseMessage, 'no address data') !== false) {
$code = SendCloudRequestException::CODE_NO_ADDRESS_DATA;
$code = SendcloudRequestException::CODE_NO_ADDRESS_DATA;
} elseif (stripos($responseMessage, 'not allowed to announce') !== false) {
$code = SendCloudRequestException::CODE_NOT_ALLOWED_TO_ANNOUNCE;
$code = SendcloudRequestException::CODE_NOT_ALLOWED_TO_ANNOUNCE;
}
}

return new SendCloudRequestException($message, $code, $exception, $responseCode, $responseMessage);
return new SendcloudRequestException($message, $code, $exception, $responseCode, $responseMessage);
}

protected function parseParcelArgument(Parcel|int $parcel): int
Expand Down
7 changes: 0 additions & 7 deletions src/Exception/SendCloudClientException.php

This file was deleted.

7 changes: 0 additions & 7 deletions src/Exception/SendCloudStateException.php

This file was deleted.

7 changes: 7 additions & 0 deletions src/Exception/SendcloudClientException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace JouwWeb\Sendcloud\Exception;

abstract class SendcloudClientException extends \Exception
{
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace JouwWeb\SendCloud\Exception;
namespace JouwWeb\Sendcloud\Exception;

class SendCloudRequestException extends SendCloudClientException
class SendcloudRequestException extends SendcloudClientException
{
public const CODE_UNKNOWN = 0;
public const CODE_NO_ADDRESS_DATA = 1;
Expand All @@ -20,27 +20,27 @@ class SendCloudRequestException extends SendCloudClientException

public function __construct(
string $message = '',
int $code = SendCloudRequestException::CODE_UNKNOWN,
int $code = SendcloudRequestException::CODE_UNKNOWN,
\Throwable $previous = null,
protected ?int $sendCloudCode = null,
protected ?string $sendCloudMessage = null
protected ?int $sendcloudCode = null,
protected ?string $sendcloudMessage = null
) {
parent::__construct($message, $code, $previous);
}

/**
* Returns the code reported by Sendcloud when available. This usually equals the HTTP status code.
*/
public function getSendCloudCode(): ?int
public function getSendcloudCode(): ?int
{
return $this->sendCloudCode;
return $this->sendcloudCode;
}

/**
* Returns the error message reported by Sendcloud when available.
*/
public function getSendCloudMessage(): ?string
public function getSendcloudMessage(): ?string
{
return $this->sendCloudMessage;
return $this->sendcloudMessage;
}
}
7 changes: 7 additions & 0 deletions src/Exception/SendcloudStateException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace JouwWeb\Sendcloud\Exception;

class SendcloudStateException extends SendcloudClientException
{
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace JouwWeb\SendCloud\Exception;
namespace JouwWeb\Sendcloud\Exception;

class SendCloudWebhookException extends \Exception
class SendcloudWebhookException extends \Exception
{
public const CODE_INVALID_REQUEST = 1;
public const CODE_VERIFICATION_FAILED = 2;
Expand Down
2 changes: 1 addition & 1 deletion src/Model/Address.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace JouwWeb\SendCloud\Model;
namespace JouwWeb\Sendcloud\Model;

class Address
{
Expand Down
4 changes: 2 additions & 2 deletions src/Model/Parcel.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace JouwWeb\SendCloud\Model;
namespace JouwWeb\Sendcloud\Model;

use JouwWeb\SendCloud\Utility;
use JouwWeb\Sendcloud\Utility;

class Parcel
{
Expand Down
2 changes: 1 addition & 1 deletion src/Model/ParcelItem.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace JouwWeb\SendCloud\Model;
namespace JouwWeb\Sendcloud\Model;

/**
* A product type that is contained in a parcel.
Expand Down
Loading

0 comments on commit 2b82a52

Please sign in to comment.