My Project
 All Classes Functions Variables Pages
RESTClient.h
1 /*
2  * RESTClient.h
3  *
4  * Created on: Mar 12, 2017
5  * Author: kolban
6  */
7 
8 #ifndef MAIN_RESTCLIENT_H_
9 #define MAIN_RESTCLIENT_H_
10 #include "sdkconfig.h"
11 #if defined(CONFIG_LIBCURL_PRESENT)
12 
13 #include <string>
14 #include <curl/curl.h>
15 class RESTClient;
16 
20 class RESTTimings {
21 public:
22  RESTTimings(RESTClient* client);
23  void refresh();
24  std::string toString();
25 
26 private:
27  double m_namelookup = 0;
28  double m_connect = 0;
29  double m_appconnect = 0;
30  double m_pretransfer = 0;
31  double m_starttransfer = 0;
32  double m_total = 0;
33  RESTClient* client = nullptr;
34 
35 };
36 
68 class RESTClient {
69 public:
70  RESTClient();
71  virtual ~RESTClient();
72  void addHeader(std::string name, std::string value);
73  long get(); // Added return response_code 2018_4_12
74  std::string getErrorMessage();
80  std::string getResponse() {
81  return m_response;
82  }
83 
87  RESTTimings *getTimings() {
88  return m_timings;
89  }
90 
91  long post(std::string body); // Added return response_code 2018_4_12
92 
99  void setURL(std::string url) {
100  m_url = url;
101  };
102 
108  void setVerbose(bool value) {
109  m_verbose = value;
110  };
111 
112 private:
113  CURL* m_curlHandle;
114  std::string m_url;
115  char m_errbuf[CURL_ERROR_SIZE];
116  struct curl_slist* m_headers = nullptr;
117  bool m_verbose = false;
118  friend class RESTTimings;
119  RESTTimings* m_timings;
120  std::string m_response;
121  static size_t handleData(void* buffer, size_t size, size_t nmemb, void* userp);
122  void prepForCall();
123 
124 };
125 #endif /* CONFIG_LIBCURL_PRESENT */
126 #endif /* MAIN_RESTCLIENT_H_ */