formatting
This commit is contained in:
parent
a0ac1a7975
commit
b7c3c4c042
@ -5,7 +5,7 @@
|
||||
|
||||
class DokuWiki
|
||||
{
|
||||
public:
|
||||
public:
|
||||
using error = std::runtime_error;
|
||||
|
||||
struct PageInfo
|
||||
@ -15,8 +15,9 @@ class DokuWiki
|
||||
std::string timestamp;
|
||||
};
|
||||
|
||||
public:
|
||||
DokuWiki(const std::string &url, const std::string &username, const std::string &password);
|
||||
public:
|
||||
DokuWiki(const std::string &url, const std::string &username,
|
||||
const std::string &password);
|
||||
~DokuWiki();
|
||||
|
||||
std::string getVersion();
|
||||
@ -31,8 +32,7 @@ class DokuWiki
|
||||
|
||||
void appendToPage(const std::string &pageName, const std::string &content);
|
||||
|
||||
private:
|
||||
private:
|
||||
class impl;
|
||||
std::unique_ptr<impl> pimpl;
|
||||
};
|
||||
|
||||
|
@ -5,7 +5,8 @@
|
||||
|
||||
#include <iostream>
|
||||
|
||||
DokuWiki::DokuWiki(const std::string &url, const std::string &username, const std::string &password)
|
||||
DokuWiki::DokuWiki(const std::string &url, const std::string &username,
|
||||
const std::string &password)
|
||||
: pimpl{std::make_unique<impl>(url, username, password)}
|
||||
{
|
||||
}
|
||||
@ -52,7 +53,8 @@ void DokuWiki::addPage(const std::string &pageName, const std::string &content)
|
||||
pimpl->addPage(pageName, content);
|
||||
}
|
||||
|
||||
void DokuWiki::appendToPage(const std::string &pageName, const std::string &content)
|
||||
void DokuWiki::appendToPage(
|
||||
const std::string &pageName, const std::string &content)
|
||||
{
|
||||
pimpl->appendToPage(pageName, content);
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
#include <iostream>
|
||||
|
||||
template<>
|
||||
template <>
|
||||
xmlrpc_c::value DokuWiki::impl::executeCommand(const std::string &command,
|
||||
const std::list<std::string> ¶ms,
|
||||
const std::map<std::string, xmlrpc_c::value> &attributes)
|
||||
@ -29,15 +29,15 @@ xmlrpc_c::value DokuWiki::impl::executeCommand(const std::string &command,
|
||||
return rpc->getResult();
|
||||
}
|
||||
|
||||
template<>
|
||||
xmlrpc_c::value_struct DokuWiki::impl::executeCommand(const std::string &command,
|
||||
const std::list<std::string> ¶ms,
|
||||
template <>
|
||||
xmlrpc_c::value_struct DokuWiki::impl::executeCommand(
|
||||
const std::string &command, const std::list<std::string> ¶ms,
|
||||
const std::map<std::string, xmlrpc_c::value> &attributes)
|
||||
{
|
||||
try
|
||||
{
|
||||
return xmlrpc_c::value_struct(executeCommand<xmlrpc_c::value>(
|
||||
command, params, attributes));
|
||||
return xmlrpc_c::value_struct(
|
||||
executeCommand<xmlrpc_c::value>(command, params, attributes));
|
||||
}
|
||||
catch (girerr::error &e)
|
||||
{
|
||||
@ -45,15 +45,15 @@ xmlrpc_c::value_struct DokuWiki::impl::executeCommand(const std::string &command
|
||||
}
|
||||
}
|
||||
|
||||
template<>
|
||||
template <>
|
||||
std::string DokuWiki::impl::executeCommand(const std::string &command,
|
||||
const std::list<std::string> ¶ms,
|
||||
const std::map<std::string, xmlrpc_c::value> &attributes)
|
||||
{
|
||||
try
|
||||
{
|
||||
return xmlrpc_c::value_string(executeCommand<xmlrpc_c::value>(
|
||||
command, params, attributes));
|
||||
return xmlrpc_c::value_string(
|
||||
executeCommand<xmlrpc_c::value>(command, params, attributes));
|
||||
}
|
||||
catch (girerr::error &e)
|
||||
{
|
||||
@ -61,15 +61,15 @@ std::string DokuWiki::impl::executeCommand(const std::string &command,
|
||||
}
|
||||
}
|
||||
|
||||
template<>
|
||||
template <>
|
||||
int DokuWiki::impl::executeCommand(const std::string &command,
|
||||
const std::list<std::string> ¶ms,
|
||||
const std::map<std::string, xmlrpc_c::value> &attributes)
|
||||
{
|
||||
try
|
||||
{
|
||||
return xmlrpc_c::value_int(executeCommand<xmlrpc_c::value>(
|
||||
command, params, attributes));
|
||||
return xmlrpc_c::value_int(
|
||||
executeCommand<xmlrpc_c::value>(command, params, attributes));
|
||||
}
|
||||
catch (girerr::error &e)
|
||||
{
|
||||
@ -77,15 +77,15 @@ int DokuWiki::impl::executeCommand(const std::string &command,
|
||||
}
|
||||
}
|
||||
|
||||
template<>
|
||||
template <>
|
||||
bool DokuWiki::impl::executeCommand(const std::string &command,
|
||||
const std::list<std::string> ¶ms,
|
||||
const std::map<std::string, xmlrpc_c::value> &attributes)
|
||||
{
|
||||
try
|
||||
{
|
||||
return xmlrpc_c::value_boolean(executeCommand<xmlrpc_c::value>(
|
||||
command, params, attributes));
|
||||
return xmlrpc_c::value_boolean(
|
||||
executeCommand<xmlrpc_c::value>(command, params, attributes));
|
||||
}
|
||||
catch (girerr::error &e)
|
||||
{
|
||||
@ -100,9 +100,10 @@ DokuWiki::impl::impl(const std::string &url, const std::string &username,
|
||||
login(username, password);
|
||||
}
|
||||
|
||||
void DokuWiki::impl::login(const std::string &username, const std::string &password)
|
||||
void DokuWiki::impl::login(
|
||||
const std::string &username, const std::string &password)
|
||||
{
|
||||
if (executeCommand<bool>("dokuwiki.login", { username, password }) == false)
|
||||
if (executeCommand<bool>("dokuwiki.login", {username, password}) == false)
|
||||
{
|
||||
throw DokuWiki::error("login failed");
|
||||
}
|
||||
@ -122,7 +123,7 @@ std::string DokuWiki::impl::getTime()
|
||||
|
||||
std::string DokuWiki::impl::getPage(const std::string &pageName)
|
||||
{
|
||||
return executeCommand<std::string>("wiki.getPage", { pageName });
|
||||
return executeCommand<std::string>("wiki.getPage", {pageName});
|
||||
}
|
||||
|
||||
std::string DokuWiki::impl::getWikiTitle()
|
||||
@ -133,16 +134,13 @@ std::string DokuWiki::impl::getWikiTitle()
|
||||
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 }));
|
||||
executeCommand<xmlrpc_c::value_struct>("wiki.getPageInfo", {pageName}));
|
||||
|
||||
std::time_t modificationTime = xmlrpc_c::value_int(values["version"]);
|
||||
|
||||
DokuWiki::PageInfo pageInfo =
|
||||
{
|
||||
xmlrpc_c::value_string(values["name"]),
|
||||
DokuWiki::PageInfo pageInfo = {xmlrpc_c::value_string(values["name"]),
|
||||
xmlrpc_c::value_string(values["author"]),
|
||||
std::asctime(std::localtime(&modificationTime))
|
||||
};
|
||||
std::asctime(std::localtime(&modificationTime))};
|
||||
|
||||
return pageInfo;
|
||||
}
|
||||
@ -160,17 +158,19 @@ bool DokuWiki::impl::pageExists(const std::string &pageName)
|
||||
}
|
||||
}
|
||||
|
||||
void DokuWiki::impl::putPage(const std::string &pageName, const std::string &content)
|
||||
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) }}))
|
||||
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)
|
||||
void DokuWiki::impl::addPage(
|
||||
const std::string &pageName, const std::string &content)
|
||||
{
|
||||
if (pageExists(pageName))
|
||||
{
|
||||
@ -180,13 +180,13 @@ void DokuWiki::impl::addPage(const std::string &pageName, const std::string &con
|
||||
putPage(pageName, content);
|
||||
}
|
||||
|
||||
void DokuWiki::impl::appendToPage(const std::string &pageName, const std::string &content)
|
||||
void DokuWiki::impl::appendToPage(
|
||||
const std::string &pageName, const std::string &content)
|
||||
{
|
||||
if (!executeCommand<bool>("dokuwiki.appendPage", { pageName, content },
|
||||
{{ "sum", xmlrpc_c::value_string("Added automatically") },
|
||||
{"minor", xmlrpc_c::value_boolean(false) }}))
|
||||
if (!executeCommand<bool>("dokuwiki.appendPage", {pageName, content},
|
||||
{{"sum", xmlrpc_c::value_string("Added automatically")},
|
||||
{"minor", xmlrpc_c::value_boolean(false)}}))
|
||||
{
|
||||
throw std::runtime_error("failed to append to page");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,12 +9,13 @@
|
||||
|
||||
class DokuWiki::impl
|
||||
{
|
||||
private:
|
||||
private:
|
||||
std::string m_url;
|
||||
xmlrpc_c::clientXmlTransport_curl m_clientTransport;
|
||||
|
||||
public:
|
||||
impl(const std::string &url, const std::string &username, const std::string &password);
|
||||
public:
|
||||
impl(const std::string &url, const std::string &username,
|
||||
const std::string &password);
|
||||
|
||||
void login(const std::string &username, const std::string &password);
|
||||
std::string getVersion();
|
||||
@ -35,4 +36,3 @@ class DokuWiki::impl
|
||||
const std::list<std::string> ¶ms = {},
|
||||
const std::map<std::string, xmlrpc_c::value> &attributes = {});
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user