tmarois / baseify-php-sdk
此包已被废弃,不再维护。未建议替代包。
此包的最新版本(v1.0.8)没有可用的许可证信息。
Baseify API - PHP SDK
v1.0.8
2018-11-28 09:14 UTC
Requires
- php: >=7.0
- basephp/support: 1.*
- guzzlehttp/guzzle: ^6.3
Requires (Dev)
- phpunit/phpunit: ^6
- satooshi/php-coveralls: ^2.0
README
此SDK用于baseify.com发布者API的产品搜索
。
安装
Composer 安装包。
使用 composer require tmarois/baseify-php-sdk
配置使用
$baseify = (new Baseify('YOUR_CLIENT_KEY'))->productSearch([ 'domain' => 'yourdomain.com' ]); // set the users IP address // This allows the API to return the proper results $baseify->user()->set('ip',$testIp); // set the user agent (also a requirement) $baseify->user()->set('ua',$testAgent); // how many items do you want to limit this request to $baseify->filter()->set('limit',10);
查询使用
// send in the query request $results = $baseify->query('car chargers'); // get a list of all the products returned $products = $results->getProducts(); // count how many products are returned $products->count(); // get a list of the stores in the results $stores = $results->getStores(); // get a list of the brands in the results $brands = $results->getBrands(); // get a list of the brands in the results $categories = $results->getCategories();
结果
使用 query()
方法返回 Baseify\Api\ProductSearch\Results
方法 | 描述 |
---|---|
getRaw() |
获取原始 JSON 结果 |
getStatus() |
获取结果状态 |
getMessage() |
获取结果状态消息 |
getEndpoint() |
获取完整的API请求URL |
getStores() |
获取一个从产品中拉取的商店 array |
getBrands() |
获取一个从产品中拉取的品牌 array |
getCategories() |
获取一个从产品中拉取的类别 array |
getCategoryWithIds() |
获取类别和类别ID |
getProducts() |
以 Collection 对象的形式获取产品 |
toArray() |
获取整个结果数组 |
产品集合
getProducts()
返回使用来自 basephp\support 的 Collection
对象的结果,以下是一些有用的方法。
方法 | 描述 |
---|---|
all() |
获取集合中的所有项 |
has($key) |
如果参数定义,则返回true。 |
get($key, $default) |
获取指定的值。 |
first() |
从集合中获取第一个项。 |
last() |
从集合中获取最后一个项。 |
shuffle() |
对集合中的项进行洗牌。 |
slice() |
切割底层的集合数组。 |
reverse() |
反转项的顺序。 |
remove($key) |
移除项。 |
count() |
返回项的数量。 |
take($limit) |
获取第一个或最后一个 {$limit} 个项。 |
map($callable) |
对每个项运行映射。 |
pluck($value, $key) |
获取给定键的值。 |
random($number) |
随机获取一个或多个项。 |
sort($callable) |
通过回调对每个项进行排序。 |
filter($callable) |
对每个项运行过滤器。 |
where($key, $operator, $value) |
通过给定的键值对过滤项。 |
whereIn($key, $values) |
通过给定的键值对过滤项。 |
push($value) |
将项推送到集合的末尾。 |
pull($value) |
从集合中获取并移除项。 |
put($key, $value) |
通过键将项放入集合中。 |
toArray() |
获取项的集合作为纯数组。 |
toJson() |
获取项的集合作为JSON。 |
资源
贡献
任何人都可对 baseify-php-sdk 项目做出贡献。请通过发布问题时发现意外情况或发送改进的拉取请求来参与。
许可证
baseify-php-sdk 是开源软件,使用 MIT 许可证。