#ifndef CPR_API_H #define CPR_API_H #include #include #include #include #include #include "cpr/auth.h" #include "cpr/bearer.h" #include "cpr/cprtypes.h" #include "cpr/digest.h" #include "cpr/multipart.h" #include "cpr/ntlm.h" #include "cpr/payload.h" #include "cpr/response.h" #include "cpr/session.h" #include namespace cpr { using AsyncResponse = std::future; namespace priv { template void set_option(Session& session, T&& t) { session.SetOption(std::forward(t)); } template void set_option(Session& session, T&& t, Ts&&... ts) { set_option(session, std::forward(t)); set_option(session, std::forward(ts)...); } } // namespace priv // Get methods template Response Get(Ts&&... ts) { Session session; priv::set_option(session, std::forward(ts)...); return session.Get(); } // Get async methods template AsyncResponse GetAsync(Ts... ts) { return std::async( std::launch::async, [](Ts... ts) { return Get(std::move(ts)...); }, std::move(ts)...); } // Get callback methods template // NOLINTNEXTLINE(fuchsia-trailing-return) auto GetCallback(Then then, Ts... ts) -> std::future { return std::async( std::launch::async, [](Then then, Ts... ts) { return then(Get(std::move(ts)...)); }, std::move(then), std::move(ts)...); } // Post methods template Response Post(Ts&&... ts) { Session session; priv::set_option(session, std::forward(ts)...); return session.Post(); } // Post async methods template AsyncResponse PostAsync(Ts... ts) { return std::async( std::launch::async, [](Ts... ts) { return Post(std::move(ts)...); }, std::move(ts)...); } // Post callback methods template // NOLINTNEXTLINE(fuchsia-trailing-return) auto PostCallback(Then then, Ts... ts) -> std::future { return std::async( std::launch::async, [](Then then, Ts... ts) { return then(Post(std::move(ts)...)); }, std::move(then), std::move(ts)...); } // Put methods template Response Put(Ts&&... ts) { Session session; priv::set_option(session, std::forward(ts)...); return session.Put(); } // Put async methods template AsyncResponse PutAsync(Ts... ts) { return std::async( std::launch::async, [](Ts... ts) { return Put(std::move(ts)...); }, std::move(ts)...); } // Put callback methods template // NOLINTNEXTLINE(fuchsia-trailing-return) auto PutCallback(Then then, Ts... ts) -> std::future { return std::async( std::launch::async, [](Then then, Ts... ts) { return then(Put(std::move(ts)...)); }, std::move(then), std::move(ts)...); } // Head methods template Response Head(Ts&&... ts) { Session session; priv::set_option(session, std::forward(ts)...); return session.Head(); } // Head async methods template AsyncResponse HeadAsync(Ts... ts) { return std::async( std::launch::async, [](Ts... ts) { return Head(std::move(ts)...); }, std::move(ts)...); } // Head callback methods template // NOLINTNEXTLINE(fuchsia-trailing-return) auto HeadCallback(Then then, Ts... ts) -> std::future { return std::async( std::launch::async, [](Then then, Ts... ts) { return then(Head(std::move(ts)...)); }, std::move(then), std::move(ts)...); } // Delete methods template Response Delete(Ts&&... ts) { Session session; priv::set_option(session, std::forward(ts)...); return session.Delete(); } // Delete async methods template AsyncResponse DeleteAsync(Ts... ts) { return std::async( std::launch::async, [](Ts... ts) { return Delete(std::move(ts)...); }, std::move(ts)...); } // Delete callback methods template // NOLINTNEXTLINE(fuchsia-trailing-return) auto DeleteCallback(Then then, Ts... ts) -> std::future { return std::async( std::launch::async, [](Then then, Ts... ts) { return then(Delete(std::move(ts)...)); }, std::move(then), std::move(ts)...); } // Options methods template Response Options(Ts&&... ts) { Session session; priv::set_option(session, std::forward(ts)...); return session.Options(); } // Options async methods template AsyncResponse OptionsAsync(Ts... ts) { return std::async( std::launch::async, [](Ts... ts) { return Options(std::move(ts)...); }, std::move(ts)...); } // Options callback methods template // NOLINTNEXTLINE(fuchsia-trailing-return) auto OptionsCallback(Then then, Ts... ts) -> std::future { return std::async( std::launch::async, [](Then then, Ts... ts) { return then(Options(std::move(ts)...)); }, std::move(then), std::move(ts)...); } // Patch methods template Response Patch(Ts&&... ts) { Session session; priv::set_option(session, std::forward(ts)...); return session.Patch(); } // Patch async methods template AsyncResponse PatchAsync(Ts... ts) { return std::async( std::launch::async, [](Ts... ts) { return Patch(std::move(ts)...); }, std::move(ts)...); } // Patch callback methods template // NOLINTNEXTLINE(fuchsia-trailing-return) auto PatchCallback(Then then, Ts... ts) -> std::future { return std::async( std::launch::async, [](Then then, Ts... ts) { return then(Patch(std::move(ts)...)); }, std::move(then), std::move(ts)...); } // Download methods template Response Download(std::ofstream& file, Ts&&... ts) { Session session; priv::set_option(session, std::forward(ts)...); return session.Download(file); } // Download with user callback template Response Download(const WriteCallback& write, Ts&&... ts) { Session session; priv::set_option(session, std::forward(ts)...); return session.Download(write); } } // namespace cpr #endif