FluidHubAPIClient.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 FluidHubAPIClient.hpp
34 
35  @author Jean-Christophe FABRE <jean-christophe.fabre@supagro.inra.fr>
36 */
37 
38 
39 #ifndef __OPENFLUID_UTILS_FLUIDHUBAPICLIENT_HPP__
40 #define __OPENFLUID_UTILS_FLUIDHUBAPICLIENT_HPP__
41 
42 
43 #include <set>
44 
45 #include <QString>
46 
47 #include <openfluid/dllexport.hpp>
48 #include <openfluid/ware/TypeDefs.hpp>
50 
51 
52 namespace openfluid { namespace utils {
53 
54 
56 {
57  public:
58 
60  {
61  public:
62 
63  std::string ShortDescription;
64 
65  std::string GitUrl;
66 
67  std::vector<std::string> GitBranches;
68 
69  std::map<std::string,unsigned int> IssuesCounters;
70 
71  std::set<std::string> ROUsers;
72 
73  std::set<std::string> RWUsers;
74  };
75 
76  typedef std::map<openfluid::ware::WareType,std::set<openfluid::ware::WareID_t>> WaresListByType_t;
77 
78  typedef std::map<openfluid::ware::WareID_t,WareDetailedDescription> WaresDetailsByID_t;
79 
80 
81  private:
82 
83  RESTClient m_RESTClient;
84 
85  RESTClient::SSLConfiguration m_SSLConfig;
86 
87  QString m_HubName;
88 
89  QString m_HubStatus;
90 
91  QString m_HubAPIVersion;
92 
93  std::set<QString> m_HubCapabilities;
94 
95  void reset();
96 
97  bool isCapable(const QString& Capacity) const;
98 
99  static QString wareTypeToString(openfluid::ware::WareType Type);
100 
101 
102  public:
103 
105  { }
106 
108  { }
109 
110  /**
111  Connects to the FluidHub given by the URL
112  @param[in] URL the URL of the FluidHub to connect to
113  @param[in] SSLConfig the SSL configuration for the connection (if needed)
114  @return true if the connection is OK, false otherwise
115  */
116  bool connect(const QString& URL, const RESTClient::SSLConfiguration& SSLConfig = RESTClient::SSLConfiguration());
117 
118  /**
119  Disconnects from the connected FluidHub
120  */
121  void disconnect();
122 
123  /**
124  Returns true if the client is currently connected
125  @return true if connected
126  */
127  bool isConnected() const
128  { return !(m_RESTClient.getBaseURL().isEmpty()); }
129 
130  /**
131  Returns the URL of the current FluidHub
132  @return the FluidHub URL
133  */
134  QString getHubURL() const
135  { return m_RESTClient.getBaseURL(); }
136 
137  /**
138  Returns the API version of the current FluidHub
139  @return the FluidHub API version
140  */
141  QString getHubAPIVersion() const
142  { return m_HubAPIVersion; }
143 
144  /**
145  Returns the status of the current FluidHub
146  @return the FluidHub status
147  */
148  QString getHubStatus() const
149  { return m_HubStatus; }
150 
151  /**
152  Returns the name of the current FluidHub
153  @return the FluidHub name
154  */
155  QString getHubName() const
156  { return m_HubName; }
157 
158  /**
159  Returns the capabilities list of the current FluidHub ("news","wareshub", ...)
160  @return the FluidHub capabilities
161  */
162  std::set<QString> getHubCapabilities() const
163  { return m_HubCapabilities; }
164 
165  /**
166  Returns the list of all available wares in the current FluidHub
167  @return the list of wares categorized by ware type
168  */
169  WaresListByType_t getAllAvailableWares() const;
170 
171  /**
172  Returns the detailed list of all available wares in the current FluidHub
173  @param[in] Type the type of wares to list
174  @param[in] Username Optional username used in returned git URL
175  @return the detailed list of wares of the give type
176  */
177  WaresDetailsByID_t getAvailableWaresWithDetails(openfluid::ware::WareType Type,
178  const QString& Username = "") const;
179 
180  /**
181  Returns the news as an RSS string content
182  @param[in] Lang Optional lang for news content
183  @return the RSS content
184  */
185  QString getNews(const QString& Lang = "") const;
186 
187 
188 };
189 
190 
191 } } // namespaces
192 
193 
194 #endif /* __OPENFLUID_UTILS_FLUIDHUBAPICLIENT_HPP__ */
std::set< QString > getHubCapabilities() const
Definition: FluidHubAPIClient.hpp:162
bool isConnected() const
Definition: FluidHubAPIClient.hpp:127
std::set< std::string > RWUsers
Definition: FluidHubAPIClient.hpp:73
QString getHubAPIVersion() const
Definition: FluidHubAPIClient.hpp:141
~FluidHubAPIClient()
Definition: FluidHubAPIClient.hpp:107
QString getHubURL() const
Definition: FluidHubAPIClient.hpp:134
std::string ShortDescription
Definition: FluidHubAPIClient.hpp:63
std::map< std::string, unsigned int > IssuesCounters
Definition: FluidHubAPIClient.hpp:69
std::set< std::string > ROUsers
Definition: FluidHubAPIClient.hpp:71
std::map< openfluid::ware::WareID_t, WareDetailedDescription > WaresDetailsByID_t
Definition: FluidHubAPIClient.hpp:78
QString getBaseURL() const
Definition: RESTClient.hpp:140
Definition: RESTClient.hpp:51
std::map< openfluid::ware::WareType, std::set< openfluid::ware::WareID_t > > WaresListByType_t
Definition: FluidHubAPIClient.hpp:76
Definition: FluidHubAPIClient.hpp:55
FluidHubAPIClient()
Definition: FluidHubAPIClient.hpp:104
std::vector< std::string > GitBranches
Definition: FluidHubAPIClient.hpp:67
Definition: ApplicationException.hpp:47
QString getHubStatus() const
Definition: FluidHubAPIClient.hpp:148
QString getHubName() const
Definition: FluidHubAPIClient.hpp:155
WareType
Definition: TypeDefs.hpp:62
#define OPENFLUID_API
Definition: dllexport.hpp:87
std::string GitUrl
Definition: FluidHubAPIClient.hpp:65