prodevcon/dc-api-wrapper

Buyoda - 数据收集器API包装器

v3.0.0 2021-08-17 10:23 UTC

This package is auto-updated.

Last update: 2024-09-17 16:50:33 UTC


README

这个库用于轻松使用 DataCollector API。它将API响应映射到适当的模型(对象),以便在任意应用程序中轻松使用。检查模型以获取可用的方法调用。

API调用需要认证令牌。请在使用库之前确保获取令牌。

use DataCollector\Api\Client;
use DataCollector\Api\Service\Url\UrlApiService;
use DataCollector\Api\Service\Company\CompanyApiService;
use DataCollector\Api\Service\Company\CompanyImportApiService;

/* Auhtenticate User */
$authToken = '###auth_token###';
$client = new Client($authToken);

可用服务

公司服务
/* Initialize service */
$companyApiService = new CompanyApiService($client);

/* Get Company by id */
$request = $companyApiService->get(5347, CompanyApiService::RESPONSE_JSON);

/* Get Company by url string */
$request = $companyApiService->getByUrl('http://www.felbo.ch', CompanyApiService::RESPONSE_JSON);

/* Find Companies by keyword */
$request = $companyApiService->find('Computer Repair', CompanyApiService::RESPONSE_JSON);

/* Get Companies by import name */
$request = $companyApiService->getByImportName([
	'e-fon ag',
	'1 Computer',
	'abraxas informatik ag'
], CompanyApiService::RESPONSE_JSON);

/** Get Companies by import */
$request = $companyApiService->getByImport([
		'name'      => 'e-fon ag',
		'country'   => 'switzerland',
		'in_queue'  => 1
	], 
	CompanyApiService::RESPONSE_JSON);

公司导入服务
/* Initialize service */
$companyImportApiService = new CompanyImportApiService($client);

/* Get Company Import by rule id */
$request = $companyImportApiService->getByRule(54, CompanyImportApiService::RESPONSE_JSON);

/* Get Company Import by rule id with Google Analytics */
$request = $companyImportApiService->getByRuleWithGoogleAnalytics(54, CompanyImportApiService::RESPONSE_JSON);
URL服务
/* Initialize service */
$urlApiService = new UrlApiService($client);

/* Get URL by id */
$request = $urlApiService->get(3011, UrlApiService::RESPONSE_JSON);

/* Get Url by url string */
$request = $urlApiService->getByUrl('http://www.felbo.ch', UrlApiService::RESPONSE_JSON);

/* Find Urls by keyword */
$request = $urlApiService->find('Computer Repair', UrlApiService::RESPONSE_JSON);

Kompass服务
/* Initialize service */
$kompassApiService = new KompassApiService($client);

/* Get Kompass by import */
$request = $kompassApiService->getByImport([
		'name'      => 'e-fon ag',
		'country'   => 'switzerland'
	], KompassApiService::RESPONSE_JSON);

请求

$request 将包含一个 \GuzzleHttp\Psr7\Psr7\Request 对象

/* Get response headers */
$request->getHeaders() /* Array of response header values*/

/* Get response content */
$request->getBody();

结果构建器(例如,UrlApiService)

/* Build Result / Serialize API Response to objects/models */

/* Url Service - Get */
$urlApiService->buildResult($request->getBody(), UrlApiService::URL, CompanyApiService::RESPONSE_JSON);
/* Url Service - Get By URL  */
$urlApiService->buildResult($request->getBody(), UrlApiService::URL_BY_URL, CompanyApiService::RESPONSE_JSON);
/* Url Service - Find */
$urlApiService->buildResult($request->getBody(), UrlApiService::URL_FIND, CompanyApiService::RESPONSE_JSON);

安装

推荐通过 Composer 安装DataCollector API包装器。

php composer.phar require prodevcon/dc-api-wrapper

安装后,您需要要求Composer的自动加载器并注册注解到AnnotationRegistry(由 jms/serializer 需要)

use Doctrine\Common\Annotations\AnnotationRegistry;

$loader = require __DIR__ . '/vendor/autoload.php';
AnnotationRegistry::registerLoader([$loader, 'loadClass']);