http_interface.cpp
Go to the documentation of this file.
4 
5 HTTPInterface::HTTPInterface(std::string host, std::string path) : host(std::move(host)), base_path(std::move(path))
6 {
7 }
8 
9 const std::map<std::string, std::string> HTTPInterface::get(const std::vector<std::string>& json_keys,
10  const std::string& command,
11  const std::initializer_list<param_type>& list)
12 {
13  CurlResource res(host);
15  res.append_path(command);
16  res.append_query(list);
17  return get_(json_keys, res);
18 }
19 
20 const std::map<std::string, std::string> HTTPInterface::get(const std::vector<std::string>& json_keys,
21  const std::string& command, const param_map_type& params)
22 {
23  CurlResource res(host);
25  res.append_path(command);
26  res.append_query(params);
27  return get_(json_keys, res);
28 }
29 
30 const std::map<std::string, std::string> HTTPInterface::get_(const std::vector<std::string>& json_keys,
31  CurlResource& res)
32 {
33  Json::Value json_resp;
34  std::map<std::string, std::string> json_kv;
35 
36  try
37  {
38  res.get(json_resp);
39  json_kv[std::string("error_http")] = std::string("OK");
40  }
41  catch (curlpp::RuntimeError& e)
42  {
43  json_kv[std::string("error_http")] = std::string(e.what());
44  return json_kv;
45  }
46  catch (curlpp::LogicError& e)
47  {
48  json_kv[std::string("error_http")] = std::string(e.what());
49  return json_kv;
50  }
51 
52  for (std::string key : json_keys)
53  {
54  try
55  {
56  if (json_resp[key].isArray())
57  json_kv[key] = http_helpers::from_array(json_resp[key]);
58  else
59  json_kv[key] = json_resp[key].asString();
60  }
61  catch (std::exception& e)
62  {
63  json_kv[key] = "--COULD NOT RETRIEVE VALUE--";
64  }
65  }
66  return json_kv;
67 }
HTTPInterface::base_path
const std::string base_path
Definition: http_interface.h:40
HTTPInterface::get_
const std::map< std::string, std::string > get_(const std::vector< std::string > &json_keys, CurlResource &res)
Definition: http_interface.cpp:30
curl_resource.h
command
ROSLIB_DECL std::string command(const std::string &cmd)
http_helpers::from_array
std::string from_array(const Json::Value &val)
Definition: http_helpers.cpp:3
CurlResource::append_path
void append_path(const std::string &path)
Definition: curl_resource.cpp:10
CurlResource::append_query
void append_query(const std::initializer_list< param_type > &list, bool do_encoding=false)
Definition: curl_resource.cpp:15
http_helpers.h
HTTPInterface::HTTPInterface
HTTPInterface(std::string host, std::string path="")
Definition: http_interface.cpp:5
param_map_type
std::map< std::string, std::string > param_map_type
Definition: param_map_type.h:20
CurlResource::get
void get(Json::Value &json_resp)
Definition: curl_resource.cpp:35
HTTPInterface::get
const std::map< std::string, std::string > get(const std::vector< std::string > &json_keys, const std::string &command, const std::initializer_list< param_type > &list=std::initializer_list< param_type >())
Definition: http_interface.cpp:9
std
CurlResource
Definition: curl_resource.h:26
HTTPInterface::host
const std::string host
Definition: http_interface.h:39
http_interface.h
move
void move(std::vector< T > &a, std::vector< T > &b)


pf_driver
Author(s): Harsh Deshpande
autogenerated on Sun Feb 4 2024 03:32:56