Huggle  build:^490^dce1e5c
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
apiquery.hpp
1 //This program is free software: you can redistribute it and/or modify
2 //it under the terms of the GNU General Public License as published by
3 //the Free Software Foundation, either version 3 of the License, or
4 //(at your option) any later version.
5 
6 //This program is distributed in the hope that it will be useful,
7 //but WITHOUT ANY WARRANTY; without even the implied warranty of
8 //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 //GNU General Public License for more details.
10 
11 #ifndef APIQUERY_H
12 #define APIQUERY_H
13 
14 #include <QString>
15 #include <QtNetwork/QtNetwork>
16 #include <QUrl>
17 #include <QtXml/QtXml>
18 #include <QObject>
19 #include <QThread>
20 #include "query.hpp"
21 #include "revertquery.hpp"
22 #include "configuration.hpp"
23 #include "core.hpp"
24 #include "exception.hpp"
25 
26 namespace Huggle
27 {
28  class RevertQuery;
29 
30  enum Action
31  {
32  ActionQuery,
33  ActionLogin,
34  ActionLogout,
35  ActionTokens,
36  ActionPurge,
37  ActionRollback,
38  ActionDelete,
39  ActionUndelete,
40  ActionBlock,
41  ActionProtect,
42  ActionEdit
43  };
44 
45  //! Format in which the result will be returned
46  enum Format
47  {
48  XML,
49  JSON,
50  PlainText,
51  Default
52  };
53 
54  //! This class can be used to execute any kind of api query on any wiki
55  class ApiQuery : public Query
56  {
57  Q_OBJECT
58 
59  private:
60  QString ActionPart;
61  //! Reply from qnet
62  QNetworkReply *reply;
63  //! Generate api url
64  void ConstructUrl();
65  QString ConstructParameterLessUrl();
66  //! Check if return format is supported by huggle
68  //! This is only needed when you are using rollback
69  void FinishRollback();
70  private slots:
71  void ReadData();
72  void Finished();
73  public:
74  //! Creates a new instance of this class and set the defaults
75  explicit ApiQuery();
76  //! Whether the query will submit parameters using POST data
77  bool UsingPOST;
78  //! This is a requested format in which the result should be written in
80  //! This is an url of api request, you probably don't want to change it unless
81  //! you want to construct whole api request yourself
82  QString URL;
83  //! Parameters for action, for example page title
84  QString Parameters;
85  //! Run
86  void Process();
87  //! Change the action type
88  void SetAction(const Action action);
89  //! Set the raw action type, you should not use this unless you have to
90  void SetAction(const QString action);
91  //! Terminate the query
92  void Kill();
93  //! Get a query target as a string
94  QString QueryTargetToString();
95  //! Returns a type of query as a string
96  QString QueryTypeToString();
97  //! This is optional property which contains a label of target this query is for
98  QString Target;
99  //! You can change this to url of different wiki than a project
100  QString OverrideWiki;
101  };
102 }
103 
104 #endif // APIQUERY_H
Format
Format in which the result will be returned.
Definition: apiquery.hpp:46
QString Target
This is optional property which contains a label of target this query is for.
Definition: apiquery.hpp:98
void Kill()
Terminate the query.
Definition: apiquery.cpp:229
bool FormatIsCurrentlySupported()
Check if return format is supported by huggle.
Definition: apiquery.cpp:82
QString QueryTypeToString()
Returns a type of query as a string.
Definition: apiquery.cpp:242
void Process()
Run.
Definition: apiquery.cpp:138
ApiQuery()
Creates a new instance of this class and set the defaults.
Definition: apiquery.cpp:98
QString OverrideWiki
You can change this to url of different wiki than a project.
Definition: apiquery.hpp:100
QNetworkReply * reply
Reply from qnet.
Definition: apiquery.hpp:62
void SetAction(const Action action)
Change the action type.
Definition: apiquery.cpp:185
void ConstructUrl()
Generate api url.
Definition: apiquery.cpp:15
bool UsingPOST
Whether the query will submit parameters using POST data.
Definition: apiquery.hpp:77
void FinishRollback()
This is only needed when you are using rollback.
Definition: apiquery.cpp:89
QString Parameters
Parameters for action, for example page title.
Definition: apiquery.hpp:84
QString QueryTargetToString()
Get a query target as a string.
Definition: apiquery.cpp:237
This class can be used to execute any kind of api query on any wiki.
Definition: apiquery.hpp:55
Format RequestFormat
This is a requested format in which the result should be written in.
Definition: apiquery.hpp:79
Query base class for all http queries executed by huggle.
Definition: query.hpp:64