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