Skip to content

Commit

Permalink
SubAccount. In Progress (#886)
Browse files Browse the repository at this point in the history
* SubAccount. In Progress

* CRUD operations with sub accounts

* Styles fixes

* Extend methods. They have own parameter for custom headers.
Added supporting SubAccount requests

* Extend methods. They have own parameter for custom headers.
Added supporting SubAccount requests

* Add readme info
  • Loading branch information
oleksandr-mykhailenko authored Dec 16, 2023
1 parent 3dbdc2f commit 454ab2b
Show file tree
Hide file tree
Showing 28 changed files with 1,123 additions and 466 deletions.
50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,56 @@ $resultDelete = $mgClient->httpClient()->httpDelete($path, $params);

```


### SubAccounts

```php
//Enable Sub Account
try {
$items = $mgClient->subaccounts()->enable($id);
} catch (Exception $exception) {
echo sprintf('HTTP CODE - %s,', $exception->getCode());
echo sprintf('Error - %s', $exception->getMessage());
}

//Create a new Sub Account
try {
$items = $mgClient->subaccounts()->create('some name');
} catch (Exception $exception) {
echo sprintf('HTTP CODE - %s,', $exception->getCode());
echo sprintf('Error - %s', $exception->getMessage());
}

//Get All
try {
$items = $mgClient->subaccounts()->index();

print_r($items->getItems());
} catch (Exception $exception) {
echo sprintf('HTTP CODE - %s,', $exception->getCode());
echo sprintf('Error - %s', $exception->getMessage());
}
```
### Performing API Requests "On Behalf Of" Subaccounts
More Detailed you can read here - [https://help.mailgun.com/hc/en-us/articles/16380043681435-Subaccounts#01H2VMHAW8CN4A7WXM6ZFNSH4R](https://help.mailgun.com/hc/en-us/articles/16380043681435-Subaccounts#01H2VMHAW8CN4A7WXM6ZFNSH4R)
```php
$mgClient = Mailgun::create(
'xxx',
'yyy',
$subAccountId
);
```

```php
use Mailgun\HttpClient\HttpClientConfigurator;
use Mailgun\Hydrator\NoopHydrator;

$configurator = new HttpClientConfigurator();
$configurator->setEndpoint('http://bin.mailgun.net/aecf68de');
$configurator->setApiKey('key-example');
$configurator->setSubAccountId($subAccountId)
```

### All usage examples

You will find more detailed documentation at [/doc](doc/index.md) and on
Expand Down
7 changes: 5 additions & 2 deletions src/Api/Attachment.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Mailgun\Api;

use Mailgun\Assert;
use Mailgun\Exception\UnknownErrorException;
use Psr\Http\Client\ClientExceptionInterface;
use Psr\Http\Message\ResponseInterface;

Expand All @@ -22,16 +23,18 @@ class Attachment extends HttpApi
{
/**
* @param string $url
* @param array $requestHeaders
* @return ResponseInterface
* @throws ClientExceptionInterface
* @throws UnknownErrorException
*/
public function show(string $url): ResponseInterface
public function show(string $url, array $requestHeaders = []): ResponseInterface
{
Assert::stringNotEmpty($url);
Assert::regex($url, '@https://.*mailgun\.(net|org)/v.+@');
Assert::regex($url, '|/attachments/[0-9]+|');

$response = $this->httpGet($url);
$response = $this->httpGet($url, [], $requestHeaders);

if (200 !== $response->getStatusCode()) {
$this->handleErrors($response);
Expand Down
Loading

0 comments on commit 454ab2b

Please sign in to comment.