RESTClient.hpp
Go to the documentation of this file.
1 /*
2 
3  This file is part of OpenFLUID software
4  Copyright(c) 2007, INRA - Montpellier SupAgro
5 
6 
7  == GNU General Public License Usage ==
8 
9  OpenFLUID is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  (at your option) any later version.
13 
14  OpenFLUID is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with OpenFLUID. If not, see <http://www.gnu.org/licenses/>.
21 
22 
23  == Other Usage ==
24 
25  Other Usage means a use of OpenFLUID that is inconsistent with the GPL
26  license, and requires a written agreement between You and INRA.
27  Licensees for Other Usage of OpenFLUID may use this file in accordance
28  with the terms contained in the written agreement between You and INRA.
29 
30 */
31 
32 /**
33  @file RESTClient.hpp
34 
35  @author Jean-Christophe FABRE <jean-christophe.fabre@supagro.inra.fr>
36 */
37 
38 
39 #ifndef __OPENFLUID_UTILS_RESTCLIENT_HPP__
40 #define __OPENFLUID_UTILS_RESTCLIENT_HPP__
41 
42 
43 #include <QSslSocket>
44 
45 #include <openfluid/dllexport.hpp>
46 
47 
48 namespace openfluid { namespace utils {
49 
50 
52 {
53 
54  public:
55 
56  class Reply
57  {
58  private:
59 
60  int m_StatusCode = -1;
61 
62  unsigned int m_NetworkErrorCode = 0;
63 
64  QString m_NetworkErrorString;
65 
66  QString m_Content;
67 
68 
69  public:
70 
72  { }
73 
74  Reply(int StatusCode, unsigned int NetworkErrorCode, const QString& NetworkErrorString, const QString& Content):
75  m_StatusCode(StatusCode),
76  m_NetworkErrorCode(NetworkErrorCode),
77  m_NetworkErrorString(NetworkErrorString),
78  m_Content(Content)
79  { }
80 
81  int getStatusCode() const
82  { return m_StatusCode; }
83 
84  int getNetworkErrorCode() const
85  { return m_NetworkErrorCode; }
86 
87  QString getNetworkErrorString() const
88  { return m_NetworkErrorString; }
89 
90  QString getContent() const
91  { return m_Content; }
92 
93  bool isOK() const
94  { return m_NetworkErrorCode == 0 && m_StatusCode >= 200 && m_StatusCode < 300; }
95 
96  void clear()
97  {
98  m_StatusCode = -1;
99  m_Content.clear();
100  }
101  };
102 
104  {
105  private:
106 
107  QSslSocket::PeerVerifyMode m_CertificateVerifyMode;
108 
109  public:
110 
111  SSLConfiguration() : m_CertificateVerifyMode(QSslSocket::AutoVerifyPeer)
112  { }
113 
114  QSslSocket::PeerVerifyMode getCertificateVerifyMode() const
115  { return m_CertificateVerifyMode; }
116 
117  void setCertificateVerifyMode(QSslSocket::PeerVerifyMode Mode)
118  { m_CertificateVerifyMode = Mode; }
119  };
120 
121 
122  private:
123 
124  QString m_BaseURL;
125 
126  SSLConfiguration m_SSLConfiguration;
127 
128  Reply performRequest(const QString& Path, const QString& Method, const QString& Data = "") const;
129 
130 
131  public:
132 
133  RESTClient();
134 
136  { }
137 
138  void setBaseURL(const QString& URL);
139 
140  QString getBaseURL() const
141  { return m_BaseURL; }
142 
144  { m_SSLConfiguration = Config; }
145 
147  { return m_SSLConfiguration; }
148 
149  Reply getResource(const QString& Path) const;
150 
151  Reply postResource(const QString& Path, const QString& Data) const;
152 
153  Reply putResource(const QString& Path, const QString& Data) const;
154 
155  Reply patchResource(const QString& Path, const QString& Data) const;
156 
157  Reply deleteResource(const QString& Path, const QString& Data) const;
158 
159 };
160 
161 
162 } } // namespaces
163 
164 
165 #endif /* __OPENFLUID_UTILS_RESTCLIENT_HPP__ */
int getStatusCode() const
Definition: RESTClient.hpp:81
void clear()
Definition: RESTClient.hpp:96
QString getBaseURL() const
Definition: RESTClient.hpp:140
Definition: RESTClient.hpp:51
Reply()
Definition: RESTClient.hpp:71
QString getNetworkErrorString() const
Definition: RESTClient.hpp:87
SSLConfiguration getSSLConfiguration() const
Definition: RESTClient.hpp:146
void setCertificateVerifyMode(QSslSocket::PeerVerifyMode Mode)
Definition: RESTClient.hpp:117
QString getContent() const
Definition: RESTClient.hpp:90
bool isOK() const
Definition: RESTClient.hpp:93
SSLConfiguration()
Definition: RESTClient.hpp:111
Definition: RESTClient.hpp:56
int getNetworkErrorCode() const
Definition: RESTClient.hpp:84
Definition: ApplicationException.hpp:47
QSslSocket::PeerVerifyMode getCertificateVerifyMode() const
Definition: RESTClient.hpp:114
#define OPENFLUID_API
Definition: dllexport.hpp:87
~RESTClient()
Definition: RESTClient.hpp:135
void setSSLConfiguration(const SSLConfiguration &Config)
Definition: RESTClient.hpp:143
Reply(int StatusCode, unsigned int NetworkErrorCode, const QString &NetworkErrorString, const QString &Content)
Definition: RESTClient.hpp:74