#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, Ts&&... ts) { std::initializer_list ignore = { (session.SetOption(std::forward(ts)), 0)... }; (void)ignore; } } // 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_inner) { return Get(std::move(ts_inner)...); }, 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_inner, Ts... ts_inner) { return then_inner(Get(std::move(ts_inner)...)); }, 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_inner) { return Post(std::move(ts_inner)...); }, 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_inner, Ts... ts_inner) { return then_inner(Post(std::move(ts_inner)...)); }, 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_inner) { return Put(std::move(ts_inner)...); }, 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_inner, Ts... ts_inner) { return then_inner(Put(std::move(ts_inner)...)); }, 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_inner) { return Head(std::move(ts_inner)...); }, 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_inner, Ts... ts_inner) { return then_inner(Head(std::move(ts_inner)...)); }, 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_inner) { return Delete(std::move(ts_inner)...); }, 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_inner, Ts... ts_inner) { return then_inner(Delete(std::move(ts_inner)...)); }, 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_inner) { return Options(std::move(ts_inner)...); }, 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_inner, Ts... ts_inner) { return then_inner(Options(std::move(ts_inner)...)); }, 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_inner) { return Patch(std::move(ts_inner)...); }, 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_inner, Ts... ts_inner) { return then_inner(Patch(std::move(ts_inner)...)); }, 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