Documentation for OpenFLUID 2.2.0
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  @author Armel THONI <armel.thoni@inrae.fr>
37 */
38 
39 
40 #ifndef __OPENFLUID_UTILS_FLUIDHUBAPICLIENT_HPP__
41 #define __OPENFLUID_UTILS_FLUIDHUBAPICLIENT_HPP__
42 
43 
44 #include <string>
45 #include <map>
46 #include <set>
47 
48 #include <openfluid/dllexport.hpp>
49 #include <openfluid/ware/TypeDefs.hpp>
52 
53 
54 namespace openfluid { namespace utils {
55 
56 
58 {
59  public:
60 
62  {
63  public:
64 
65  std::string ShortDescription;
66 
67  std::string GitUrl;
68 
69  std::vector<std::string> GitBranches;
70 
71  std::map<std::string,unsigned int> IssuesCounters;
72 
73  std::set<std::string> ROUsers;
74 
75  std::set<std::string> RWUsers;
76  };
77 
78  typedef std::map<openfluid::ware::WareType,std::set<openfluid::ware::WareID_t>> WaresListByType_t;
79 
80  typedef std::map<openfluid::ware::WareID_t,WareDetailedDescription> WaresDetailsByID_t;
81 
82 
83  private:
84 
85  HTTPClient m_RESTClient;
86 
87  std::string m_HubName;
88 
89  std::string m_HubStatus;
90 
91  std::string m_HubAPIVersion;
92 
93  bool m_IsV0ofAPI = true;
94 
95  std::string m_WareCapabilityName = "wareshub";
96 
97  std::set<std::string> m_HubCapabilities;
98 
99  void reset();
100 
101  bool isCapable(const std::string& Capacity) const;
102 
103  static std::string wareTypeToString(openfluid::ware::WareType Type);
104 
105  WaresDetailsByID_t getAvailableElementsWithDetails(std::string& Path, const std::string& Username) const;
106 
107 
108  public:
109 
111 
112  /**
113  Connects to the FluidHub given by the URL
114  @param[in] URL the URL of the FluidHub to connect to
115  @param[in] VerifyCertificate enables/disables SSL certicate verification (default is true)
116  @param[in] AllowedRedirections maximum redirections allowed, -1 for no redirection (default is 2)
117  @return true if the connection is OK, false otherwise
118  */
119  bool connect(const std::string& URL, bool VerifyCertificate = true, bool AllowedRedirections = 2);
120 
121  /**
122  Disconnects from the connected FluidHub
123  */
124  void disconnect();
125 
126  /**
127  Unsets the authentication informations
128  */
129  void logout();
130 
131  /**
132  Returns true if the client is currently connected
133  @return true if connected
134  */
135  bool isConnected() const
136  {
137  return !(m_RESTClient.getBaseURL().empty());
138  }
139 
140  /**
141  Returns true if the serveur uses the deprecated API (old wareshub)
142  @return true if connected
143  */
144  bool isV0ofAPI() const
145  {
146  return m_IsV0ofAPI;
147  }
148 
149  /**
150  Returns the URL of the current FluidHub
151  @return the FluidHub URL
152  */
153  std::string getHubURL() const
154  {
155  return m_RESTClient.getBaseURL();
156  }
157 
158  /**
159  Returns the API version of the current FluidHub
160  @return the FluidHub API version
161  */
162  std::string getHubAPIVersion() const
163  {
164  return m_HubAPIVersion;
165  }
166 
167  /**
168  Returns the status of the current FluidHub
169  @return the FluidHub status
170  */
171  std::string getHubStatus() const
172  {
173  return m_HubStatus;
174  }
175 
176  /**
177  Returns the name of the current FluidHub
178  @return the FluidHub name
179  */
180  std::string getHubName() const
181  {
182  return m_HubName;
183  }
184 
185  /**
186  Returns the capabilities list of the current FluidHub ("news","wareshub", ...)
187  @return the FluidHub capabilities
188  */
189  std::set<std::string> getHubCapabilities() const
190  {
191  return m_HubCapabilities;
192  }
193 
194  /**
195  Returns the corresponding user unixname if connected and not deprecated API
196  @return the connected user unixname
197  */
198  std::string getUserUnixname(const std::string& Email, const std::string& Password);
199 
200  /**
201  Returns true if login credentials are valid
202  @return True if login credentials are valid, false otherwise
203  */
204  bool areCredentialsValid(const std::string& Unixname, const std::string& Password);
205 
206  /**
207  Returns the list of all available wares in the current FluidHub
208  @return the list of wares categorized by ware type
209  */
211 
212  /**
213  Returns the detailed list of all available wares in the current FluidHub
214  @param[in] Type the type of wares to list
215  @param[in] Username Optional username used in returned git URL
216  @return the detailed list of wares of the give type
217  */
219  const std::string& Username = "") const;
220 
221  /**
222  Returns the detailed list of all available fragments in the current FluidHub
223  @param[in] Username Optional username used in returned git URL
224  @return the detailed list of fragments
225  */
226  WaresDetailsByID_t getAvailableFragmentsWithDetails(const std::string& Username = "") const;
227 
228  /**
229  Returns the news as an RSS string content
230  @param[in] Lang Optional lang for news content
231  @return the RSS content
232  */
233  std::string getNews(const std::string& Lang = "") const;
234 
235 
236 };
237 
238 
239 } } // namespaces
240 
241 
242 #endif /* __OPENFLUID_UTILS_FLUIDHUBAPICLIENT_HPP__ */
#define CPPCLASS_DEFAULT_FIVE(classname)
Definition: CppLangHelpers.hpp:57
std::map< std::string, unsigned int > IssuesCounters
Definition: FluidHubAPIClient.hpp:71
std::string GitUrl
Definition: FluidHubAPIClient.hpp:67
std::set< std::string > ROUsers
Definition: FluidHubAPIClient.hpp:73
std::string ShortDescription
Definition: FluidHubAPIClient.hpp:65
std::vector< std::string > GitBranches
Definition: FluidHubAPIClient.hpp:69
std::set< std::string > RWUsers
Definition: FluidHubAPIClient.hpp:75
Definition: FluidHubAPIClient.hpp:58
WaresDetailsByID_t getAvailableFragmentsWithDetails(const std::string &Username="") const
std::string getHubName() const
Definition: FluidHubAPIClient.hpp:180
WaresListByType_t getAllAvailableWares() const
WaresDetailsByID_t getAvailableWaresWithDetails(openfluid::ware::WareType Type, const std::string &Username="") const
std::map< openfluid::ware::WareID_t, WareDetailedDescription > WaresDetailsByID_t
Definition: FluidHubAPIClient.hpp:80
std::string getHubAPIVersion() const
Definition: FluidHubAPIClient.hpp:162
std::string getUserUnixname(const std::string &Email, const std::string &Password)
std::string getHubURL() const
Definition: FluidHubAPIClient.hpp:153
std::string getHubStatus() const
Definition: FluidHubAPIClient.hpp:171
std::map< openfluid::ware::WareType, std::set< openfluid::ware::WareID_t > > WaresListByType_t
Definition: FluidHubAPIClient.hpp:78
bool areCredentialsValid(const std::string &Unixname, const std::string &Password)
bool isV0ofAPI() const
Definition: FluidHubAPIClient.hpp:144
std::string getNews(const std::string &Lang="") const
std::set< std::string > getHubCapabilities() const
Definition: FluidHubAPIClient.hpp:189
Definition: HTTPClient.hpp:56
std::string getBaseURL() const
Definition: HTTPClient.hpp:162
#define OPENFLUID_API
Definition: dllexport.hpp:86
FilesystemPath Path
Definition: FilesystemPath.hpp:308
WareType
Definition: TypeDefs.hpp:61
Definition: ApplicationException.hpp:47