summaryrefslogtreecommitdiff
path: root/lib/pleroma/web/api_spec/operations/pleroma_account_operation.ex
blob: 23201a4badfffb323227aab27fcd8f51430d15b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# Pleroma: A lightweight social networking server
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only

defmodule Pleroma.Web.ApiSpec.PleromaAccountOperation do
  alias OpenApiSpex.Operation
  alias OpenApiSpex.Schema
  alias Pleroma.Web.ApiSpec.AccountOperation
  alias Pleroma.Web.ApiSpec.Schemas.AccountRelationship
  alias Pleroma.Web.ApiSpec.Schemas.ApiError
  alias Pleroma.Web.ApiSpec.Schemas.FlakeID
  alias Pleroma.Web.ApiSpec.StatusOperation

  import Pleroma.Web.ApiSpec.Helpers

  def open_api_operation(action) do
    operation = String.to_existing_atom("#{action}_operation")
    apply(__MODULE__, operation, [])
  end

  def confirmation_resend_operation do
    %Operation{
      tags: ["Account credentials"],
      summary: "Resend confirmation email",
      description: "Expects `email` or `nickname`.",
      operationId: "PleromaAPI.AccountController.confirmation_resend",
      parameters: [
        Operation.parameter(:email, :query, :string, "Email of that needs to be verified",
          example: "cofe@cofe.io"
        ),
        Operation.parameter(
          :nickname,
          :query,
          :string,
          "Nickname of user that needs to be verified",
          example: "cofefe"
        )
      ],
      responses: %{
        204 => no_content_response()
      }
    }
  end

  def favourites_operation do
    %Operation{
      tags: ["Retrieve account information"],
      summary: "Favorites",
      description:
        "Only returns data if the user has opted into sharing it. See `hide_favorites` in [Update account credentials](#operation/AccountController.update_credentials).",
      operationId: "PleromaAPI.AccountController.favourites",
      parameters: [id_param() | pagination_params()],
      security: [%{"oAuth" => ["read:favourites"]}],
      responses: %{
        200 =>
          Operation.response(
            "Array of Statuses",
            "application/json",
            StatusOperation.array_of_statuses()
          ),
        403 => Operation.response("Forbidden", "application/json", ApiError),
        404 => Operation.response("Not Found", "application/json", ApiError)
      }
    }
  end

  def endorsements_operation do
    %Operation{
      tags: ["Retrieve account information"],
      summary: "Endorsements",
      description: "Returns endorsed accounts",
      operationId: "PleromaAPI.AccountController.endorsements",
      parameters: [with_relationships_param(), id_param()],
      responses: %{
        200 =>
          Operation.response(
            "Array of Accounts",
            "application/json",
            AccountOperation.array_of_accounts()
          ),
        404 => Operation.response("Not Found", "application/json", ApiError)
      }
    }
  end

  def subscribe_operation do
    %Operation{
      tags: ["Account actions"],
      summary: "Subscribe",
      description: "Receive notifications for all statuses posted by the account.",
      operationId: "PleromaAPI.AccountController.subscribe",
      parameters: [id_param()],
      security: [%{"oAuth" => ["follow", "write:follows"]}],
      responses: %{
        200 => Operation.response("Relationship", "application/json", AccountRelationship),
        404 => Operation.response("Not Found", "application/json", ApiError)
      }
    }
  end

  def unsubscribe_operation do
    %Operation{
      tags: ["Account actions"],
      summary: "Unsubscribe",
      description: "Stop receiving notifications for all statuses posted by the account.",
      operationId: "PleromaAPI.AccountController.unsubscribe",
      parameters: [id_param()],
      security: [%{"oAuth" => ["follow", "write:follows"]}],
      responses: %{
        200 => Operation.response("Relationship", "application/json", AccountRelationship),
        404 => Operation.response("Not Found", "application/json", ApiError)
      }
    }
  end

  def birthdays_operation do
    %Operation{
      tags: ["Retrieve account information"],
      summary: "Birthday reminders",
      description: "Birthday reminders about users you follow.",
      operationId: "PleromaAPI.AccountController.birthdays",
      parameters: [
        Operation.parameter(
          :day,
          :query,
          %Schema{type: :integer},
          "Day of users' birthdays"
        ),
        Operation.parameter(
          :month,
          :query,
          %Schema{type: :integer},
          "Month of users' birthdays"
        )
      ],
      security: [%{"oAuth" => ["read:accounts"]}],
      responses: %{
        200 =>
          Operation.response("Accounts", "application/json", AccountOperation.array_of_accounts())
      }
    }
  end

  defp id_param do
    Operation.parameter(:id, :path, FlakeID, "Account ID",
      example: "9umDrYheeY451cQnEe",
      required: true
    )
  end
end