pxgamer / devrant-php
一个简单的PHP包装器,用于利用devRant API。
v1.2.2
2017-11-02 14:37 UTC
Requires
- php: >=5.6.0
- ext-curl: *
Requires (Dev)
- phpunit/phpunit: ^5.7.23 || ^6.4.3
README
一个简单的PHP包装器,用于利用devRant api。
用法
包含类
- 使用Composer
composer require pxgamer/devrant-php
<?php require 'vendor/autoload.php';
- 手动包含文件
<?php include 'src/Connection.php'; include 'src/Rant.php';
包含后,您可以使用以下任一方式初始化类
$devRant = new \pxgamer\devRant\Connection();
use \pxgamer\devRant\Connection; $devRant = new Connection();
类方法
示例
获取rant数组
$devRant = new \pxgamer\devRant\Connection; $devRant->getRants(); // Get rants $devRant->getRants($searchterm); // Get rants using a search query
失败时返回false,或
[
0 => Rant object,
1 => Rant object,
...
]
通过ID获取单个rant
$devRant = new \pxgamer\devRant\Connection; $devRant->getRantById(int);
失败时返回false,或返回一个Rant对象。
通过ID获取用户
$devRant = new \pxgamer\devRant\Connection; $devRant->getUserById(int);
返回
[
"success" => true,
"profile" => [
"username" => "",
"score" => 0,
"about" => "",
"location" => "",
"created_time" => 1474613872,
"skills" => "",
"github" => "",
"website" => "",
"content" => [
"content" => [
"rants" => [],
"upvoted" => [],
"comments" => [],
"favorites" => []
[,
"counts" => []
],
"avatar" => []
]
]
搜索rant
$devRant = new \pxgamer\devRant\Connection; $devRant->getRants('string');
失败时返回false,或
[
0 => Rant object [
"id" => 0,
"text" => "string",
"num_upvotes" => 0,
"num_downvotes" => 0,
"score" => 0,
"created_time" => 0,
"attached_image" => [
"url" => "string",
"width" => 0,
"height" => 0
],
"num_comments" => 0,
"tags" => [
"string"
],
"vote_state" => 0,
"edited" => false,
"user_id" => 0,
"user_username" => "string",
"user_score" => 0,
"user_avatar" => [
"b" => "string"
]
],
1 => Rant object,
...
]
从用户名获取用户ID
$devRant = new \pxgamer\devRant\Connection; $devRant->getUserId('username');
返回
[
"success" => true,
"user_id" => 0
]
登录
$devRant = new \pxgamer\devRant\Connection; $devRant->login('username', 'password');
如果成功返回true,否则返回false
发布rant
use \pxgamer\devRant\Rant; $devRant = new \pxgamer\devRant\Connection; if ($devRant->login('username', 'password')) { $devRant->rant(new Rant($rant_content, $tags)); }
返回
[
"success" => true,
"rant_id" => 31131
]
发布评论
$devRant = new \pxgamer\devRant\Connection; if ($devRant->login('username', 'password')) { $devRant->comment($rantId, 'Comment Content'); }
返回
[
"success" => true
]
获取Collabs
$devRant = new \pxgamer\devRant\Connection; $collabs = $devRant->collabs();
返回
[
"success" => true,
"rants" => [
[0] => [
...
]
]
]
在Rants上投票
$devRant = new \pxgamer\devRant\Connection; if ($devRant->login('username', 'password')) { $voteRant = $devRant->voteRant($rantId, $vote); }
返回
[
"success" => true,
"rant" => [
[id] => ...,
...
]
]
在评论上投票
$devRant = new \pxgamer\devRant\Connection; if ($devRant->login('username', 'password')) { $voteRant = $devRant->voteComment($commentId, $vote); }
返回
[
"success" => true,
"comment" => [
[id] => ...,
...
]
]
获取您的通知
$devRant = new \pxgamer\devRant\Connection; if ($devRant->login('username', 'password')) { $notifications = $devRant->notifs(); }
返回
[
"success" => true,
"data" => {
"items" => [
...
],
"check_time" => 11111,
"username_map" => {
...
}
}
]
删除rant
请注意,这将永久从devRant删除rant。
$devRant = new \pxgamer\devRant\Connection; if ($devRant->login('username', 'password')) { $devRant->deleteRant($rantId); }
返回
[
"success" => true
]
删除评论
请注意,这将永久从devRant删除评论。
$devRant = new \pxgamer\devRant\Connection; if ($devRant->login('username', 'password')) { $devRant->deleteComment($commentId); }
返回
[
"success" => true
]
删除您的账户
请注意,这将永久从devRant删除您的账户。
$devRant = new \pxgamer\devRant\Connection; if ($devRant->login('username', 'password')) { $devRant->deleteAccount(); }
返回
[
"success" => true
]
许可证
MIT许可证(MIT)。有关更多信息,请参阅许可证文件。