Skip to content

Update Client.php #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Sendcloud
e# Sendcloud

This is a PHP library that provides a simple way to communicate with the Sendcloud API. It was created because there
were no simple alternatives that follow good object-oriented code practices.
Expand Down Expand Up @@ -109,4 +109,4 @@ try {
```

## Installation
`composer require jouwweb/sendcloud`
`composer require akali22/sendcloud`
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "jouwweb/sendcloud",
"name": "akali22/sendcloud",
"description": "Provides a client to interact with the Sendcloud API in an object-oriented way.",
"keywords": [
"sendcloud",
Expand All @@ -9,13 +9,13 @@
"parcel",
"webhook"
],
"homepage": "https://github.com/Webador/sendcloud",
"homepage": "https://github.com/akali22/sendcloud",
"type": "library",
"license": "MIT",
"authors": [
{
"name": "Webador",
"email": "tech@webador.com"
"name": "akali22",
"email": "akali22@gmail.com"
}
],
"scripts": {
Expand Down
21 changes: 20 additions & 1 deletion src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,21 @@ public function getUser(): User
* @param SenderAddress|int|null $senderAddress The sender address to ship from. Methods available to all of your
* account's sender addresses will be retrieved when null.
* @param bool $returnMethodsOnly When true, methods for making a return are returned instead.
* @param int from_postal_code
* @param int to_postal_code
* @param int to_country iso2 code
* @return ShippingMethod[]
* @throws SendcloudClientException
* @see https://sendcloud.dev/docs/shipping/shipping-methods/
*/
public function getShippingMethods(
?int $servicePointId = null,
SenderAddress|int|null $senderAddress = null,
bool $returnMethodsOnly = false
bool $returnMethodsOnly = false,
?int $from_postal_code =null,
?int $to_postal_code =null,
?string $to_country =null,
Comment on lines +89 to +91
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it would be better to sync up the naming with Sendcloud's, but consistency with existing code is more important in this case. Let's rename these to use lowerCamelCase like the other arguments!


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty line:

Suggested change

And: To bring this fully in line with the documentation all that's needed still is the is_return boolean argument. Let's add that while we're at it?

): array {
try {
$queryData = [];
Expand All @@ -109,6 +116,18 @@ public function getShippingMethods(
$queryData['is_return'] = 'true';
}

if ($from_postal_code) {
$queryData['from_postal_code'] = $from_postal_code;
}

if ($to_postal_code) {
$queryData['to_postal_code'] = $to_postal_code;
}

if ($to_country) {
$queryData['to_country'] = $to_country;
}

$response = $this->guzzleClient->get('shipping_methods', [
RequestOptions::QUERY => $queryData,
]);
Expand Down