answear/overseas-bundle

海外API的Symfony包。

安装数: 9,817

依赖关系: 0

建议者: 0

安全: 0

星标: 0

关注者: 3

分支: 0

开放问题: 0

类型:symfony-bundle

2.3.0 2024-09-03 08:55 UTC

This package is auto-updated.

Last update: 2024-09-03 09:49:47 UTC


README

Symfony的海外集成。
API文档可在此处找到: https://api.overseas.hr/apiinfo

安装

  • 使用Composer安装
composer require git@github.com:answear/overseas-bundle.git

Answear\OverseasBundle\AnswearOverseasBundle::class => ['all' => true],
应该由Symfony Flex自动添加到您的 config/bundles.php 文件中。

配置

  • 提供所需的配置数据: 环境apiKey
# config/packages/answear_overseas.yaml
answear_overseas:
    environment: test|prod
    apiKey: yourApiKey
    logger: yourCustomLoggerService #default: null

Logger服务必须实现 Psr\Log\LoggerInterface 接口。

使用

获取包裹店

@see https://api.overseas.hr/apiinfo#parcelshops

/** @var \Answear\OverseasBundle\Service\ParcelShopsService $parcelShopService **/
$parcelShopService->get();

将返回 \Answear\OverseasBundle\Response\DTO\ParcelShop[] 数组。

获取地点

@see https://api.overseas.hr/apiinfo#places

$zipCode = 12345;
$name = 'name';
$approx = true;

/** @var \Answear\OverseasBundle\Service\PlacesService $placesService **/
$placesService->get($zipCode, $name, $approx);

将返回 \Answear\OverseasBundle\Response\DTO\Place[] 数组,根据参数缩小范围。或者简单地

$placesService->get();

获取所有地点。

错误处理

  • Answear\OverseasBundle\Exception\ServiceUnavailableException 用于所有 GuzzleException
  • MalformedResponseException 用于合作伙伴其他错误
  • Answear\OverseasBundle\Exception\BadRequestException 如果验证失败或为错误响应

最后说明

请随意提交具有新功能、改进或错误修复的拉取请求。Answear团队将非常感激任何评论。