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@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 
104  FluidHubAPIClient() = default;
105 
107  { }
108 
109  /**
110  Connects to the FluidHub given by the URL
111  @param[in] URL the URL of the FluidHub to connect to
112  @param[in] SSLConfig the SSL configuration for the connection (if needed)
113  @return true if the connection is OK, false otherwise
114  */
115  bool connect(const QString& URL, const RESTClient::SSLConfiguration& SSLConfig = RESTClient::SSLConfiguration());
116 
117  /**
118  Disconnects from the connected FluidHub
119  */
120  void disconnect();
121 
122  /**
123  Returns true if the client is currently connected
124  @return true if connected
125  */
126  bool isConnected() const
127  { return !(m_RESTClient.getBaseURL().isEmpty()); }
128 
129  /**
130  Returns the URL of the current FluidHub
131  @return the FluidHub URL
132  */
133  QString getHubURL() const
134  { return m_RESTClient.getBaseURL(); }
135 
136  /**
137  Returns the API version of the current FluidHub
138  @return the FluidHub API version
139  */
140  QString getHubAPIVersion() const
141  { return m_HubAPIVersion; }
142 
143  /**
144  Returns the status of the current FluidHub
145  @return the FluidHub status
146  */
147  QString getHubStatus() const
148  { return m_HubStatus; }
149 
150  /**
151  Returns the name of the current FluidHub
152  @return the FluidHub name
153  */
154  QString getHubName() const
155  { return m_HubName; }
156 
157  /**
158  Returns the capabilities list of the current FluidHub ("news","wareshub", ...)
159  @return the FluidHub capabilities
160  */
161  std::set<QString> getHubCapabilities() const
162  { return m_HubCapabilities; }
163 
164  /**
165  Returns the list of all available wares in the current FluidHub
166  @return the list of wares categorized by ware type
167  */
168  WaresListByType_t getAllAvailableWares() const;
169 
170  /**
171  Returns the detailed list of all available wares in the current FluidHub
172  @param[in] Type the type of wares to list
173  @param[in] Username Optional username used in returned git URL
174  @return the detailed list of wares of the give type
175  */
176  WaresDetailsByID_t getAvailableWaresWithDetails(openfluid::ware::WareType Type,
177  const QString& Username = "") const;
178 
179  /**
180  Returns the news as an RSS string content
181  @param[in] Lang Optional lang for news content
182  @return the RSS content
183  */
184  QString getNews(const QString& Lang = "") const;
185 
186 
187 };
188 
189 
190 } } // namespaces
191 
192 
193 #endif /* __OPENFLUID_UTILS_FLUIDHUBAPICLIENT_HPP__ */
std::string ShortDescription
Definition: FluidHubAPIClient.hpp:63
std::set< std::string > ROUsers
Definition: FluidHubAPIClient.hpp:71
QString getBaseURL() const
Definition: RESTClient.hpp:146
std::map< openfluid::ware::WareID_t, WareDetailedDescription > WaresDetailsByID_t
Definition: FluidHubAPIClient.hpp:78
std::string GitUrl
Definition: FluidHubAPIClient.hpp:65
Definition: FluidHubAPIClient.hpp:55
~FluidHubAPIClient()
Definition: FluidHubAPIClient.hpp:106
QString getHubName() const
Definition: FluidHubAPIClient.hpp:154
std::map< openfluid::ware::WareType, std::set< openfluid::ware::WareID_t > > WaresListByType_t
Definition: FluidHubAPIClient.hpp:76
Definition: RESTClient.hpp:58
WareType
Definition: TypeDefs.hpp:60
QString getHubAPIVersion() const
Definition: FluidHubAPIClient.hpp:140
Definition: ApplicationException.hpp:47
bool isConnected() const
Definition: FluidHubAPIClient.hpp:126
std::set< QString > getHubCapabilities() const
Definition: FluidHubAPIClient.hpp:161
QString getHubURL() const
Definition: FluidHubAPIClient.hpp:133
QString getHubStatus() const
Definition: FluidHubAPIClient.hpp:147
std::set< std::string > RWUsers
Definition: FluidHubAPIClient.hpp:73
#define OPENFLUID_API
Definition: dllexport.hpp:86
std::vector< std::string > GitBranches
Definition: FluidHubAPIClient.hpp:67
std::map< std::string, unsigned int > IssuesCounters
Definition: FluidHubAPIClient.hpp:69