AOSharedServiceLibrary
http_interface.h
1 /*
2 MIT License Block
3 
4 Copyright (c) 2016 Alex Barry
5 
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to deal
8 in the Software without restriction, including without limitation the rights
9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12 
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15 
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 THE SOFTWARE.
23 */
24 
25 #include <string>
26 
27 #ifndef AOSSL_HTTP_CLIENT_INCLUDE_HTTP_INTERFACE_H_
28 #define AOSSL_HTTP_CLIENT_INCLUDE_HTTP_INTERFACE_H_
29 
32 struct HttpRequestException: public std::exception {
34  std::string int_msg;
35  const char * int_msg_cstr;
36 
38  inline HttpRequestException(std::string msg) {
39  int_msg = "Error Sending HTTP Request: " + msg;
40  int_msg_cstr = int_msg.c_str();
41  }
42 
44  ~HttpRequestException() throw() {}
45 
47  const char * what() const throw() {
48  return int_msg_cstr;
49  }
50 };
51 
52 typedef size_t (*WriteCallback)(char *, size_t, size_t, void*);
53 
55 
59  public:
61  virtual void shutdown() = 0;
62 
63  virtual ~HttpInterface() {}
64 
65  // HTTP Methods
66 
68 
71  virtual bool put(std::string url, std::string data, int timeout) = 0;
72 
74 
77  virtual std::string get(std::string url, int timeout) = 0;
78 
80 
83  virtual bool post(std::string url, std::string data, int timeout) = 0;
84 
86 
89  virtual bool del(std::string url, int timeout) = 0;
90 };
91 
92 #endif // AOSSL_HTTP_CLIENT_INCLUDE_HTTP_INTERFACE_H_
The HTTP Requests Administrators.
Definition: http_interface.h:58
Definition: http_interface.h:32
HttpRequestException(std::string msg)
Create a HTTP Request Exception, and store the given error message.
Definition: http_interface.h:38
std::string int_msg
An error message passed on initialization.
Definition: http_interface.h:34
const char * what() const
Show the error message in readable format.
Definition: http_interface.h:47