web_backend.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // SPDX-FileCopyrightText: 2017 Citra Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include <memory>
  5. #include <string>
  6. namespace WebService {
  7. struct WebResult;
  8. class Client {
  9. public:
  10. Client(std::string host, std::string username, std::string token);
  11. ~Client();
  12. /**
  13. * Posts JSON to the specified path.
  14. * @param path the URL segment after the host address.
  15. * @param data String of JSON data to use for the body of the POST request.
  16. * @param allow_anonymous If true, allow anonymous unauthenticated requests.
  17. * @return the result of the request.
  18. */
  19. WebResult PostJson(const std::string& path, const std::string& data, bool allow_anonymous);
  20. /**
  21. * Gets JSON from the specified path.
  22. * @param path the URL segment after the host address.
  23. * @param allow_anonymous If true, allow anonymous unauthenticated requests.
  24. * @return the result of the request.
  25. */
  26. WebResult GetJson(const std::string& path, bool allow_anonymous);
  27. /**
  28. * Deletes JSON to the specified path.
  29. * @param path the URL segment after the host address.
  30. * @param data String of JSON data to use for the body of the DELETE request.
  31. * @param allow_anonymous If true, allow anonymous unauthenticated requests.
  32. * @return the result of the request.
  33. */
  34. WebResult DeleteJson(const std::string& path, const std::string& data, bool allow_anonymous);
  35. /**
  36. * Gets a plain string from the specified path.
  37. * @param path the URL segment after the host address.
  38. * @param allow_anonymous If true, allow anonymous unauthenticated requests.
  39. * @return the result of the request.
  40. */
  41. WebResult GetPlain(const std::string& path, bool allow_anonymous);
  42. /**
  43. * Gets an PNG image from the specified path.
  44. * @param path the URL segment after the host address.
  45. * @param allow_anonymous If true, allow anonymous unauthenticated requests.
  46. * @return the result of the request.
  47. */
  48. WebResult GetImage(const std::string& path, bool allow_anonymous);
  49. /**
  50. * Requests an external JWT for the specific audience provided.
  51. * @param audience the audience of the JWT requested.
  52. * @return the result of the request.
  53. */
  54. WebResult GetExternalJWT(const std::string& audience);
  55. private:
  56. struct Impl;
  57. std::unique_ptr<Impl> impl;
  58. };
  59. } // namespace WebService