always-open / shipengine
ShipEngine API 包装器
v3.2.1
2024-02-18 01:19 UTC
Requires
- php: ^8.0.0|^8.1.0
- always-open/laravel-request-logger: ^2.1
- guzzlehttp/guzzle: ^7.4
- illuminate/contracts: ^9.0|^10.0
- illuminate/support: ^9.0|^10.0
- spatie/data-transfer-object: ^3.7
- spatie/laravel-package-tools: ^1.9.2
- symfony/property-access: ^6.0
- symfony/serializer: ^6.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.1
- nunomaduro/collision: ^6.0
- nunomaduro/larastan: ^2.0
- orchestra/testbench: ^7.0
- pestphp/pest: ^1.21
- pestphp/pest-plugin-laravel: ^1.1
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- phpunit/phpunit: ^9.5
- spatie/laravel-ray: ^1.26
- 3.x-dev
- v3.2.1
- v3.2.0
- v3.1.1
- v3.1.0
- v3.0.2
- v3.0.1
- v3.0.0
- 2.x-dev
- v2.3.0
- v2.2.1
- v2.1.1
- v2.1.0
- v2.0.2
- v2.0.1
- v2.0.0
- 1.x-dev
- v0.9.1
- v0.9.0
- v0.8.2
- v0.8.1
- v0.8.0
- v0.7.3
- v0.7.2
- v0.7.1
- v0.7.0
- v0.6.0
- v0.5.1
- v0.5.0
- v0.4.0
- v0.3.1
- v0.3.0
- v0.2.0
- v0.1.0
- dev-feature/add-local-limit-to-config
- dev-main
- dev-feature/add-warehouse-endpoints
This package is auto-updated.
Last update: 2024-09-14 10:01:35 UTC
README
ShipEngine API 包装器
安装
您可以通过 composer 安装此包
composer require always-open/shipengine
您可以使用以下命令发布配置文件
php artisan vendor:publish --tag="shipengine-config"
这是已发布配置文件的内容
return [ /* |-------------------------------------------------------------------------- | ShipEngine configurations |-------------------------------------------------------------------------- | | API Key used to authenticate with ShipEngine APIs. | https://www.shipengine.com/docs/auth/ | */ 'credentials' => [ 'key' => env('SHIP_ENGINE_API_KEY'), ], /* |-------------------------------------------------------------------------- | ShipEngine configurations |-------------------------------------------------------------------------- | | Values used to set configuration of ShipEngine API integration. | */ 'endpoint' => [ 'version' => env('SHIP_ENGINE_API_VERSION', 'v1'), 'base' => env('SHIP_ENGINE_ENDPOINT', 'https://api.shipengine.com/'), ], 'retries' => env('SHIP_ENGINE_RETRIES', 1), 'response' => [ 'as_object' => env('SHIP_ENGINE_RESPONSE_AS_OBJECT', false), 'page_size' => env('SHIP_ENGINE_RESPONSE_PAGE_SIZE', 50), ], 'timeout' => 'PT10S', ];
用法
配置
要使用 ShipEngine 包装器,您必须首先实例化一个新实例。
默认情况下,配置信息是从配置文件中读取的,但可以在运行时覆盖。这可以在实例化新实例时完成,这将影响所有后续调用,或者可以在调用时完成。
// Use default config settings from `config/shipengine.php` $shipengine = new AlwaysOpen\ShipEngine\ShipEngine(); // Override config which will impact all calls made with this instance $config = new \AlwaysOpen\ShipEngine\ShipEngineConfig(['asObject' => true]); $custom_shipengine = new AlwaysOpen\ShipEngine\ShipEngine($config); // Override config on a single specific call $shipengine->listShipments(config: ['asObject' => true]);
调用
要调用 ShipEngine API,您必须在 ShipEngine 中设置凭据。这些 API 凭据将由该库用于处理调用和响应。
注意: 此库仍处于 0.x.x 阶段,并非所有端点都已完全映射。我们正在努力实现现有 API 端点的 100% 覆盖率。
方法名称应与官方 ShipEngine API 文档 中的 API 端点文档名称匹配。
示例调用
以下是如何获取运输清单以及 asObject => false
和 asObject => true
之间的区别的示例。
$shipengine = new AlwaysOpen\ShipEngine\ShipEngine(); $shipengine->listShipments(); //[ // "shipments" => [ // [ // "shipment_id" => "se-123456789", // "carrier_id" => "se-123456", // ... // ], // [...], // ], // "total" => 12, // "page" => 1, // "pages" => 1, // "links" => [ // "first" => [ // "href" => "https://api.shipengine.com/v1/shipments?page=1&page_size=25", // ], // "last" => [ // "href" => "https://api.shipengine.com/v1/shipments?page=1&page_size=25", // ], // "prev" => [], // "next" => [], // ], //]; $shipengine->listShipments(config: ['asObject' => true]); // [ // "shipments" => [ // AlwaysOpen\ShipEngine\DTO\Shipment {#4070 // +shipment_id: "se-123456789", // +carrier_id: "se-123456", // ... // ], // [...], // ], // "total" => 12, // "page" => 1, // "pages" => 1, // "links" => [ // "first" => [ // "href" => "https://api.shipengine.com/v1/shipments?page=1&page_size=25", // ], // "last" => [ // "href" => "https://api.shipengine.com/v1/shipments?page=1&page_size=25", // ], // "prev" => [], // "next" => [], // ], //];
测试
composer test
变更日志
有关最近更改的更多信息,请参阅 变更日志。
贡献
有关详细信息,请参阅 贡献指南。
安全漏洞
有关如何报告安全漏洞的详细信息,请参阅 我们的安全策略。
鸣谢
许可证
MIT 许可证 (MIT)。有关更多信息,请参阅 许可证文件。