comodojo / metaweblog
遗留的metaweblog兼容rpc接口
Requires
- php: >=5.3.0
- comodojo/exceptions: @stable
- comodojo/rpcclient: 1.1.*
Requires (Dev)
- phpunit/phpunit: ~4.0
- scrutinizer/ocular: ~1.1
- wp-cli/wp-cli: ~0.19
README
A metaweblog rpc客户端。
这是开发分支,请勿在生产环境中使用
此库旨在用作许多博客平台(如wordpress)的基本客户端,或用于为rpc服务器生成测试用例。
安装
安装 composer,然后
composer require comodojo/metaweblog
使用示例
从博客获取最近的文章
try { // Create a new metaweblog instance providing address, username and password $mwlog = new \Comodojo\MetaWeblog\MetaWeblog( "www.example.org", "john", "doe" ); // Get last 10 posts $posts = $mwlog->getRecentPosts(10); } catch (\Exception $e) { /* something did not work :( */ }
支持的方法
此库支持整个metaweblog API
-
getPost($id)
:从weblog检索文章 -
getRecentPosts(/*可选,默认10*/ $howmany)
:从博客获取$howmany
篇文章 -
newPost($struct, /*可选,默认true*/ $publish)
:创建新文章 -
editPost($postId, $struct, /*可选,默认true*/ $publish)
:编辑通过postId
引用的文章 -
deletePost($postId, /*可选,默认false*/ $appkey, /*可选,默认false*/ $publish)
:删除通过postId
引用的文章 -
getCategories()
:从weblog检索类别列表 -
newMediaObject($name, $mimetype, $content, /*可选,默认false*/ $overwrite)
:使用metaWeblog.newMediaObject
调用将新媒体上传到weblog -
getTemplate($template_type, /*可选,默认false*/ $appkey)
:获取模板 -
setTemplate($template, $template_type, /*可选,默认false*/ $appkey)
:设置模板 -
getUsersBlogs(/*可选,默认false*/ $appkey)
:返回有关用户是成员的所有博客的信息
有关方法更详细的信息,请参阅 comodojo/metaweblog API。
RPC客户端和传输选项
getRpcClient()
方法允许访问rpc客户端选项(以及传输选项)。
例如,要从监听端口8080的博客获取最近的文章
try { // Create a new metaweblog instance providing address, username and password $mwlog = new \Comodojo\MetaWeblog\MetaWeblog( "www.example.org", "john", "doe" ); $mwlog->getRpcClient()->getTransport()->setPort(8080); // Get last 10 posts $posts = $mwlog->getRecentPosts(10); } catch (\Exception $e) { /* something did not work :( */ }
其他设置/获取器
-
获取/设置博客ID
// Get current blog ID $id = $mwlog->getId() // Set current blog ID $mwlog->setId(2);
-
获取/设置编码
// Get current encoding $enc = $mwlog->getEncoding() // Set current encoding $mwlog->setEncoding('utf-8');
文档
贡献
欢迎贡献,并将得到充分认可。有关详细信息,请参阅CONTRIBUTING。
许可证
comodojo/metaweblog
在MIT许可证(MIT)下发布。有关更多信息,请参阅许可证文件。