-
Notifications
You must be signed in to change notification settings - Fork 17
Add sending domain update and company info endpoints #77
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| use Mailtrap\Config; | ||
| use Mailtrap\DTO\Request\Domain\CompanyInfo; | ||
| use Mailtrap\DTO\Request\Domain\CreateCompanyInfo; | ||
| use Mailtrap\DTO\Request\Domain\UpdateCompanyInfo; | ||
| use Mailtrap\Helper\ResponseHelper; | ||
| use Mailtrap\MailtrapSendingClient; | ||
|
|
||
| require __DIR__ . '/../../vendor/autoload.php'; | ||
|
|
||
| $domainId = (int) $_ENV['MAILTRAP_DOMAIN_ID']; | ||
| $config = new Config($_ENV['MAILTRAP_API_KEY']); #your API token from here https://mailtrap.io/api-tokens | ||
|
|
||
| $companyInfo = (new MailtrapSendingClient($config))->companyInfo($domainId); #required parameter is domainId | ||
|
|
||
| /** | ||
| * Create company info for a sending domain | ||
| * | ||
| * POST https://mailtrap.io/api/domains/{domain_id}/company_info | ||
| */ | ||
| try { | ||
| $response = $companyInfo->createCompanyInfo( | ||
| new CreateCompanyInfo( | ||
| name: 'Mailtrap', | ||
| address: '123 Main St', | ||
| city: 'San Francisco', | ||
| country: 'US', | ||
| zipCode: '94105', | ||
| websiteUrl: 'https://mailtrap.io', | ||
| phone: '+1-555-0100', | ||
| privacyPolicyUrl: 'https://mailtrap.io/privacy', | ||
| termsOfServiceUrl: 'https://mailtrap.io/terms', | ||
| infoLevel: CompanyInfo::INFO_LEVEL_BUSINESS | ||
| ) | ||
| ); | ||
|
|
||
| // print the response body (array) | ||
| var_dump(ResponseHelper::toArray($response)); | ||
| } catch (Exception $e) { | ||
| echo 'Caught exception: ', $e->getMessage(), "\n"; | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * Get company info for a sending domain | ||
| * | ||
| * GET https://mailtrap.io/api/domains/{domain_id}/company_info | ||
| */ | ||
| try { | ||
| $response = $companyInfo->getCompanyInfo(); | ||
|
|
||
| // print the response body (array) | ||
| var_dump(ResponseHelper::toArray($response)); | ||
| } catch (Exception $e) { | ||
| echo 'Caught exception: ', $e->getMessage(), "\n"; | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * Update company info for a sending domain | ||
| * | ||
| * PATCH https://mailtrap.io/api/domains/{domain_id}/company_info | ||
| * | ||
| * Only the fields provided are updated. | ||
| */ | ||
| try { | ||
| $response = $companyInfo->updateCompanyInfo(new UpdateCompanyInfo(city: 'New York', zipCode: '10001')); | ||
|
|
||
| // print the response body (array) | ||
| var_dump(ResponseHelper::toArray($response)); | ||
| } catch (Exception $e) { | ||
| echo 'Caught exception: ', $e->getMessage(), "\n"; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Mailtrap\Api\Sending; | ||
|
|
||
| use Mailtrap\Api\AbstractApi; | ||
| use Mailtrap\ConfigInterface; | ||
| use Mailtrap\DTO\Request\Domain\CreateCompanyInfo; | ||
| use Mailtrap\DTO\Request\Domain\UpdateCompanyInfo; | ||
| use Psr\Http\Message\ResponseInterface; | ||
|
|
||
| /** | ||
| * Class CompanyInfo | ||
| */ | ||
| class CompanyInfo extends AbstractApi implements SendingInterface | ||
| { | ||
| public function __construct(ConfigInterface $config, private int $domainId) | ||
| { | ||
| parent::__construct($config); | ||
| } | ||
|
|
||
| /** | ||
| * Get the company info associated with the sending domain. | ||
| * | ||
| * @return ResponseInterface | ||
| */ | ||
| public function getCompanyInfo(): ResponseInterface | ||
| { | ||
| return $this->handleResponse( | ||
| $this->httpGet($this->getBasePath()) | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Create the company info for the sending domain. Company info is required | ||
| * for domain compliance verification. | ||
| * | ||
| * @param CreateCompanyInfo $companyInfo | ||
| * @return ResponseInterface | ||
| */ | ||
| public function createCompanyInfo(CreateCompanyInfo $companyInfo): ResponseInterface | ||
| { | ||
| return $this->handleResponse( | ||
| $this->httpPost( | ||
| path: $this->getBasePath(), | ||
| body: [ | ||
| 'company_info' => $companyInfo->toArray() | ||
| ] | ||
| ) | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Update the company info for the sending domain. | ||
| * | ||
| * @param UpdateCompanyInfo $companyInfo | ||
| * @return ResponseInterface | ||
| */ | ||
| public function updateCompanyInfo(UpdateCompanyInfo $companyInfo): ResponseInterface | ||
| { | ||
| return $this->handleResponse( | ||
| $this->httpPatch( | ||
| path: $this->getBasePath(), | ||
| body: [ | ||
| 'company_info' => $companyInfo->toArray() | ||
| ] | ||
| ) | ||
| ); | ||
| } | ||
|
|
||
| private function getBasePath(): string | ||
| { | ||
| return sprintf('%s/api/domains/%s/company_info', $this->getHost(), $this->domainId); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Mailtrap\DTO\Request\Domain; | ||
|
|
||
| /** | ||
| * Company info vocabulary: sender info levels. | ||
| */ | ||
| final class CompanyInfo | ||
| { | ||
| public const INFO_LEVEL_BUSINESS = 'business'; | ||
| public const INFO_LEVEL_INDIVIDUAL = 'individual'; | ||
|
|
||
| private function __construct() | ||
| { | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Mailtrap\DTO\Request\Domain; | ||
|
|
||
| /** | ||
| * Class CreateCompanyInfo | ||
| * | ||
| * Company information for a sending domain. Required for domain compliance | ||
| * verification. | ||
| */ | ||
| final class CreateCompanyInfo implements DomainInterface | ||
| { | ||
| /** | ||
| * @param string $name Company or individual name | ||
| * @param string $address Street address | ||
| * @param string $city City | ||
| * @param string $country Country | ||
| * @param string $zipCode ZIP or postal code | ||
| * @param string $websiteUrl Company website URL | ||
| * @param string|null $phone Phone number | ||
| * @param string|null $privacyPolicyUrl URL to the privacy policy page | ||
| * @param string|null $termsOfServiceUrl URL to the terms of service page | ||
| * @param string|null $infoLevel One of CompanyInfo::INFO_LEVEL_* | ||
| */ | ||
| public function __construct( | ||
| private string $name, | ||
| private string $address, | ||
| private string $city, | ||
| private string $country, | ||
| private string $zipCode, | ||
| private string $websiteUrl, | ||
| private ?string $phone = null, | ||
| private ?string $privacyPolicyUrl = null, | ||
| private ?string $termsOfServiceUrl = null, | ||
| private ?string $infoLevel = null, | ||
| ) { | ||
| } | ||
|
|
||
| public function toArray(): array | ||
| { | ||
| $payload = [ | ||
| 'name' => $this->name, | ||
| 'address' => $this->address, | ||
| 'city' => $this->city, | ||
| 'country' => $this->country, | ||
| 'zip_code' => $this->zipCode, | ||
| 'website_url' => $this->websiteUrl, | ||
| ]; | ||
|
|
||
| if ($this->phone !== null) { | ||
| $payload['phone'] = $this->phone; | ||
| } | ||
|
|
||
| if ($this->privacyPolicyUrl !== null) { | ||
| $payload['privacy_policy_url'] = $this->privacyPolicyUrl; | ||
| } | ||
|
|
||
| if ($this->termsOfServiceUrl !== null) { | ||
| $payload['terms_of_service_url'] = $this->termsOfServiceUrl; | ||
| } | ||
|
|
||
| if ($this->infoLevel !== null) { | ||
| $payload['info_level'] = $this->infoLevel; | ||
| } | ||
|
|
||
| return $payload; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Mailtrap\DTO\Request\Domain; | ||
|
|
||
| use Mailtrap\DTO\Request\RequestInterface; | ||
|
|
||
| interface DomainInterface extends RequestInterface | ||
| { | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.