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 }
const std::map< std::string, std::string > get_(const std::vector< std::string > &json_keys, CurlResource &res)
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 >())
std::string from_array(const Json::Value &val)
Definition: http_helpers.cpp:3
std::map< std::string, std::string > param_map_type
HTTPInterface(std::string host, std::string path="")
void get(Json::Value &json_resp)
const std::string base_path
void append_path(const std::string &path)
void move(std::vector< T > &a, std::vector< T > &b)
const std::string host
void append_query(const std::initializer_list< param_type > &list, bool do_encoding=false)


pf_driver
Author(s): Harsh Deshpande
autogenerated on Fri Feb 24 2023 03:59:35