sellerlabs/nodemws-client

此包已 弃用 且不再维护。作者建议使用 sellerlabs/modernmws-client 包。

SellerLabs 研究API的PHP客户端

v0.3.0 2016-09-15 22:05 UTC

README

这是 SellerLabs 研究API服务的官方PHP客户端库(之前称为NodeMWS/ModernMWS客户端)。

要求

  • PHP +5.6 或 HHVM +3.6。
  • Composer 和 autoload.php
  • 当然:使用研究服务的凭证。

文档

安装 & 使用

使用 Composer

首先,将此包添加到您的 composer.json

    // ...
    "require": {
        "sellerlabs/research-php": "*"
    }
    // ...

然后运行 composer update

如何与 Laravel 5 一起使用

首先,您需要在您的应用程序服务提供程序内配置客户端

public function register()
{
    $this->app->bind(
        SellerLabs\Research\Interfaces\ResearchClientInterface::class,
        function () {
            return new ResearchClient(
                'YourClientId',
                'YourClientSecret',
                'http://research.api.sellerlabs.com'
            );
        }
    );
}

然后,在您的任何控制器中,您可以通过构造函数注入依赖项

// ...
class ProductsController extends Controller
{
    /**
     * Implementation of a client for SellerLabs' research API
     *
     * @var ResearchClientInterface
     */
    protected $researchClient;

    /**
     * Construct an instance of a ProductsController
     */
    public function __construct(ResearchClientInterface $researchClient)
    {
        $this->researchClient = $researchClient;
    }

    /**
     * Handle GET /products/
     */
    public function getIndex()
    {
        return $this->researchClient->getSearch('keyword', 'testing');
    }
}

Laravel 的容器足够智能,可以自动执行依赖注入,在初始化控制器类时为您添加客户端参数