RestApi.hh
Go to the documentation of this file.
1 /*
2  * copyright (C) 2015 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 
18 #ifndef _GAZEBO_REST_API_HH_
19 #define _GAZEBO_REST_API_HH_
20 
21 #include <string>
22 #include <list>
23 #include <gazebo/common/Console.hh>
24 
25 #include "RestException.hh"
26 
27 namespace gazebo
28 {
31  class RestApi
32  {
34  public: RestApi();
35 
37  public: virtual ~RestApi();
38 
45  public: std::string Login(const std::string &_url,
46  const std::string &_route,
47  const std::string &_user,
48  const std::string &_pass);
49 
53  public: void Logout();
54 
58  public: void PostJsonData(const char *_route, const char *_json);
59 
62  public: std::string GetUser() const;
63 
70  private: std::string Request(const std::string &_requestUrl,
71  const std::string &_postStr);
72 
74  private: void SendUnpostedPosts();
75 
77  private: std::string url;
78 
80  private: std::string user;
81 
83  private: std::string pass;
84 
86  private: std::string loginRoute;
87 
89  private: bool isLoggedIn;
90 
92  private: struct Post
93  {
94  std::string route;
95  std::string json;
96  };
97 
99  private: std::list<Post> posts;
100 
102  private: boost::mutex postsMutex;
103  };
104 }
105 
106 #endif
RestApi()
Constructor.
virtual ~RestApi()
Destructor.
REST interface.
Definition: RestApi.hh:31
std::string GetUser() const
Returns the username.
void Logout()
Stops sending messages to the REST service.
std::string Login(const std::string &_url, const std::string &_route, const std::string &_user, const std::string &_pass)
Connects to the REST service.
void PostJsonData(const char *_route, const char *_json)
Notify the service with a http POST.