logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

relay_operation.ex (2681B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Web.ApiSpec.Admin.RelayOperation do
  5. alias OpenApiSpex.Operation
  6. alias OpenApiSpex.Schema
  7. import Pleroma.Web.ApiSpec.Helpers
  8. def open_api_operation(action) do
  9. operation = String.to_existing_atom("#{action}_operation")
  10. apply(__MODULE__, operation, [])
  11. end
  12. def index_operation do
  13. %Operation{
  14. tags: ["Relays"],
  15. summary: "Retrieve a list of relays",
  16. operationId: "AdminAPI.RelayController.index",
  17. security: [%{"oAuth" => ["admin:read"]}],
  18. parameters: admin_api_params(),
  19. responses: %{
  20. 200 =>
  21. Operation.response("Response", "application/json", %Schema{
  22. type: :object,
  23. properties: %{
  24. relays: %Schema{
  25. type: :array,
  26. items: relay()
  27. }
  28. }
  29. })
  30. }
  31. }
  32. end
  33. def follow_operation do
  34. %Operation{
  35. tags: ["Relays"],
  36. summary: "Follow a relay",
  37. operationId: "AdminAPI.RelayController.follow",
  38. security: [%{"oAuth" => ["admin:write:follows"]}],
  39. parameters: admin_api_params(),
  40. requestBody: request_body("Parameters", relay_url()),
  41. responses: %{
  42. 200 => Operation.response("Status", "application/json", relay())
  43. }
  44. }
  45. end
  46. def unfollow_operation do
  47. %Operation{
  48. tags: ["Relays"],
  49. summary: "Unfollow a relay",
  50. operationId: "AdminAPI.RelayController.unfollow",
  51. security: [%{"oAuth" => ["admin:write:follows"]}],
  52. parameters: admin_api_params(),
  53. requestBody: request_body("Parameters", relay_unfollow()),
  54. responses: %{
  55. 200 =>
  56. Operation.response("Status", "application/json", %Schema{
  57. type: :string,
  58. example: "http://mastodon.example.org/users/admin"
  59. })
  60. }
  61. }
  62. end
  63. defp relay do
  64. %Schema{
  65. type: :object,
  66. properties: %{
  67. actor: %Schema{
  68. type: :string,
  69. example: "https://example.com/relay"
  70. },
  71. followed_back: %Schema{
  72. type: :boolean,
  73. description: "Is relay followed back by this actor?"
  74. }
  75. }
  76. }
  77. end
  78. defp relay_url do
  79. %Schema{
  80. type: :object,
  81. properties: %{
  82. relay_url: %Schema{type: :string, format: :uri}
  83. }
  84. }
  85. end
  86. defp relay_unfollow do
  87. %Schema{
  88. type: :object,
  89. properties: %{
  90. relay_url: %Schema{type: :string, format: :uri},
  91. force: %Schema{type: :boolean, default: false}
  92. }
  93. }
  94. end
  95. end