urieldavid/desafio_xlr8_php
最新稳定版本:v2.2.0
Composer 安装命令:
composer require urieldavid/desafio_xlr8_php
包简介
XLR8 Backend Interview
README 文档
README
Project to develop PHP package for testing in XLR8. The project consists of creating a PHP library to consume the XLR8 API, and with that, through the coordinates of Latitude and Longitude, generate a list of hotels closest to you or cheaper.
Library Setup with Composer
composer require urieldavid/desafio_xlr8_php
After that, it is necessary to create the json, config.json in the root of the project, with valid endpoints to use the library, below is an example of the file:
{
"source_1": "https://xlr8-interview-files.s3.eu-west-2.amazonaws.com/source_1.json",
"source_2": "https://xlr8-interview-files.s3.eu-west-2.amazonaws.com/source_2.json"
}
Use the library
use XLR8\Exception\XLR8Exception; use XLR8\Search; require implode(DIRECTORY_SEPARATOR, [__DIR__, "vendor", "autoload.php"]); try { $search = new Search(); $search->getNearbyHotels(41.157944, -8.629105, "pricepernight"); } catch (XLR8Exception $e) { echo $e->getMessage(); }
OR
use XLR8\Exception\XLR8Exception; use XLR8\Search; require implode(DIRECTORY_SEPARATOR, [__DIR__, "vendor", "autoload.php"]); try { $options = [ 'page' => 1, 'limit' => 15, 'responseJson' => false | true, 'selectSource' => null | 'source_1' | 'any other endpoint in config.json' ]; $search = new Search(); $search->getNearbyHotels(41.157944, -8.629105, "pricepernight", $options); } catch (XLR8Exception $e) { echo $e->getMessage(); }
Obs.:
-
Default param required
getNearbyHotels($latitude, $longitude) -
To set sort by
"pricepernight"=>getNearbyHotels($latitude, $longitude, "pricepernight") -
By default sorting is by
"proximity" -
Param options:
$options = [ 'page' => 1, 'limit' => 15, 'responseJson' => false | true, 'selectSource' => null | 'source_1' | 'any other endpoint in config.json' ];
Obs-1.: By default it will bring all the results, if you want pagination then you need to pass the values in the options param,
$page => selected pageand$limit => data limit per page.Obs-2.: It is optional but there is the possibility of setting the information cache time,
new Search(3600);, in this case 3600 seconds are equivalent to 1 hour, by default the cache is 1 day 42300 seconds.
统计信息
- 总下载量: 7
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-05-19