crowdvalley / crowdentials-api-wrapper
此包已废弃,不再维护。未建议替代包。
提供 Crowdentials Api 的包装器
0.1.0
2014-07-09 16:53 UTC
Requires
- php: >=5.3.0
- kriswallsmith/buzz: 0.10.*
Requires (Dev)
- henrikbjorn/phpspec-code-coverage: 0.1.*
- phpspec/phpspec: 2.0.*
This package is not auto-updated.
Last update: 2016-10-07 17:27:35 UTC
README
提供 Crowdentials Api 的包装器。
安装
通过 Composer 设置
首先,将其添加到您的 composer.json
文件中的依赖列表中
{ "require": { "crowdvalley/crowdentials-api-wrapper": "dev-master" } }
然后,只需使用 Composer 安装即可
$> composer update crowdvalley/crowdentials-api-wrapper
示例
发送认证请求
use Crowdvalley\Crowdentials\Api\Accreditation\Wrapper as ApiWrapper;
use Crowdvalley\Crowdentials\Api\Accreditation\Creation\Request;
$api = new ApiWrapper('your-key');
// Prepares the accreditation request
$request = new Request('John', 'Doe', 'johnd@foo.bar', '123', 'Client Inc');
// Calls the api
$process = $api->create($request);
/* Gets process info */
// The id of the request that has been entered into the Crowdentials system
echo $process->getId();
echo "\r\n";
// The timestamp for when the request was created in the Crowdentials system
echo $process->getCreated()->format('Y-m-d H:i:s');
echo "\r\n";
获取认证请求
use Crowdvalley\Crowdentials\Api\Accreditation\Wrapper as ApiWrapper;
use Crowdvalley\Crowdentials\Api\Accreditation\Checking\Response;
$api = new ApiWrapper('your-key');
// The id of the request for which you would like to receive information
$id = 123;
// Calls the api
$response = $api->check($id);
/* Checks response */
if ($response->isSubmitted()) {
echo "Accreditation was submitted.";
} elseif ($response->isPending()) {
echo "Accreditation is pending.";
} elseif ($response->isVerified()) {
echo "Accreditation is verified.";
}
/* Or compares the state directly */
if ($response->getState() == Response::STATE_VERIFIED) {
echo "Accreditation is verified.";
}
/* Gets more fields */
// The first name of the verifier entered by the investor
$response->getFirstName();
// The last name of the verifier entered by the investor
$response->getLastName();
// The date the investor was verified on
$response->getDate();
移除认证请求
use Crowdvalley\Crowdentials\Api\Accreditation\Wrapper as ApiWrapper;
use Crowdvalley\Crowdentials\Api\Accreditation\Removal\SuccessResponse;
use Crowdvalley\Crowdentials\Api\Accreditation\Removal\FailureResponse;
$api = new ApiWrapper('your-key');
// The id of the request for which you would like to remove
$id = 123;
// Calls the api
$response = $api->remove($id);
/* Checks response */
if ($response instanceof SuccessResponse) {
echo "Accreditation removed successfully";
} elseif ($response instanceof FailureResponse) {
echo "Accreditation was not removed.";
if ($response->wasDenied()) {
echo sprintf("Access denied. Please check your permissions on the accreditation %s.", $id);
} elseif ($response->wasRemoved()) {
echo sprintf("The accreditation %s was already removed", $id);
} elseif ($response->wasCompleted()) {
echo sprintf("The accreditation %s was already completed", $id);
}
}
/* Or gets the error directly */
if ($response instanceof SuccessResponse) {
echo "Accreditation removed successfully";
} elseif ($response instanceof FailureResponse) {
echo "Accreditation was not removed. We get an error from the server:\r\n";
echo $response->getReason();
}