Skip to content
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
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
/phpcs.xml.dist export-ignore
/phpstan.neon export-ignore
/phpunit.xml.dist export-ignore
/.php-cs-fixer.dist.php export-ignore
/bump-version.sh export-ignore
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ vendor
.idea
composer.lock
.phpunit.result.cache
.phpunit.cache
.phpunit.cache
.php-cs-fixer.cache
25 changes: 25 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

$finder = (new PhpCsFixer\Finder())
->in(__DIR__)
->append([__FILE__]);

return (new PhpCsFixer\Config())
->setRules([
'@PER-CS' => true,
'no_empty_phpdoc' => true,
'no_superfluous_phpdoc_tags' => [
'allow_mixed' => true,
],
'no_unused_imports' => true,
'not_operator_with_successor_space' => true,
'phpdoc_trim' => true,
'phpdoc_trim_consecutive_blank_line_separation' => true,
'trailing_comma_in_multiline' => [
'after_heredoc' => true,
// https://cs.symfony.com/doc/rules/control_structure/trailing_comma_in_multiline.html
// only enable for the elements that are safe to use with PHP 7.4+
'elements' => ['arguments', 'arrays'],
],
])
->setFinder($finder);
45 changes: 45 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,51 @@ $connection->setClientId('your-client-id')
});
```

### Transports

By default, the SDK will create a `Transport` with the `TransportFactory` if you do not supply one.

To create your own `Transport` you have to create a class which implements `Sendy\Api\Http\Tranport\TransportInterface`.

An example for the Laravel framework could look like this

```php
use Illuminate\Foundation\Application;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Http;
use Sendy\Api\Exceptions\TransportException;
use Sendy\Api\Http\Request;
use Sendy\Api\Http\Response;
use Sendy\Api\Http\Transport\TransportInterface

class LaravelTransport implements TransportInterface
{
public function send(Request $request): Response
{
$headers = $request->getHeaders();
$contentType = Arr::pull($headers, 'Content-Type', 'application/json');

try {
$response = Http::withHeaders($headers)
->withBody($request->getBody(), $contentType)
->withMethod($request->getMethod())
->withUrl($request->getUrl())
->send();
} catch (\Throwable $e) {
throw new TransportException($e->getMessage(), $e->getCode(), $e);
}

return new Response($response->status(), $response->headers(), $response->body());
}

public function getUserAgent() : string
{
return 'LaravelHttpClient/' . Application::VERSION;
}
}

```

### Endpoints

The endpoints in the API documentation are mapped to the resource as defined in the Resources directory. Please consult
Expand Down
37 changes: 37 additions & 0 deletions bump_version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env bash
# Print the current version of the project and bump it to the given version.

set -e

current_version=$(echo "echo Connection::VERSION . PHP_EOL;" | cat src/Connection.php - | php)
echo "Current version: $current_version"

if [[ -z "$1" ]]
then
echo "To bump the version, provide the new version number as an argument."
exit 1
fi

# Remove the 'v' prefix if it exists
new_version=${1#v}

echo "New version: $new_version"

if ! [[ "$new_version" =~ ^[0-9]+\.[0-9]+\.[0-9](-[a-z]+\.[0-9]+)?$ ]]
then
echo "Invalid version format. Please use semantic versioning (https://semver.org/)."
exit 1
fi

echo "Bumping version to: $new_version"

perl -pi -e "s/^ public const VERSION = .*/ public const VERSION = '$new_version';/" src/Connection.php

echo
echo "To release the new version, first, commit the changes:"
echo " git add --all"
echo " git commit -m "$new_version""
echo " git push"
echo
echo "Once the commit is pushed to the master branch, create a release on GitHub to distribute the new version:"
echo " https://github.com/sendynl/php-sdk/releases/new?tag=v$new_version"
14 changes: 8 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
},
"require": {
"php": ">=7.4.0",
"ext-json": "*",
"guzzlehttp/guzzle": "~6.0|~7.0"
"ext-json": "*"
},
"config": {
"platform": {
Expand All @@ -38,12 +37,15 @@
"require-dev": {
"phpunit/phpunit": "^9.0",
"phpstan/phpstan": "^1",
"squizlabs/php_codesniffer": "^3.7",
"mockery/mockery": "^1.5"
"mockery/mockery": "^1.5",
"php-cs-fixer/shim": "^3.87",
"psr/http-client": "^1.0",
"psr/http-factory": "^1.1"
},
"scripts": {
"lint": "vendor/bin/phpcs",
"analyze": "vendor/bin/phpstan --xdebug",
"lint": "vendor/bin/php-cs-fixer fix --dry-run --diff",
"fix": "vendor/bin/php-cs-fixer fix",
"analyze": "vendor/bin/phpstan",
"test": "vendor/bin/phpunit"
}
}
48 changes: 0 additions & 48 deletions phpcs.xml.dist

This file was deleted.

31 changes: 5 additions & 26 deletions src/ApiException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,8 @@

namespace Sendy\Api;

final class ApiException extends \Exception
{
/** @var array<string, string[]> */
private array $errors = [];

/**
* @param string $message
* @param int $code
* @param \Throwable|null $previous
* @param string[][] $errors
*/
public function __construct(string $message = "", int $code = 0, ?\Throwable $previous = null, array $errors = [])
{
$this->errors = $errors;

parent::__construct($message, $code, $previous);
}

/**
* @return array<string, string[]>
*/
public function getErrors(): array
{
return $this->errors;
}
}
/**
* @deprecated This interface exists for backwards compatibility and may be removed in a future version.
* @internal
*/
interface ApiException extends \Throwable {}
Loading