europeansourcing / api-php-client
此包已被废弃,不再维护。未建议替代包。
此包的最新版本(1.0)没有可用的许可证信息。
EuropeanSourcing API 的 PHP 客户端
1.0
2017-02-06 15:13 UTC
Requires
- php: >=5.3.0
- symfony/property-access: ^3.2
Requires (Dev)
- phpunit/phpunit: ^4.8
- symfony/var-dumper: ^3.2
This package is not auto-updated.
Last update: 2021-01-29 03:50:37 UTC
README
PHP API 客户端,用于搜索 Europeansourcing 产品数据库
安装
将 europeansourcing/api-php-client
添加到您的 composer.json
文件中
composer require europeansourcing/api-php-client
用法
如果您在本地主机上安装了 /api-php-client,可以通过 https:///api-php-client/example 调用来查看所有示例。
确保您在本地主机上,以便可以使用 "dump" 功能。
<?php use EuropeanSourcing\Api\ElasticSearch\Client; use EuropeanSourcing\Api\ElasticSearch\SearchRequest; use EuropeanSourcing\Api\ApiCaller\CurlCaller; use EuropeanSourcing\Api\Transformer\ArrayTransformer; require '../vendor/autoload.php'; // Token given by EuropeanSourcing $token = 'O5L2T01JWVR5GQ05KIZHJ63DB3TSTAY4'; // api caller // perform the call to API $apiCaller = new CurlCaller($token); // data transformer $transformer = new ArrayTransformer(); // api client // organise the call to API, the transformation and the response $client = new Client($apiCaller, $transformer, $url); // search request object // Handle all parameters of your search $searchRequest = new SearchRequest(); $searchRequest->setQuery('stylo'); $searchRequest->setLanguage('fr'); // Do a search (see Client.php for the list of function) $response = $client->search($searchRequest, 0, 1); // array response dump($response);
这是一个简单的示例之一。它根据 $searchRequest 的内容进行搜索,并基于转换器返回 $results。由于我们通过 "ArrayTransformer" 传递它,因此我们得到一个 $results 的数组。您可以将自己的转换器传递给 $client
转换器之一是 ModelTransformer。它不是有 json 或数组,而是构建整个实例结构。您可以复制/粘贴模型文件夹到您的项目中(如果您想修改它),然后只需更改命名空间即可
// our transformer (build model from results) $modelNamespace = '\\EuropeanSourcing\\Api\\Model\\'; $transformer = new ModelTransformer($modelNamespace);
要获取搜索的所有输入参数,可以查看 SearchRequest 文件,所有参数都有文档说明。
低级 API
如果您不想使用 SearchRequest/Client、模型等(不建议这样做),可以直接调用 URL。
您可以使用 GET 或 POST
// search products + aggregations (facets) http://ws.europeansourcing.com/api?q=pen&language=en&sort=price&s[]=1774&token=O5L2T01JWVR5GQ05KIZHJ63DB3TSTAY4 // categories http://ws.europeansourcing.com/api/categories?q=pen&language=en&sort=price&s[]=1774&token=O5L2T01JWVR5GQ05KIZHJ63DB3TSTAY4 // brands http://ws.europeansourcing.com/api/brands?q=pen&language=en&sort=price&s[]=1774&token=O5L2T01JWVR5GQ05KIZHJ63DB3TSTAY4 // date of last modification http://ws.europeansourcing.com/api/last-modified?q=pen&language=en&sort=price&s[]=1774&token=O5L2T01JWVR5GQ05KIZHJ63DB3TSTAY4 // images (you should use http cache) http://www.europeansourcing.com/products/{id_image}-400x400.jpg
以下是一系列原始参数
page => (int) page number limit => (int) number of products per page q => (string) text query b => (integer) one brand id s[] => (array) supplier ids c[] => (array) category ids a[] => (array) attribute ids prix_min => (float) min price prix_max => (float) max price withstockonly => (integer 0|1) has stock not_ids[] => (array) ids exclusion ids[] => (array) ids inclusion variantIds[] => (array) variant ids inclusion withaggs => (integer 0|1) add aggregations (facets) language => (string fr|en|de|it|es|nl|pt) language aschema => (string plain|tree) schema for attributes cschema => (string plain|tree) schema for categories sort => (string random|price|update|score) sort sens => (string asc|desc) sens aop => (string or|and) attributes operator cop => (string or|and) categories operator last_updated => (string) today|yesterday|last_24h
考虑使用 chrome/firefox 的扩展程序来检查 Json(例如 Jsonview)