therealartz / amadeus-php
Amadeus Self-Service travel API 的 PHP 库
0.2.1
2019-10-19 15:26 UTC
Requires
- php: >=7.3
- ext-json: *
- guzzlehttp/guzzle: ^6.3
- psr/log: ^1.1
- symfony/cache: ^4.3
Requires (Dev)
- monolog/monolog: ^2.0
- phpunit/phpunit: ^8.4
- symfony/var-dumper: ^4.3
This package is auto-updated.
Last update: 2024-09-20 00:20:01 UTC
README
此库提供了在 PHP 中与 Amadeus Self-Service API 交互的客户端实现。
通过 Composer 安装
composer require therealartz/amadeus-php
快速开始
设置客户端
use Amadeus\Client; $apiKey = 'api_key'; $apiSecret = 'api_secret'; $client = new Client($apiKey, $apiSecret);
在第一次请求之前将执行身份验证,但令牌需要在应用程序端存储,并在每个请求中将它放入客户端。
// TODO: 提供一些示例
航班优惠购物
use Amadeus\Request\Shopping\FlightOffersRequestOptions; $request = new FlightOffersRequestOptions( $origin = 'JFK', $destination = 'ORD', $departureDate = \DateTimeImmutable::createFromFormat('Y-m-d', '2020-03-01'), // Any \DateTimeInterface $returnDate = null, $adults = 2, $children = 0, $infants = 0, $seniors = 0, $travelClass = null, $nonStop = false, $currency = 'USD', $maxResults = 50, $maxPrice = null, $arrivalBy = null, $returnBy = null, $includeAirlines = [], $excludeAirlines = [] ); $results = $client->shoppingFlightOffers($request);
日志记录
要启用创建客户端时的库日志记录,请将 Psr\Log\LoggerInterface
的实例作为第四个参数传递(可选)
use Amadeus\Client; use Monolog\Logger; $client = new Client( $apiKey = 'api_key', $apiSecret = 'api_secret', $isProduction = false, $logger = new Logger( 'amadeus', [ new Monolog\Handler\StreamHandler(__DIR__ . '/var/log/amadeus.log') ] ), );
缓存
要启用创建客户端时的内置库缓存,请将 Symfony\Contracts\Cache\CacheInterface
的实例作为第五个参数传递(PSR-16 目前不支持)(可选)
use Amadeus\Client; use Symfony\Component\Cache\Adapter\FilesystemAdapter; $client = new Client( $apiKey = 'api_key', $apiSecret = 'api_secret', $isProduction = false, $logger = null, $cache = new FilesystemAdapter('amadeus', 0, __DIR__ . '/var/cache'), );