gam / estafeta-command
PHP库,用于以编程方式运行“estafeta交互命令”网站操作。
v1.2.0
2022-08-24 00:06 UTC
Requires
- php: >=8.0
- ext-json: *
- myclabs/php-enum: ^1.8
- nette/schema: ^1.2
- symfony/browser-kit: ^6.0
- symfony/http-client: ^6.0
- symfony/mime: ^6.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- phpstan/phpstan: ^1.5
- phpunit/phpunit: ^9.5
- roave/security-advisories: dev-master
- timeweb/phpstan-enum: ^3.0
This package is auto-updated.
Last update: 2024-09-24 04:30:24 UTC
README
PHP库,用于以编程方式运行“estafeta交互命令”网站操作。
赞助商
功能
- 以编程方式获取Estafeta账户信息
- 可用服务
- 可用内容类型
- 通过邮政编码查找位置。
- 通过名称查找郊区(Colonia)。
- 创建标签(Guias)。
安装
composer require gam/estafeta-command
用法
这是一个简单的示例
// 1. set your credentials $credentials = new Credentials('user', 'password'); $command = new Command($credentials); // 2. fetch your account data $account = $command->fetchAccount(); $terrestre = $account->getServiceByName(Service::NEXT_DAY); $caja = $account->getContentTypeByName(ContentType::BOX); // 3. Find a Suburb by Postal Code & Name $originSection= $command->fetchSections('97306') ->findBySuburb('LOS HEROES', true) ->first(); // 4. Create an Origin Address $originAddress = new Address('Salome', '587'); // 5. Create an Origin Contact $originContact = new Contact( 'Foo', 'Bar', new Rfc('Foo Company'), 'foo@bar.com', new ContactPhone('0000000000', '0000000000') ); // 6. Create the Origin $origin = new Location( '', // not necessary $originSection, $originAddress, LocationCategory::OTHERS(), LocationType::ORIGIN(), $originContact ); // 7. Find Destination Section by postal code $destinationSection = $command->fetchSections('81000') ->findBySuburb('CENTRO', true) ->first(); // 8. Create Destination Address $destinationAddress = new Address('Vicente Guerrero', '790', '2'); // 9. Create Destination Contact $destinationContact = new Contact( 'Foo', 'Bar', new Rfc('Bar SA') ); // 10. Create the Destination $destination = new Location( '', // not necessary $destinationSection, $destinationAddress, LocationCategory::OTHERS(), LocationType::DESTINATION(), $destinationContact ); // 11. Set Print Config $pringConfig = new PrintConfig(PrintType::LOCAL(), PaperType::BOND()); // 12. Build the Label. $labelParameters = (new \Gam\Estafeta\Command\LabelParametersBuilder()) ->withAccount($account) ->withService($terrestre) ->withContentType($caja) ->withPackage(new Package( 14.0, new \Gam\Estafeta\Command\Model\Dimension(57, 57, 21), 'Vasos termicos' )) ->withPackagingType(PackagingType::PACKAGE()) ->withOrigin($origin) ->withDestination($destination) ->withPrintConfig($pringConfig) ->build(); $label = $command->createLabel($labelParameters); // store the label file file_put_contents("{$label->getId()}.pdf", $label->getPdf()); // finally, close the session $command->logout();
模型验证与清理
该包根据官方网站规则内置了验证。以下模型在构造函数中进行验证,因为它们的属性在对象构造后无法修改。
- 地址
- 联系
- 联系电话
- 尺寸
- 标签引用
- 包裹
- 参考
- Rfc
以下模型具有内置清理(数据净化)功能,以删除不允许的字符
地址
firstStreet:删除[a-z ÁÉÍÓÚáéíóú\d.,;:#*^\/]的不同字符。streetAddress:删除[^a-zÁÉÍÓÚáéíóú \d_]的不同字符。apartmentNumber:删除[a-z ÁÉÍÓÚáéíóú\d.,;:#*^\/]的不同字符。secondStreet:删除[^a-zÁÉÍÓÚáéíóú \d_]的不同字符。
联系
shortName:删除[a-z ÁÉÍÓÚáéíóú\d.,;:#*^\/]的不同字符。contactName:删除[a-z ÁÉÍÓÚáéíóú\d.,;:#*^\/]的不同字符。
标签引用
contentDescription:删除[^a-zÁÉÍÓÚáéíóú \d_]的不同字符。reference:删除[a-z ÁÉÍÓÚáéíóú\d.,;:#*^\/]的不同字符。description:删除[a-zÁÉÍÓÚáéíóú \d_]的不同字符。
包裹
additionalInfo:删除[a-z ÁÉÍÓÚáéíóú\d.,;:#*^\/]的不同字符。costCenter:删除[a-zÁÉÍÓÚáéíóú \d_]的不同字符。
参考
betweenStreet:删除[a-zÁÉÍÓÚáéíóú \d_]的不同字符。andStreet:删除[a-zÁÉÍÓÚáéíóú \d_]的不同字符。shed:删除[a-zÁÉÍÓÚáéíóú \d_]的不同字符。platform:删除[a-zÁÉÍÓÚáéíóú \d_]的不同字符。references:删除[a-zÁÉÍÓÚáéíóú \d_]的不同字符。
如果您想在某些模型上禁用此净化,请设置
Reference::disablePrepareData();
您还可以添加自己的净化方法
Reference::registerPrepareCallbacks([ 'betweenStreet' => [MyOwnCleaner::class, 'sizeTruncate'] ]);
请参阅CleanerTest获取更多示例。
贡献
欢迎拉取请求。对于重大更改,请先打开一个问题来讨论您想要更改的内容。
请确保适当更新测试。
许可
Apache许可证。有关更多信息,请参阅许可证文件。
致谢
待办事项
- 设置CD工作流程:我需要一个秘密文件来运行测试
- 验证模型:根据Estafeta Web App规则验证模型属性。
- 改进文档:也许ReadTheDocs,使用markdown等...