Skip to content
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

De 1301 mailgun sdk the template search filters do not match the documentation #914

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
2f6f7aa
Add dependabot. Change php-cs-fixer
oleksandr-mykhailenko Mar 7, 2024
e7e227e
Merge branch 'master' of github.com:mailgun/mailgun-php
oleksandr-mykhailenko Mar 9, 2024
fca806c
Merge branch 'master' of github.com:mailgun/mailgun-php
oleksandr-mykhailenko Apr 22, 2024
6499a70
Merge branch 'master' of github.com:mailgun/mailgun-php
oleksandr-mykhailenko Apr 27, 2024
017fac4
Merge branch 'master' of github.com:mailgun/mailgun-php
oleksandr-mykhailenko Apr 27, 2024
b568e7a
Merge branch 'master' of github.com:mailgun/mailgun-php
oleksandr-mykhailenko Apr 27, 2024
2e906af
Merge branch 'master' of github.com:mailgun/mailgun-php
oleksandr-mykhailenko Apr 27, 2024
f84822d
Domains. V4
oleksandr-mykhailenko Apr 27, 2024
36f1cf3
Merge branch 'master' of github.com:mailgun/mailgun-php
oleksandr-mykhailenko Jul 7, 2024
8ffe44d
Merge branch 'master' of github.com:mailgun/mailgun-php
oleksandr-mykhailenko Jul 7, 2024
383e36f
Merge branch 'master' of github.com:mailgun/mailgun-php
oleksandr-mykhailenko Jul 10, 2024
4e98711
Merge branch 'master' of github.com:mailgun/mailgun-php
oleksandr-mykhailenko Jul 14, 2024
6971c50
Merge branch 'master' of github.com:mailgun/mailgun-php
oleksandr-mykhailenko Jul 15, 2024
4891e53
Merge branch 'master' of github.com:mailgun/mailgun-php
oleksandr-mykhailenko Jul 30, 2024
c8a5976
Correcting params to the method. Updated php docs
oleksandr-mykhailenko Jul 30, 2024
83c07b4
Correcting params to the method. Updated php docs
oleksandr-mykhailenko Jul 30, 2024
0e6a4f7
Correcting params to the method. Updated php docs
oleksandr-mykhailenko Jul 30, 2024
4a04fbd
Correcting params to the method. Updated php docs
oleksandr-mykhailenko Jul 30, 2024
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: 1 addition & 1 deletion src/Api/HttpApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ abstract class HttpApi
* @param RequestBuilder $requestBuilder
* @param Hydrator $hydrator
*/
public function __construct($httpClient, RequestBuilder $requestBuilder, Hydrator $hydrator)
public function __construct(ClientInterface $httpClient, RequestBuilder $requestBuilder, Hydrator $hydrator)
{
$this->httpClient = $httpClient;
$this->requestBuilder = $requestBuilder;
Expand Down
16 changes: 8 additions & 8 deletions src/Api/MailingList/Member.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,14 @@ public function create(

/**
* Adds multiple members (up to 1000) to the mailing list.
* @param string $list Address of the mailing list
* @param array $members Array of members, each item should be either a single string address or an array of member properties
* @param bool $upsert `true` to update existing members, `false` (default) to ignore duplicates
* @param array $requestHeaders
* @return UpdateResponse
* @param string $list Address of the mailing list
* @param array $members Array of members, each item should be either a single string address or an array of member properties
* @param bool $upsert `true` to update existing members, `false` (default) to ignore duplicates
* @param array $requestHeaders
* @return MailingListUpdateResponse|null
* @throws ClientExceptionInterface
*/
public function createMultiple(string $list, array $members, bool $upsert = false, array $requestHeaders = [])
public function createMultiple(string $list, array $members, bool $upsert = false, array $requestHeaders = []): ?MailingListUpdateResponse
{
Assert::stringNotEmpty($list);
Assert::isArray($members);
Expand Down Expand Up @@ -156,11 +156,11 @@ public function createMultiple(string $list, array $members, bool $upsert = fals
if (is_array($value)) {
$value = json_encode($value);
}
// We should assert that "vars"'s $value is a string.
break;
// We should assert that "vars"'s $value is a string.
// no break
case 'name':
Comment on lines -159 to 162
Copy link

Choose a reason for hiding this comment

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

Just checking: should this break have been added? There's a comment two lines below that says "no break", and the comment above that seems to explain why. json_encode could return false, so perhaps that's what was being avoided here.

I haven't read through any of this code, so I don't know what it does, and I'm not using this version, so I don't know whether it breaks or improves anything. I just happened across this and thought I'd point it out and ask.

Assert::string($value);

break;
case 'subscribed':
Assert::oneOf($value, ['yes', 'no', true, false]);
Expand Down
12 changes: 11 additions & 1 deletion src/Api/Pagination.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,19 @@
*/
trait Pagination
{
/**
* @param string $path
* @param array $parameters
* @param array $requestHeaders
* @return ResponseInterface
*/
abstract protected function httpGet(string $path, array $parameters = [], array $requestHeaders = []): ResponseInterface;


/**
* @param class-string $className
* @param ResponseInterface $response
* @return mixed
*/
abstract protected function hydrateResponse(ResponseInterface $response, string $className);

Expand All @@ -49,8 +58,9 @@ public function previousPage(PagingProvider $response): ?PagingProvider
}

/**
* @param PagingProvider $response
* @param PagingProvider $response
* @return PagingProvider|null
* @throws ClientExceptionInterface
*/
public function firstPage(PagingProvider $response): ?PagingProvider
{
Expand Down
2 changes: 1 addition & 1 deletion src/Api/Templates.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function index(string $domain, int $limit, string $page, string $pivot, a

$params = [
'limit' => $limit,
'skip' => $page,
'page' => $page,
'p' => $pivot,
];

Expand Down
8 changes: 7 additions & 1 deletion src/Assert.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@
*/
final class Assert extends \Webmozart\Assert\Assert
{
protected static function reportInvalidArgument($message)
/**
* @psalm-pure this method is not supposed to perform side-effects
* @psalm-return never
* @param mixed $message
* @return void
*/
protected static function reportInvalidArgument($message): void
{
throw new InvalidArgumentException($message);
}
Expand Down
32 changes: 32 additions & 0 deletions src/HttpClient/HttpClientConfigurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,32 +101,50 @@ public function createConfiguredClient(): PluginClient
return new PluginClient($this->getHttpClient(), $plugins);
}

/**
* @param bool $debug
* @return $this
*/
public function setDebug(bool $debug): self
{
$this->debug = $debug;

return $this;
}

/**
* @param string $endpoint
* @return $this
*/
public function setEndpoint(string $endpoint): self
{
$this->endpoint = $endpoint;

return $this;
}

/**
* @return string
*/
public function getApiKey(): string
{
return $this->apiKey;
}

/**
* @param string $apiKey
* @return $this
*/
public function setApiKey(string $apiKey): self
{
$this->apiKey = $apiKey;

return $this;
}

/**
* @return UriFactoryInterface
*/
private function getUriFactory(): UriFactoryInterface
{
if (null === $this->uriFactory) {
Expand All @@ -136,13 +154,20 @@ private function getUriFactory(): UriFactoryInterface
return $this->uriFactory;
}

/**
* @param UriFactoryInterface $uriFactory
* @return $this
*/
public function setUriFactory(UriFactoryInterface $uriFactory): self
{
$this->uriFactory = $uriFactory;

return $this;
}

/**
* @return ClientInterface
*/
private function getHttpClient(): ClientInterface
{
if (null === $this->httpClient) {
Expand All @@ -152,13 +177,20 @@ private function getHttpClient(): ClientInterface
return $this->httpClient;
}

/**
* @param ClientInterface $httpClient
* @return $this
*/
public function setHttpClient(ClientInterface $httpClient): self
{
$this->httpClient = $httpClient;

return $this;
}

/**
* @return History
*/
public function getResponseHistory(): History
{
return $this->responseHistory;
Expand Down
9 changes: 9 additions & 0 deletions src/HttpClient/Plugin/ReplaceUriPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,20 @@ final class ReplaceUriPlugin implements Plugin
*/
private $uri;

/**
* @param UriInterface $uri
*/
public function __construct(UriInterface $uri)
{
$this->uri = $uri;
}

/**
* @param RequestInterface $request
* @param callable $next
* @param callable $first
* @return mixed
*/
public function doHandleRequest(RequestInterface $request, callable $next, callable $first)
{
$request = $request->withUri($this->uri);
Expand Down
31 changes: 16 additions & 15 deletions src/HttpClient/RequestBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ class RequestBuilder

/**
* Creates a new PSR-7 request.
*
* @param string $method HTTP method
* @param string $uri URI
* @param array $headers Request headers
* @param array|string|null $body Request body. If body is an array we will send a as multipart stream request.
* If array, each array *item* MUST look like:
* array (
Expand All @@ -53,7 +55,7 @@ class RequestBuilder
public function create(string $method, string $uri, array $headers = [], $body = null): RequestInterface
{
if (!is_array($body)) {
$stream = $this->getStreamFactory()->createStream((string) $body);
$stream = $this->getStreamFactory()->createStream((string)$body);

return $this->createRequest($method, $uri, $headers, $stream);
}
Expand All @@ -62,8 +64,7 @@ public function create(string $method, string $uri, array $headers = [], $body =
foreach ($body as $item) {
$name = $this->getItemValue($item, 'name');
$content = $this->getItemValue($item, 'content');
unset($item['name']);
unset($item['content']);
unset($item['name'], $item['content']);

$builder->addResource($name, $content, $item);
}
Expand All @@ -72,7 +73,7 @@ public function create(string $method, string $uri, array $headers = [], $body =
$boundary = $builder->getBoundary();
$builder->reset();

$headers['Content-Type'] = 'multipart/form-data; boundary="'.$boundary.'"';
$headers['Content-Type'] = 'multipart/form-data; boundary="' . $boundary . '"';

return $this->createRequest($method, $uri, $headers, $multipartStream);
}
Expand All @@ -90,7 +91,7 @@ private function getRequestFactory(): RequestFactoryInterface
}

/**
* @param RequestFactoryInterface $requestFactory
* @param RequestFactoryInterface $requestFactory
* @return $this
*/
public function setRequestFactory(RequestFactoryInterface $requestFactory): self
Expand All @@ -113,7 +114,7 @@ private function getStreamFactory(): StreamFactoryInterface
}

/**
* @param StreamFactoryInterface $streamFactory
* @param StreamFactoryInterface $streamFactory
* @return $this
*/
public function setStreamFactory(StreamFactoryInterface $streamFactory): self
Expand All @@ -136,7 +137,7 @@ private function getMultipartStreamBuilder(): MultipartStreamBuilder
}

/**
* @param MultipartStreamBuilder $multipartStreamBuilder
* @param MultipartStreamBuilder $multipartStreamBuilder
* @return $this
*/
public function setMultipartStreamBuilder(MultipartStreamBuilder $multipartStreamBuilder): self
Expand All @@ -147,10 +148,10 @@ public function setMultipartStreamBuilder(MultipartStreamBuilder $multipartStrea
}

/**
* @param string $method
* @param string $uri
* @param array $headers
* @param StreamInterface $stream
* @param string $method
* @param string $uri
* @param array $headers
* @param StreamInterface $stream
* @return RequestInterface
*/
private function createRequest(string $method, string $uri, array $headers, StreamInterface $stream): RequestInterface
Expand All @@ -165,14 +166,14 @@ private function createRequest(string $method, string $uri, array $headers, Stre
}

/**
* @param array $item
* @param string $key
* @param array $item
* @param string $key
* @return mixed|string
*/
private function getItemValue(array $item, string $key)
{
if (is_bool($item[$key])) {
return (string) $item[$key];
return (string)$item[$key];
}

return $item[$key];
Expand Down
2 changes: 1 addition & 1 deletion src/Mailgun.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ public function tags(): Api\Tag
*/
public function webhooks(): Api\Webhook
{
return new Api\Webhook($this->httpClient, $this->requestBuilder, $this->hydrator, $this->apiKey);
return new Api\Webhook($this->httpClient, $this->requestBuilder, $this->hydrator, $this->apiKey ?? '');
}

/**
Expand Down
3 changes: 1 addition & 2 deletions src/Message/BatchMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,9 @@ public function __construct(Message $messageApi, string $domain, bool $autoSend)
* full_name?: string,
* first?: string,
* last?: string,
*
* @return MessageBuilder
* @throws MissingRequiredParameter
* @throws TooManyRecipients
* @throws TooManyRecipients|ClientExceptionInterface
*/
protected function addRecipient(string $headerName, string $address, array $variables): MessageBuilder
{
Expand Down
5 changes: 5 additions & 0 deletions src/Message/Exceptions/LimitExceeded.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@

class LimitExceeded extends \Exception implements Exception
{
/**
* @param string $field
* @param int $limit
* @return self
*/
public static function create(string $field, int $limit)
{
return new self(sprintf('You\'ve exceeded the maximum (%d) %s for a single message.', $limit, $field));
Expand Down
5 changes: 5 additions & 0 deletions src/Message/Exceptions/MissingRequiredParameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@

class MissingRequiredParameter extends \Exception implements Exception
{
/**
* @param string $parameter
* @param string|null $message
* @return self
*/
public static function create(string $parameter, string $message = null)
{
if (null === $message) {
Expand Down
9 changes: 9 additions & 0 deletions src/Message/Exceptions/TooManyRecipients.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,20 @@

class TooManyRecipients extends LimitExceeded implements Exception
{
/**
* @param string $field
* @param int $limit
* @return LimitExceeded|self
*/
public static function create(string $field, int $limit = MessageBuilder::RECIPIENT_COUNT_LIMIT)
{
return new self(sprintf('You\'ve exceeded the maximum recipient count (%s) for filed "%s".', $limit, $field));
}

/**
* @param int $limit
* @return self
*/
public static function whenAutoSendDisabled(int $limit = MessageBuilder::RECIPIENT_COUNT_LIMIT)
{
return new self(sprintf('You\'ve exceeded the maximum recipient count (%s) with autosend disabled.', $limit));
Expand Down
Loading
Loading