Merge branch 'chores/bump-copyright' into 'develop'
[akkoma] / lib / pleroma / web / api_spec / operations / pleroma_account_operation.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.ApiSpec.PleromaAccountOperation do
6 alias OpenApiSpex.Operation
7 alias Pleroma.Web.ApiSpec.Schemas.AccountRelationship
8 alias Pleroma.Web.ApiSpec.Schemas.ApiError
9 alias Pleroma.Web.ApiSpec.Schemas.FlakeID
10 alias Pleroma.Web.ApiSpec.StatusOperation
11
12 import Pleroma.Web.ApiSpec.Helpers
13
14 def open_api_operation(action) do
15 operation = String.to_existing_atom("#{action}_operation")
16 apply(__MODULE__, operation, [])
17 end
18
19 def confirmation_resend_operation do
20 %Operation{
21 tags: ["Accounts"],
22 summary: "Resend confirmation email. Expects `email` or `nickname`",
23 operationId: "PleromaAPI.AccountController.confirmation_resend",
24 parameters: [
25 Operation.parameter(:email, :query, :string, "Email of that needs to be verified",
26 example: "cofe@cofe.io"
27 ),
28 Operation.parameter(
29 :nickname,
30 :query,
31 :string,
32 "Nickname of user that needs to be verified",
33 example: "cofefe"
34 )
35 ],
36 responses: %{
37 204 => no_content_response()
38 }
39 }
40 end
41
42 def favourites_operation do
43 %Operation{
44 tags: ["Accounts"],
45 summary: "Returns favorites timeline of any user",
46 operationId: "PleromaAPI.AccountController.favourites",
47 parameters: [id_param() | pagination_params()],
48 security: [%{"oAuth" => ["read:favourites"]}],
49 responses: %{
50 200 =>
51 Operation.response(
52 "Array of Statuses",
53 "application/json",
54 StatusOperation.array_of_statuses()
55 ),
56 403 => Operation.response("Forbidden", "application/json", ApiError),
57 404 => Operation.response("Not Found", "application/json", ApiError)
58 }
59 }
60 end
61
62 def subscribe_operation do
63 %Operation{
64 tags: ["Accounts"],
65 summary: "Subscribe to receive notifications for all statuses posted by a user",
66 operationId: "PleromaAPI.AccountController.subscribe",
67 parameters: [id_param()],
68 security: [%{"oAuth" => ["follow", "write:follows"]}],
69 responses: %{
70 200 => Operation.response("Relationship", "application/json", AccountRelationship),
71 404 => Operation.response("Not Found", "application/json", ApiError)
72 }
73 }
74 end
75
76 def unsubscribe_operation do
77 %Operation{
78 tags: ["Accounts"],
79 summary: "Unsubscribe to stop receiving notifications from user statuses",
80 operationId: "PleromaAPI.AccountController.unsubscribe",
81 parameters: [id_param()],
82 security: [%{"oAuth" => ["follow", "write:follows"]}],
83 responses: %{
84 200 => Operation.response("Relationship", "application/json", AccountRelationship),
85 404 => Operation.response("Not Found", "application/json", ApiError)
86 }
87 }
88 end
89
90 defp id_param do
91 Operation.parameter(:id, :path, FlakeID, "Account ID",
92 example: "9umDrYheeY451cQnEe",
93 required: true
94 )
95 end
96 end