comparison PalanthirCppClient/HttpClient.h @ 45:33d67e1ab173

r
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 05 Sep 2012 13:24:59 +0200
parents PalantirCppClient/HttpClient.h@9be852ad33d2
children a15e90e5d6fc
comparison
equal deleted inserted replaced
43:9be852ad33d2 45:33d67e1ab173
1 /**
2 * Palantir - A Lightweight, RESTful DICOM Store
3 * Copyright (C) 2012 Medical Physics Department, CHU of Liege,
4 * Belgium
5 *
6 * Permission is hereby granted, free of charge, to any person
7 * obtaining a copy of this software and associated documentation
8 * files (the "Software"), to deal in the Software without
9 * restriction, including without limitation the rights to use, copy,
10 * modify, merge, publish, distribute, sublicense, and/or sell copies
11 * of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be
15 * included in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
21 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
22 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 * SOFTWARE.
25 **/
26
27
28 #pragma once
29
30 #include "HttpEnumerations.h"
31 #include "HttpException.h"
32
33 #include <string>
34 #include <boost/shared_ptr.hpp>
35 #include <json/json.h>
36
37 namespace Palantir
38 {
39 class HttpClient
40 {
41 private:
42 struct PImpl;
43 boost::shared_ptr<PImpl> pimpl_;
44
45 std::string url_;
46 Palantir_HttpMethod method_;
47 Palantir_HttpStatus lastStatus_;
48 std::string postData_;
49 bool isVerbose_;
50
51 public:
52 HttpClient();
53
54 ~HttpClient();
55
56 void SetUrl(const char* url)
57 {
58 url_ = std::string(url);
59 }
60
61 void SetUrl(const std::string& url)
62 {
63 url_ = url;
64 }
65
66 const std::string& GetUrl() const
67 {
68 return url_;
69 }
70
71 void SetMethod(Palantir_HttpMethod method)
72 {
73 method_ = method;
74 }
75
76 Palantir_HttpMethod GetMethod() const
77 {
78 return method_;
79 }
80
81 std::string& AccessPostData()
82 {
83 return postData_;
84 }
85
86 const std::string& AccessPostData() const
87 {
88 return postData_;
89 }
90
91 void SetVerbose(bool isVerbose);
92
93 bool IsVerbose() const
94 {
95 return isVerbose_;
96 }
97
98 bool Apply(std::string& answer);
99
100 bool Apply(Json::Value& answer);
101
102 Palantir_HttpStatus GetLastStatus() const
103 {
104 return lastStatus_;
105 }
106
107 const char* GetLastStatusText() const
108 {
109 return HttpException::GetDescription(lastStatus_);
110 }
111
112 };
113 }