api.h
Go to the documentation of this file.
00001 #ifndef CPR_API_H
00002 #define CPR_API_H
00003 
00004 #include <functional>
00005 #include <future>
00006 #include <string>
00007 
00008 #include "auth.h"
00009 #include "cprtypes.h"
00010 #include "defines.h"
00011 #include "digest.h"
00012 #include "multipart.h"
00013 #include "payload.h"
00014 #include "response.h"
00015 #include "session.h"
00016 
00017 namespace cpr {
00018 
00019 using AsyncResponse = std::future<Response>;
00020 
00021 namespace priv {
00022 
00023 template <typename T>
00024 void set_option(Session& session, T&& t) {
00025     session.SetOption(CPR_FWD(t));
00026 }
00027 
00028 template <typename T, typename... Ts>
00029 void set_option(Session& session, T&& t, Ts&&... ts) {
00030     set_option(session, CPR_FWD(t));
00031     set_option(session, CPR_FWD(ts)...);
00032 }
00033 
00034 } // namespace priv
00035 
00036 // Get methods
00037 template <typename... Ts>
00038 Response Get(Ts&&... ts) {
00039     Session session;
00040     priv::set_option(session, CPR_FWD(ts)...);
00041     return session.Get();
00042 }
00043 
00044 // Get async methods
00045 template <typename... Ts>
00046 AsyncResponse GetAsync(Ts... ts) {
00047     return std::async(std::launch::async, [](Ts... ts) { return Get(std::move(ts)...); },
00048                       std::move(ts)...);
00049 }
00050 
00051 // Get callback methods
00052 template <typename Then, typename... Ts>
00053 auto GetCallback(Then then, Ts... ts) -> std::future<decltype(then(Get(std::move(ts)...)))> {
00054     return std::async(std::launch::async, [](Then then, Ts... ts) {
00055         return then(Get(std::move(ts)...));
00056     }, std::move(then), std::move(ts)...);
00057 }
00058 
00059 // Post methods
00060 template <typename... Ts>
00061 Response Post(Ts&&... ts) {
00062     Session session;
00063     priv::set_option(session, CPR_FWD(ts)...);
00064     return session.Post();
00065 }
00066 
00067 // Post async methods
00068 template <typename... Ts>
00069 AsyncResponse PostAsync(Ts... ts) {
00070     return std::async(std::launch::async, [](Ts... ts) { return Post(std::move(ts)...); },
00071                       std::move(ts)...);
00072 }
00073 
00074 // Post callback methods
00075 template <typename Then, typename... Ts>
00076 auto PostCallback(Then then, Ts... ts) -> std::future<decltype(then(Post(std::move(ts)...)))> {
00077     return std::async(std::launch::async, [](Then then, Ts... ts) {
00078         return then(Post(std::move(ts)...));
00079     }, std::move(then), std::move(ts)...);
00080 }
00081 
00082 // Put methods
00083 template <typename... Ts>
00084 Response Put(Ts&&... ts) {
00085     Session session;
00086     priv::set_option(session, CPR_FWD(ts)...);
00087     return session.Put();
00088 }
00089 
00090 // Put async methods
00091 template <typename... Ts>
00092 AsyncResponse PutAsync(Ts... ts) {
00093     return std::async(std::launch::async, [](Ts... ts) { return Put(std::move(ts)...); },
00094                       std::move(ts)...);
00095 }
00096 
00097 // Put callback methods
00098 template <typename Then, typename... Ts>
00099 auto PutCallback(Then then, Ts... ts) -> std::future<decltype(then(Put(std::move(ts)...)))> {
00100     return std::async(std::launch::async, [](Then then, Ts... ts) {
00101         return then(Put(std::move(ts)...));
00102     }, std::move(then), std::move(ts)...);
00103 }
00104 
00105 // Head methods
00106 template <typename... Ts>
00107 Response Head(Ts&&... ts) {
00108     Session session;
00109     priv::set_option(session, CPR_FWD(ts)...);
00110     return session.Head();
00111 }
00112 
00113 // Head async methods
00114 template <typename... Ts>
00115 AsyncResponse HeadAsync(Ts... ts) {
00116     return std::async(std::launch::async, [](Ts... ts) { return Head(std::move(ts)...); },
00117                       std::move(ts)...);
00118 }
00119 
00120 // Head callback methods
00121 template <typename Then, typename... Ts>
00122 auto HeadCallback(Then then, Ts... ts) -> std::future<decltype(then(Head(std::move(ts)...)))> {
00123     return std::async(std::launch::async, [](Then then, Ts... ts) {
00124         return then(Head(std::move(ts)...));
00125     }, std::move(then), std::move(ts)...);
00126 }
00127 
00128 // Delete methods
00129 template <typename... Ts>
00130 Response Delete(Ts&&... ts) {
00131     Session session;
00132     priv::set_option(session, CPR_FWD(ts)...);
00133     return session.Delete();
00134 }
00135 
00136 // Delete async methods
00137 template <typename... Ts>
00138 AsyncResponse DeleteAsync(Ts... ts) {
00139     return std::async(std::launch::async, [](Ts... ts) { return Delete(std::move(ts)...); },
00140                       std::move(ts)...);
00141 }
00142 
00143 // Delete callback methods
00144 template <typename Then, typename... Ts>
00145 auto DeleteCallback(Then then, Ts... ts) -> std::future<decltype(then(Delete(std::move(ts)...)))> {
00146     return std::async(std::launch::async, [](Then then, Ts... ts) {
00147         return then(Delete(std::move(ts)...));
00148     }, std::move(then), std::move(ts)...);
00149 }
00150 
00151 // Options methods
00152 template <typename... Ts>
00153 Response Options(Ts&&... ts) {
00154     Session session;
00155     priv::set_option(session, CPR_FWD(ts)...);
00156     return session.Options();
00157 }
00158 
00159 // Options async methods
00160 template <typename... Ts>
00161 AsyncResponse OptionsAsync(Ts... ts) {
00162     return std::async(std::launch::async, [](Ts... ts) { return Options(std::move(ts)...); },
00163                       std::move(ts)...);
00164 }
00165 
00166 // Options callback methods
00167 template <typename Then, typename... Ts>
00168 auto OptionsCallback(Then then, Ts... ts)
00169         -> std::future<decltype(then(Options(std::move(ts)...)))> {
00170     return std::async(std::launch::async, [](Then then, Ts... ts) {
00171         return then(Options(std::move(ts)...));
00172     }, std::move(then), std::move(ts)...);
00173 }
00174 
00175 // Patch methods
00176 template <typename... Ts>
00177 Response Patch(Ts&&... ts) {
00178     Session session;
00179     priv::set_option(session, CPR_FWD(ts)...);
00180     return session.Patch();
00181 }
00182 
00183 // Patch async methods
00184 template <typename... Ts>
00185 AsyncResponse PatchAsync(Ts... ts) {
00186     return std::async(std::launch::async, [](Ts... ts) { return Patch(std::move(ts)...); },
00187                       std::move(ts)...);
00188 }
00189 
00190 // Patch callback methods
00191 template <typename Then, typename... Ts>
00192 auto PatchCallback(Then then, Ts... ts) -> std::future<decltype(then(Patch(std::move(ts)...)))> {
00193     return std::async(std::launch::async, [](Then then, Ts... ts) {
00194         return then(Patch(std::move(ts)...));
00195     }, std::move(then), std::move(ts)...);
00196 }
00197 
00198 } // namespace cpr
00199 
00200 #endif


rc_visard_driver
Author(s): Heiko Hirschmueller , Christian Emmerich , Felix Ruess
autogenerated on Thu Jun 6 2019 20:43:01