cex
1.0.0
ไคลเอนต์ PHP สำหรับ Ajax API ภายในของ cex UK
ไคลเอนต์นี้ถูกสร้างขึ้นจากวิศวกรรมย้อนกลับการตอบสนองของ Ajax เมื่อเรียกดูเว็บไซต์ ดังนั้นจึงถือว่าถือว่ามาก
ได้รับอนุญาตภายใต้ MIT - ดู LICENSE.md สำหรับข้อมูลเพิ่มเติม
composer require liamja/ cex
vendor/bin/phpunit
สร้างอินสแตนซ์ใหม่ของไคลเอนต์ cex :
$ cex = new cex Client ();
ผลิตภัณฑ์แต่ละรายการจะเรียกว่า กล่อง
// Specify a new set of search parameters.
$ searchParameters = new SearchParameters ();
$ searchParameters -> setSearchTerm ( ' Super Mario Bros ' );
// Search for boxes that match our parameters.
$ boxes = $ cex -> searchBoxes ( $ searchParameters );
// cex Client::searchBoxes() returns an array of Liamja cex ModelsBox
foreach ( $ boxes as $ box ) {
// Get the box's unique ID.
echo $ box -> boxId ; // 045496901738
// Get the box's name.
echo $ box -> boxName ; // New Super Mario Bros. Wii
// Get the category the box belongs to.
echo $ box -> categoryName ; // Wii Software
// Get the cash price.
echo $ box -> cashPrice ; // 5.00
// Get the trade-in / exchange price.
echo $ box -> exchangePrice ; // 8.00
// Get the sale price.
echo $ box -> salePrice ; // 12.00
}
หากต้องการค้นหาหุ้นใกล้สถานที่ คุณจะต้องค้นหาร้านค้าก่อน
API จะส่งคืนชุดร้านค้าที่ใกล้เคียงกับละติจูดและลองจิจูดที่กำหนดมากที่สุด
การระบุพิกัดทางภูมิศาสตร์ไม่ได้อยู่ในขอบเขตของแพ็คเกจนี้ แต่คุณสามารถค้นหาละติจูดและลองจิจูดโดยประมาณของสถานที่ได้โดยใช้บริการระบุพิกัดทางภูมิศาสตร์ เช่น http://geocode.xyz:
// Set up a new Guzzle client solely for geocoding.
$ geocodeClient = new GuzzleHttp Client ([
' base_uri ' => ' https://geocode.xyz/ ' ,
]);
$ response = $ geocodeClient -> get ( ' Manchester, UK ' . ' ?json=1 ' );
$ results = json_decode ( $ response -> getBody ()-> getContent ());
// Use the geocoding results to find stores closest to Manchester.
$ stores = $ cex -> nearestStores ( $ results -> latt , $ results -> longt );
วิธีค้นหาร้านค้าที่ใกล้กับลองจิจูดและละติจูดมากที่สุด:
// First, you'll need the lat/long of the location you want to search.
$ latitude = 52.62343240000001 ;
$ longitude = 1.3077290999999605 ;
// Search for stores closest to a given location.
$ stores = $ cex -> nearestStores ( $ latitude , $ longitude );
// cex Client::nearestStores() returns an array of Liamja cex ModelsNearestStore
foreach ( $ stores as $ store ) {
// Get the store's unique ID.
echo $ store -> storeId ; // 168
// Get the store's name.
echo $ stores -> storeName ; // Norwich
// How far away the store is from the given location, in miles.
echo $ stores -> distance ; // 0.47
// Opening days and times.
echo $ box -> timings [ ' open ' ][ ' monday ' ]; // 9:00
echo $ box -> timings [ ' close ' ][ ' friday ' ]; // 18:00
}
$ stores = $ cex -> getStores ();
// cex Client::getStores() returns an array of Liamja cex ModelsStore
foreach ( $ stores as $ store ) {
// Get the store's unique ID.
echo $ store -> storeId ; // 168
// Get the store's name.
echo $ stores -> storeName ; // Norwich
// Get the store's region.
echo $ stores -> storeName ; // East Anglia
}
// Search for stores closest to a given location.
$ stores = $ cex -> nearestStores ( 52.62343240000001 , 1.3077290999999605 );
// Get the nearest store's ID.
$ storeId = $ stores [ 0 ]->storeId
// Search for stocked Battletoads at our nearest store.
$ searchParameters = new SearchParameters ();
$ searchParameters
-> setSearchTerm ( ' Battletoads ' )
-> setStoreId ( $ storeId )
-> isInStock ();
$ boxes = $ cex -> searchBoxes ( $ searchParameters );
หาก API ส่งกลับข้อผิดพลาด FailureException จะถูกส่งออกไป:
try {
$ boxes = $ cex -> searchBoxes ( $ searchParameters );
} catch ( Liamja cex FailureException $ e ) {
echo $ e -> getMessage (); // "Missing search text"
echo $ e -> getCode (); //
echo $ e -> getMoreInfo (); // []
}
$ cex = new cex Client ();
// Search for 'Battleloads' titles that are in stock.
$ searchParameters = new SearchParameters ();
$ searchParameters
-> setSearchTerm ( ' Battletoads ' )
-> isInStock ();
$ boxes = $ cex -> searchBoxes ( $ searchParameters );
var_dump ( $ boxes );
// Search using their predictive search (seems better at sorting by relevancy.)
$ searchParameters = new SearchParameters ();
$ searchParameters -> setSearchTerm ( ' Super Mario Bros ' );
$ results = $ cex -> predictiveSearch ( $ searchParameters );
var_dump ( $ results );
// Search for stores closest to a given location.
$ stores = $ cex -> nearestStores ( 52.62343240000001 , 1.3077290999999605 );
var_dump ( $ stores );
// Show all stores in the country.
$ stores = $ cex -> getStores ();
var_dump ( $ stores );