implemented put/add-page methods
This commit is contained in:
parent
7183624f63
commit
3b05cd7c99
4 changed files with 88 additions and 14 deletions
|
@ -25,6 +25,10 @@ class DokuWiki
|
||||||
std::string getWikiTitle();
|
std::string getWikiTitle();
|
||||||
PageInfo getPageInfo(const std::string &pageName);
|
PageInfo getPageInfo(const std::string &pageName);
|
||||||
|
|
||||||
|
bool pageExists(const std::string &pageName);
|
||||||
|
void putPage(const std::string &pageName, const std::string &content);
|
||||||
|
void addPage(const std::string &pageName, const std::string &content);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
class impl;
|
class impl;
|
||||||
std::unique_ptr<impl> pimpl;
|
std::unique_ptr<impl> pimpl;
|
||||||
|
|
|
@ -36,3 +36,19 @@ DokuWiki::PageInfo DokuWiki::getPageInfo(const std::string &pageName)
|
||||||
{
|
{
|
||||||
return pimpl->getPageInfo(pageName);
|
return pimpl->getPageInfo(pageName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool DokuWiki::pageExists(const std::string &pageName)
|
||||||
|
{
|
||||||
|
return pimpl->pageExists(pageName);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DokuWiki::putPage(const std::string &pageName, const std::string &content)
|
||||||
|
{
|
||||||
|
pimpl->putPage(pageName, content);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DokuWiki::addPage(const std::string &pageName, const std::string &content)
|
||||||
|
{
|
||||||
|
pimpl->addPage(pageName, content);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,9 +2,10 @@
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
template <>
|
template<>
|
||||||
xmlrpc_c::value DokuWiki::impl::executeCommand(const std::string &command,
|
xmlrpc_c::value DokuWiki::impl::executeCommand(const std::string &command,
|
||||||
const std::list<std::string> ¶ms)
|
const std::list<std::string> ¶ms,
|
||||||
|
const std::map<std::string, xmlrpc_c::value> &attributes)
|
||||||
{
|
{
|
||||||
xmlrpc_c::client_xml client(&m_clientTransport);
|
xmlrpc_c::client_xml client(&m_clientTransport);
|
||||||
|
|
||||||
|
@ -14,6 +15,11 @@ xmlrpc_c::value DokuWiki::impl::executeCommand(const std::string &command,
|
||||||
requestParams.add(xmlrpc_c::value_string(param));
|
requestParams.add(xmlrpc_c::value_string(param));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!attributes.empty())
|
||||||
|
{
|
||||||
|
requestParams.add(xmlrpc_c::value_struct(attributes));
|
||||||
|
}
|
||||||
|
|
||||||
xmlrpc_c::rpcPtr rpc(command, requestParams);
|
xmlrpc_c::rpcPtr rpc(command, requestParams);
|
||||||
|
|
||||||
xmlrpc_c::carriageParm_curl0 carriageParm(m_url);
|
xmlrpc_c::carriageParm_curl0 carriageParm(m_url);
|
||||||
|
@ -25,11 +31,13 @@ xmlrpc_c::value DokuWiki::impl::executeCommand(const std::string &command,
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
xmlrpc_c::value_struct DokuWiki::impl::executeCommand(const std::string &command,
|
xmlrpc_c::value_struct DokuWiki::impl::executeCommand(const std::string &command,
|
||||||
const std::list<std::string> ¶ms)
|
const std::list<std::string> ¶ms,
|
||||||
|
const std::map<std::string, xmlrpc_c::value> &attributes)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return xmlrpc_c::value_struct(executeCommand<xmlrpc_c::value>(command, params));
|
return xmlrpc_c::value_struct(executeCommand<xmlrpc_c::value>(
|
||||||
|
command, params, attributes));
|
||||||
}
|
}
|
||||||
catch (girerr::error &e)
|
catch (girerr::error &e)
|
||||||
{
|
{
|
||||||
|
@ -39,11 +47,13 @@ xmlrpc_c::value_struct DokuWiki::impl::executeCommand(const std::string &command
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
std::string DokuWiki::impl::executeCommand(const std::string &command,
|
std::string DokuWiki::impl::executeCommand(const std::string &command,
|
||||||
const std::list<std::string> ¶ms)
|
const std::list<std::string> ¶ms,
|
||||||
|
const std::map<std::string, xmlrpc_c::value> &attributes)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return xmlrpc_c::value_string(executeCommand<xmlrpc_c::value>(command, params));
|
return xmlrpc_c::value_string(executeCommand<xmlrpc_c::value>(
|
||||||
|
command, params, attributes));
|
||||||
}
|
}
|
||||||
catch (girerr::error &e)
|
catch (girerr::error &e)
|
||||||
{
|
{
|
||||||
|
@ -53,11 +63,13 @@ std::string DokuWiki::impl::executeCommand(const std::string &command,
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
int DokuWiki::impl::executeCommand(const std::string &command,
|
int DokuWiki::impl::executeCommand(const std::string &command,
|
||||||
const std::list<std::string> ¶ms)
|
const std::list<std::string> ¶ms,
|
||||||
|
const std::map<std::string, xmlrpc_c::value> &attributes)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return xmlrpc_c::value_int(executeCommand<xmlrpc_c::value>(command, params));
|
return xmlrpc_c::value_int(executeCommand<xmlrpc_c::value>(
|
||||||
|
command, params, attributes));
|
||||||
}
|
}
|
||||||
catch (girerr::error &e)
|
catch (girerr::error &e)
|
||||||
{
|
{
|
||||||
|
@ -67,11 +79,13 @@ int DokuWiki::impl::executeCommand(const std::string &command,
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
bool DokuWiki::impl::executeCommand(const std::string &command,
|
bool DokuWiki::impl::executeCommand(const std::string &command,
|
||||||
const std::list<std::string> ¶ms)
|
const std::list<std::string> ¶ms,
|
||||||
|
const std::map<std::string, xmlrpc_c::value> &attributes)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return xmlrpc_c::value_boolean(executeCommand<xmlrpc_c::value>(command, params));
|
return xmlrpc_c::value_boolean(executeCommand<xmlrpc_c::value>(
|
||||||
|
command, params, attributes));
|
||||||
}
|
}
|
||||||
catch (girerr::error &e)
|
catch (girerr::error &e)
|
||||||
{
|
{
|
||||||
|
@ -79,7 +93,8 @@ bool DokuWiki::impl::executeCommand(const std::string &command,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DokuWiki::impl::impl(const std::string &url, const std::string &username, const std::string &password)
|
DokuWiki::impl::impl(const std::string &url, const std::string &username,
|
||||||
|
const std::string &password)
|
||||||
: m_url(url)
|
: m_url(url)
|
||||||
{
|
{
|
||||||
login(username, password);
|
login(username, password);
|
||||||
|
@ -117,7 +132,8 @@ std::string DokuWiki::impl::getWikiTitle()
|
||||||
|
|
||||||
DokuWiki::PageInfo DokuWiki::impl::getPageInfo(const std::string &pageName)
|
DokuWiki::PageInfo DokuWiki::impl::getPageInfo(const std::string &pageName)
|
||||||
{
|
{
|
||||||
auto values = static_cast<std::map<std::string, xmlrpc_c::value>>(executeCommand<xmlrpc_c::value_struct>("wiki.getPageInfo", { pageName }));
|
auto values = static_cast<std::map<std::string, xmlrpc_c::value>>(
|
||||||
|
executeCommand<xmlrpc_c::value_struct>("wiki.getPageInfo", { pageName }));
|
||||||
|
|
||||||
std::time_t modificationTime = xmlrpc_c::value_int(values["version"]);
|
std::time_t modificationTime = xmlrpc_c::value_int(values["version"]);
|
||||||
|
|
||||||
|
@ -131,3 +147,36 @@ DokuWiki::PageInfo DokuWiki::impl::getPageInfo(const std::string &pageName)
|
||||||
return pageInfo;
|
return pageInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool DokuWiki::impl::pageExists(const std::string &pageName)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
getPageInfo(pageName);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (std::runtime_error &)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DokuWiki::impl::putPage(const std::string &pageName, const std::string &content)
|
||||||
|
{
|
||||||
|
if (!executeCommand<bool>("wiki.putPage", { pageName, content },
|
||||||
|
{{ "sum", xmlrpc_c::value_string("Added automatically") },
|
||||||
|
{"minor", xmlrpc_c::value_boolean(false) }}))
|
||||||
|
{
|
||||||
|
throw std::runtime_error("failed to add page");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DokuWiki::impl::addPage(const std::string &pageName, const std::string &content)
|
||||||
|
{
|
||||||
|
if (pageExists(pageName))
|
||||||
|
{
|
||||||
|
throw std::runtime_error("page already exists");
|
||||||
|
}
|
||||||
|
|
||||||
|
putPage(pageName, content);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,9 +23,14 @@ class DokuWiki::impl
|
||||||
std::string getWikiTitle();
|
std::string getWikiTitle();
|
||||||
|
|
||||||
DokuWiki::PageInfo getPageInfo(const std::string &pageName);
|
DokuWiki::PageInfo getPageInfo(const std::string &pageName);
|
||||||
|
|
||||||
|
bool pageExists(const std::string &pageName);
|
||||||
|
void putPage(const std::string &pageName, const std::string &content);
|
||||||
|
void addPage(const std::string &pageName, const std::string &content);
|
||||||
|
|
||||||
template <typename ReturnType>
|
template <typename ReturnType>
|
||||||
ReturnType executeCommand(const std::string &command,
|
ReturnType executeCommand(const std::string &command,
|
||||||
const std::list<std::string> ¶ms = {});
|
const std::list<std::string> ¶ms = {},
|
||||||
|
const std::map<std::string, xmlrpc_c::value> &attributes = {});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue