11 #include "apiquery.hpp"
13 using namespace Huggle;
17 if (this->ActionPart ==
"")
19 throw new Exception(
"No action provided for api request");
42 URL +=
"&format=json";
50 QString ApiQuery::ConstructParameterLessUrl()
53 if (this->ActionPart ==
"")
55 throw new Exception(
"No action provided for api request",
"void ApiQuery::ConstructParameterLessUrl()");
72 url +=
"&format=json";
94 this->
Result->Failed =
true;
103 this->ActionPart =
"";
111 void ApiQuery::Finished()
115 if (this->
reply->error())
118 this->
Result->Failed =
true;
119 this->
reply->deleteLater();
121 this->Status = StatusDone;
124 if (this->ActionPart ==
"rollback")
128 this->
reply->deleteLater();
134 this->Status = StatusDone;
140 if (this->Status == StatusProcessing)
145 this->StartTime = QDateTime::currentDateTime();
150 this->Status = StatusProcessing;
155 url = QUrl::fromEncoded(this->ConstructParameterLessUrl().toUtf8());
158 url = QUrl::fromEncoded(this->
URL.toUtf8());
160 QNetworkRequest request(url);
163 request.setHeader(QNetworkRequest::ContentTypeHeader,
"application/x-www-form-urlencoded");
167 this->
reply = Query::NetworkManager.post(request, this->
Parameters.toUtf8());
170 this->
reply = Query::NetworkManager.get(request);
176 QObject::connect(this->
reply, SIGNAL(finished()),
this, SLOT(Finished()));
177 QObject::connect(this->
reply, SIGNAL(readyRead()),
this, SLOT(ReadData()));
180 void ApiQuery::ReadData()
190 this->ActionPart =
"query";
193 this->ActionPart =
"login";
196 this->ActionPart =
"logout";
199 this->ActionPart =
"tokens";
202 this->ActionPart =
"purge";
205 this->ActionPart =
"rollback";
208 this->ActionPart =
"delete";
211 this->ActionPart =
"undelete";
214 this->ActionPart =
"block";
217 this->ActionPart =
"protect";
220 this->ActionPart =
"edit";
226 this->ActionPart = action;
231 if (this->
reply != NULL)
233 this->
reply->abort();
244 return "ApiQuery (" +
245 this->ActionPart +
")";
static QString GetProjectScriptURL()
Return a script url like http://en.wikipedia.org/w/.
QString Target
This is optional property which contains a label of target this query is for.
void Kill()
Terminate the query.
bool FormatIsCurrentlySupported()
Check if return format is supported by huggle.
static QString GetURLProtocolPrefix()
Return a prefix for url.
QString QueryTypeToString()
Returns a type of query as a string.
ApiQuery()
Creates a new instance of this class and set the defaults.
QString OverrideWiki
You can change this to url of different wiki than a project.
QueryType Type
Type of a query.
QNetworkReply * reply
Reply from qnet.
void SetAction(const Action action)
Change the action type.
void ConstructUrl()
Generate api url.
Every exception raised by huggle is defined by this class.
bool UsingPOST
Whether the query will submit parameters using POST data.
void FinishRollback()
This is only needed when you are using rollback.
static WikiSite Project
currently selected project
static void DebugLog(QString Message, unsigned int Verbosity=1)
This log is only shown if verbosity is same or larger than requested verbosity.
QString ErrorMessage
If query is in error the reason for error is stored here.
QString Parameters
Parameters for action, for example page title.
QString CustomStatus
Custom status.
QString QueryTargetToString()
Get a query target as a string.
Format RequestFormat
This is a requested format in which the result should be written in.
QString Data
Data retrieved by query.
QueryResult * Result
Result of query, see documentation of QueryResult for more.