kiwicom / email-on-acid-sdk
该库为与Email on Acid API工作提供基本功能
Requires
- php: >=7.1
- guzzlehttp/guzzle: ^6.2
Requires (Dev)
- phpunit/phpunit: 6.2.2
- roave/better-reflection: @dev
This package is not auto-updated.
Last update: 2024-09-15 04:07:03 UTC
README
安装
composer require "kiwicom/email-on-acid-sdk"
使用
使用所需参数创建ApiFactory - apikey
和 password
可在 https://www.emailonacid.com 的 Account
部分获取
$apiFactory = new \EmailOnAcid\ApiFactory('yourapikey', 'yourpassword', $timeout);
创建Email测试API示例
$emailTestsApi = $apiFactory->createEmailTesting()
创建新测试需要EmailTestRequest作为参数,填写所需数据,其中url / html之一必须提供作为电子邮件内容,并返回包含您新测试数据的Response\NewEmailTest
try { $newEmailTest = $emailTestsApi->createEmailTest( new \EmailOnAcid\Request\EmailTestRequest( 'Email subject to test', '<html>Html of your email to test</html>' ) ); } catch (\EmailOnAcid\Ecxception\EmailOnAcidException $e) { // handle exception }
API调用结果是不可变对象,来自 \EmailOnAcid\Response
命名空间或简单的string[]。
获取测试结果示例
要获取测试结果,您需要testId,它在Response\NewEmailTest中提供(testId用于操作如链接测试、电子邮件内容测试、垃圾邮件测试、代码分析,因此您可能希望在创建新测试后将其存储在某个地方)
$testInfo = $emailTestApi->getTestInfo( $newEmailTest->getId() );
异常类型
\EmailOnAcid\Ecxception\ApiRequestException
- 非预期的API错误
\EmailOnAcid\Ecxception\UnsuccessfulActionException
- 一些API调用仅提供true|false结果,不包含任何附加数据;在结果为false时抛出UnsuccessfulActionException
\EmailOnAcid\Ecxception\NotFoundException
- 可在请求的内容找不到的情况下抛出(通常与需要test id作为参数的函数相关,且该id在API上不存在)