web_backend.h 2.4 KB

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