1818#include " restclient-cpp/helpers.h"
1919#include " restclient-cpp/version.h"
2020
21- using namespace RestClient ;
22-
23- Connection::Connection (const std::string baseUrl) : infoStruct(), headerFields() {
21+ RestClient::Connection::Connection (const std::string baseUrl)
22+ : infoStruct(), headerFields() {
2423 this ->curlHandle = curl_easy_init ();
2524 if (!this ->curlHandle ) {
2625 throw std::runtime_error (" Couldn't initialize curl handle" );
2726 }
2827 this ->baseUrl = baseUrl;
2928}
3029
31- Connection::~Connection () {
30+ RestClient:: Connection::~Connection () {
3231 if (this ->curlHandle ) {
3332 curl_easy_cleanup (this ->curlHandle );
3433 }
@@ -43,9 +42,9 @@ Connection::~Connection() {
4342 * @param value for the header field
4443 *
4544 */
46- void Connection::AppendHeader (const std::string& key,
45+ void
46+ RestClient::Connection::AppendHeader (const std::string& key,
4747 const std::string& value) {
48-
4948 this ->headerFields [key] = value;
5049}
5150
@@ -65,9 +64,10 @@ void Connection::AppendHeader(const std::string& key,
6564 *
6665 * @return 0 on success and 1 on error
6766 */
68- Response Connection::performCurlRequest (const std::string& uri) {
69-
70- Response ret = {};
67+ RestClient::Response
68+ RestClient::Connection::performCurlRequest (const std::string& uri) {
69+ // init return type
70+ RestClient::Response ret = {};
7171
7272 std::string url = std::string (this ->baseUrl + uri);
7373 std::string headerString;
@@ -77,11 +77,13 @@ Response Connection::performCurlRequest(const std::string& uri) {
7777 /* * set query URL */
7878 curl_easy_setopt (this ->curlHandle , CURLOPT_URL, url.c_str ());
7979 /* * set callback function */
80- curl_easy_setopt (this ->curlHandle , CURLOPT_WRITEFUNCTION, Helpers::write_callback);
80+ curl_easy_setopt (this ->curlHandle , CURLOPT_WRITEFUNCTION,
81+ Helpers::write_callback);
8182 /* * set data object to pass to callback function */
8283 curl_easy_setopt (this ->curlHandle , CURLOPT_WRITEDATA, &ret);
8384 /* * set the header callback function */
84- curl_easy_setopt (this ->curlHandle , CURLOPT_HEADERFUNCTION, Helpers::header_callback);
85+ curl_easy_setopt (this ->curlHandle , CURLOPT_HEADERFUNCTION,
86+ Helpers::header_callback);
8587 /* * callback object for headers */
8688 curl_easy_setopt (this ->curlHandle , CURLOPT_HEADERDATA, &ret);
8789 /* * set http headers */
@@ -92,9 +94,11 @@ Response Connection::performCurlRequest(const std::string& uri) {
9294 headerString += it->second ;
9395 headerList = curl_slist_append (headerList, headerString.c_str ());
9496 }
95- curl_easy_setopt (this ->curlHandle , CURLOPT_HTTPHEADER, headerList);
97+ curl_easy_setopt (this ->curlHandle , CURLOPT_HTTPHEADER,
98+ headerList);
9699 /* * set user agent */
97- curl_easy_setopt (this ->curlHandle , CURLOPT_USERAGENT, this ->GetUserAgent ().c_str ());
100+ curl_easy_setopt (this ->curlHandle , CURLOPT_USERAGENT,
101+ this ->GetUserAgent ().c_str ());
98102
99103 // set timeout
100104 if (this ->timeout ) {
@@ -116,7 +120,7 @@ Response Connection::performCurlRequest(const std::string& uri) {
116120 curl_easy_getinfo (this ->curlHandle , CURLINFO_RESPONSE_CODE, &http_code);
117121 ret.code = static_cast <int >(http_code);
118122
119- // TODO: get metrics from curl handle
123+ // TODO(mrtazz) : get metrics from curl handle
120124 // free header list
121125 curl_slist_free_all (headerList);
122126 // reset curl handle
@@ -131,7 +135,8 @@ Response Connection::performCurlRequest(const std::string& uri) {
131135 *
132136 * @return response struct
133137 */
134- Response Connection::get (const std::string& url) {
138+ RestClient::Response
139+ RestClient::Connection::get (const std::string& url) {
135140 return this ->performCurlRequest (url);
136141}
137142/* *
@@ -143,8 +148,9 @@ Response Connection::get(const std::string& url) {
143148 *
144149 * @return response struct
145150 */
146- Response Connection::post (const std::string& url,
147- const std::string& data) {
151+ RestClient::Response
152+ RestClient::Connection::post (const std::string& url,
153+ const std::string& data) {
148154 /* * Now specify we want to POST data */
149155 curl_easy_setopt (this ->curlHandle , CURLOPT_POST, 1L );
150156 /* * set post fields */
@@ -162,8 +168,9 @@ Response Connection::post(const std::string& url,
162168 *
163169 * @return response struct
164170 */
165- Response Connection::put (const std::string& url,
166- const std::string& data) {
171+ RestClient::Response
172+ RestClient::Connection::put (const std::string& url,
173+ const std::string& data) {
167174 /* * initialize upload object */
168175 RestClient::Helpers::UploadObject up_obj;
169176 up_obj.data = data.c_str ();
@@ -190,7 +197,8 @@ Response Connection::put(const std::string& url,
190197 *
191198 * @return response struct
192199 */
193- Response Connection::del (const std::string& url) {
200+ RestClient::Response
201+ RestClient::Connection::del (const std::string& url) {
194202 /* * we want HTTP DELETE */
195203 const char * http_delete = " DELETE" ;
196204
0 commit comments