comodojo / metaweblog
Legacy metaweblog-compliant rpc interface
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 client.
This is the development branch, please do not use it in production
This lib is intended to be used as basic client for many blog platforms (such as wordpress) or to generate testing cases for rpc server.
Installation
Install composer, then:
composer require comodojo/metaweblog
Usage example
Getting recent posts from a blog:
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 :( */ }
Supported methods
This library supports the whole metaweblog API:
-
getPost($id)
: retrieve a post from weblog -
getRecentPosts(/*optional, default 10*/ $howmany)
: get$howmany
posts from blog -
newPost($struct, /*optional, default true*/ $publish)
: create new post -
editPost($postId, $struct, /*optional, default true*/ $publish)
: edit post referenced bypostId
-
deletePost($postId, /*optional, default false*/ $appkey, /*optional, default false*/ $publish)
: delete a post referenced bypostId
-
getCategories()
: retrieve a list of categories from weblog -
newMediaObject($name, $mimetype, $content, /*optional, default false*/ $overwrite)
: upload a new media to weblog usingmetaWeblog.newMediaObject
call -
getTemplate($template_type, /*optional, default false*/ $appkey)
: get template -
setTemplate($template, $template_type, /*optional, default false*/ $appkey)
: set template -
getUsersBlogs(/*optional, default false*/ $appkey)
: returns information about all the blogs a given user is a member of
Refer to comodojo/metaweblog API for more detailed informations about methods.
RPC client and transport options
The getRpcClient()
method allows access to rpc client options (and also transport options).
For example, to get recent post from a blog listening on port 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 :( */ }
Other setters/getters
-
Get/set blog ID
// Get current blog ID $id = $mwlog->getId() // Set current blog ID $mwlog->setId(2);
-
Get/set encoding
// Get current encoding $enc = $mwlog->getEncoding() // Set current encoding $mwlog->setEncoding('utf-8');
Documentation
Contributing
Contributions are welcome and will be fully credited. Please see CONTRIBUTING for details.
License
comodojo/metaweblog
is released under the MIT License (MIT). Please see License File for more information.