承接 sentimo/php-client 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

sentimo/php-client

最新稳定版本:1.2.1

Composer 安装命令:

composer require sentimo/php-client

包简介

A PHP client for interacting with the Sentimo API to perform sentiment analysis.

README 文档

README

Welcome to the Sentimo PHP Client SDK! This SDK provides an easy-to-use interface for interacting with the Sentimo API, allowing you to post and retrieve customer reviews effortlessly.

Table of Contents

Installation

To install the Sentimo PHP Client SDK, use Composer:

composer require sentimo/php-client

Usage

Initializing the Client

First, you need to initialize the Client to interact with the Sentimo API. The ClientFactory class helps you create a configured instance of the Client using your API key.

use Sentimo\Client\HttpClient\ClientFactory;

$apiKey = 'your-api-key-here';
$clientFactory = new ClientFactory();
$client = $clientFactory->createClient($apiKey);

Posting Reviews

To post reviews, you can use the postReviews method. This method accepts an array of ReviewInterface objects and an optional channel parameter.

use Sentimo\Client\Api\Data\ReviewInterface;
use Sentimo\Client\Api\Data\AuthorInterface;
use Sentimo\Client\Api\Data\ProductInterface;

// Example Review, Author, and Product objects (these would be created according to your implementation)
$review = new class implements ReviewInterface {
// Implement the methods of ReviewInterface
};

$reviews = [$review];
$channel = 'your-channel'; // Optional

try {
    $postedReviewIds = $client->postReviews($reviews, $channel);
    echo 'Posted Reviews: ' . implode(', ', $postedReviewIds);
} catch (LocalizedException $e) {
    echo 'Error posting reviews: ' . $e->getMessage();
    
}

Fetching Reviews

To fetch reviews, you can use the getReviews method. You can optionally pass a ReviewGetRequestParamBuilder to filter and structure your request.

use Sentimo\Client\RequestParam\ReviewGetRequestParamBuilder;

$paramBuilder = new ReviewGetRequestParamBuilder();
$paramBuilder->setExternalIds(['external-id-1', 'external-id-2'])
             ->setModerationStatus('approved');

try {
    $reviews = $client->getReviews($paramBuilder, true); // true to fetch all pages
    foreach ($reviews as $review) {
        // Process each review
    }
} catch (LocalizedException $e) {
    echo 'Error fetching reviews: ' . $e->getMessage();
}

Client Configuration

The ClientFactory automatically configures the Client instance using a Symfony DI container. You only need to provide your API key, and the factory will handle the rest.

If you need to customize the client configuration further, you can modify the ContainerFactory or use the Symfony Dependency Injection component.

Error Handling

The SDK throws LocalizedException for errors that occur during API calls. You should catch and handle these exceptions in your application code.

try {
    $postedReviewIds = $client->postReviews($reviews, $channel);
} catch (LocalizedException $e) {
    // Handle the error
}

The getErrors method on the Client class can also be used to retrieve a list of errors encountered during operations.

$errors = $client->getErrors();
if (!empty($errors)) {
    foreach ($errors as $error) {
        echo $error . PHP_EOL;
    }
}

Contributing

We welcome contributions! If you find a bug or want to add a new feature, please open an issue or submit a pull request on GitHub.

License

This SDK is released under the MIT License. See the LICENSE file for more information.

统计信息

  • 总下载量: 56
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-09-02