vrakita / contentlocalizedgeneralapi
该软件包最新版本(v1.0.40)没有提供许可证信息。
通过API进行排序的本地化内容PHP库
v1.0.40
2016-04-27 11:18 UTC
Requires
- vlucas/phpdotenv: ^2.2
Requires (Dev)
- phpunit/phpunit: 4.7.*
This package is not auto-updated.
Last update: 2024-09-20 19:09:27 UTC
README
Content Localized General API用于计算订单价格和创建新项目。如果您不想从ContentLocalized网站创建订单,现在您可以使用API将其集成到自己的系统中,并在订单完成后立即收到通知。
安装
将此内容添加到您的composer.json中
{
"require": {
"vrakita/contentlocalizedgeneralapi": "1.*"
},
"config": {
"preferred-install": "dist"
}
}
更新您的依赖关系
composer update
创建包含您的ContentLocalized凭证的.env文件
CL_EMAIL=mymail@firstbeatmedia.com
CL_PASSWORD=secretpassword
CL_SSL=1
创建新订单的示例
<?php
require 'vendor/autoload.php';
try {
// In Order constructor you have to pass path to directory where .env file with your credentials is placed
$order = new \CLGeneralAPIClient\Translation\Order(__DIR__);
$order
// Your project name
->setProjectName('API Project')
// Content for translation
->setContent('Hello World')
// Set language of your content
->setSourceLanguage('gb')
// Set desired language(s) for your translation
->setTranslationLanguage(['de', 'fr'])
// Option for delivery
->setDelivery(1)
// Use sandbox mode
->sandbox(true)
// Log errors to custom directory
->log(__DIR__)
// Create order
->create();
print_r(json_decode($order));
} catch (\Exception $e) {
exit($e->getMessage());
}
计算价格并创建新订单的示例
<?php
require 'vendor/autoload.php';
try {
// In Order constructor you have to pass path to directory where .env file with your credentials is placed
$order = new \CLGeneralAPIClient\Translation\Order(__DIR__);
$calculation = $order
// Your project name
->setProjectName('API Project')
// Content for translation
->setContent('Hello World')
// Set language of your content
->setSourceLanguage('gb')
// Set desired language(s) for your translation
->setTranslationLanguage(['de', 'fr'])
// Option for delivery
->setDelivery(1)
// Use sandbox mode
->sandbox(true)
// Log errors to custom directory
->log(__DIR__);
// We now have price of our order and if we are good with it we can confirm that order
$calculation = json_decode($order->calculate());
// We are OK with the price and we can now create order based on calculate order parameters
if($calculation->price < 1000) {
$response = $order->create();
print_r(json_decode($response));
}
} catch (\Exception $e) {
exit($e->getMessage());
}
其他方法
<?php
require 'vendor/autoload.php';
/**
* Load order info by id
*/
try {
$info = new \CLGeneralAPIClient\Order\GeneralInformation(__DIR__);
$order = $info->loadOrder(2);
print_r(json_decode($order));
} catch (\Exception $e) {
echo $e->getMessage();
}
/**
* Check is desired language combination available
*/
try {
$info = new \CLGeneralAPIClient\Translation\Info(__DIR__);
$combination = $info->availableTranslation('gb', 'fr');
print_r(json_decode($combination));
} catch (\Exception $e) {
echo $e->getMessage();
}
/**
* Load all language combinations
*/
try {
$info = new \CLGeneralAPIClient\Translation\Info(__DIR__);
$combinations = $info->allCombinations();
print_r(json_decode($combinations));
} catch (\Exception $e) {
echo $e->getMessage();
}
/**
* Available options for project delivery
*/
try {
$info = new \CLGeneralAPIClient\Order\GeneralInformation(__DIR__);
$delivery = $info->getDelivery();
print_r(json_decode($delivery));
} catch (\Exception $e) {
echo $e->getMessage();
}
/**
* Available PG ratings
*/
try {
$info = new \CLGeneralAPIClient\Order\GeneralInformation(__DIR__);
$ratings = $info->getRatings();
print_r(json_decode($ratings));
} catch (\Exception $e) {
echo $e->getMessage();
}