sambo-search/sambo-search-client
最新稳定版本:0.2.1
Composer 安装命令:
composer require sambo-search/sambo-search-client
包简介
PHP API Client for Sambo-Search API
README 文档
README
Synopsis
This is a simple PHP client for the Sambo-Search API. It simplifies the usage of the API by providing many helper functions and easy access to the API suite.
Prerequisites
- PHP >= 8.1
- Composer
Install
Install via Composer:
composer require sambo-search/sambo-search-client
Usage
If you are not sure where to find your shops' public key, open the Sambo-Search Dashboard and navigate to Account > Shops.
Sending a simple search request
- Create a new
Clientinstance:$client = \SamboSearch\Client\Client::getInstance([ 'public_key' => '<your-public-key-here>' ]);
- Build your search request:
$request = $client->buildSearchRequest(); $request->setQuery('backpack') // Search query ->setFilter('color', 'Black'); // Filters
- Send request and parse response:
/** @var \SamboSearch\Client\Response\SearchResponse $response */ $response = $client->send($request); $products = $response->getProducts(); foreach ($products as $product) { echo 'ID: ' . $product->getId() . "\n<br>"; echo 'Name: ' . $product->getName() . "\n<br>"; }
Full example (same as from above, but with imports):
<?php use SamboSearch\Client\Client; use SamboSearch\Client\Response\SearchResponse; $client = Client::getInstance(['public_key' => '<your-public-key-here>']); // Apply any filters or sorting $request = $client->buildSearchRequest(); $request->setQuery('backpack') // Search query ->setFilter('color', 'Black'); // Filters /** @var SearchResponse $response */ $response = $client->send($request); // Access product details $products = $response->getProducts(); foreach ($products as $product) { echo 'ID: ' . $product->getId() . "\n<br>"; echo 'Name: ' . $product->getName() . "\n<br>"; }
Documentation
Most methods include a PHPDoc block that simply explains their usage. Here is an example from the SearchRequest class:
/** * Selects a filter with the given identifier and value. Examples: * * $searchRequest->addFilter(['manufacturer', 'Sambo-Search']); // /api/v1/search?manufacturer=Sambo-Search * $searchRequest->addFilter(['color', 'Green|Yellow']); // /api/v1/search?color=Green%7CYellow * $searchRequest->addFilter(['color', ['Green', 'Yellow']]); // same /api/v1/search?color=Green%7CYellow * $searchRequest->addFilter([ * 'categories', * 'Dogs|Food|Wet Food' * ]); // /api/v1/search?categories=Dogs%7CFood%7CWet%20Food * $searchRequest->addFilter(['price-', '10.99']); // min price /api/v1/search?price-=10.99 * $searchRequest->addFilter(['price', '35.00']); // max price /api/v1/search?price=35.00 * */ public function addFilter(string $identifier, string|array $values): static
统计信息
- 总下载量: 7
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-06-30