total rebase
[anni] / lib / pleroma / web / api_spec / operations / pleroma_scrobble_operation.ex
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
5 defmodule Pleroma.Web.ApiSpec.PleromaScrobbleOperation do
6   alias OpenApiSpex.Operation
7   alias OpenApiSpex.Reference
8   alias OpenApiSpex.Schema
9   alias Pleroma.Web.ApiSpec.Schemas.Account
10   alias Pleroma.Web.ApiSpec.Schemas.VisibilityScope
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 create_operation do
20     %Operation{
21       tags: ["Scrobbles"],
22       summary: "Creates a new Listen activity for an account",
23       security: [%{"oAuth" => ["write"]}],
24       operationId: "PleromaAPI.ScrobbleController.create",
25       deprecated: true,
26       requestBody: request_body("Parameters", create_request(), required: true),
27       responses: %{
28         200 => Operation.response("Scrobble", "application/json", scrobble())
29       }
30     }
31   end
32
33   def index_operation do
34     %Operation{
35       tags: ["Scrobbles"],
36       summary: "Requests a list of current and recent Listen activities for an account",
37       operationId: "PleromaAPI.ScrobbleController.index",
38       deprecated: true,
39       parameters: [
40         %Reference{"$ref": "#/components/parameters/accountIdOrNickname"} | pagination_params()
41       ],
42       security: [%{"oAuth" => ["read"]}],
43       responses: %{
44         200 =>
45           Operation.response("Array of Scrobble", "application/json", %Schema{
46             type: :array,
47             items: scrobble()
48           })
49       }
50     }
51   end
52
53   defp create_request do
54     %Schema{
55       type: :object,
56       required: [:title],
57       properties: %{
58         title: %Schema{type: :string, description: "The title of the media playing"},
59         album: %Schema{type: :string, description: "The album of the media playing"},
60         artist: %Schema{type: :string, description: "The artist of the media playing"},
61         length: %Schema{type: :integer, description: "The length of the media playing"},
62         externalLink: %Schema{type: :string, description: "A URL referencing the media playing"},
63         visibility: %Schema{
64           allOf: [VisibilityScope],
65           default: "public",
66           description: "Scrobble visibility"
67         }
68       },
69       example: %{
70         "title" => "Some Title",
71         "artist" => "Some Artist",
72         "album" => "Some Album",
73         "length" => 180_000,
74         "externalLink" => "https://www.last.fm/music/Some+Artist/_/Some+Title"
75       }
76     }
77   end
78
79   defp scrobble do
80     %Schema{
81       type: :object,
82       properties: %{
83         id: %Schema{type: :string},
84         account: Account,
85         title: %Schema{type: :string, description: "The title of the media playing"},
86         album: %Schema{type: :string, description: "The album of the media playing"},
87         artist: %Schema{type: :string, description: "The artist of the media playing"},
88         externalLink: %Schema{type: :string, description: "A URL referencing the media playing"},
89         length: %Schema{
90           type: :integer,
91           description: "The length of the media playing",
92           nullable: true
93         },
94         created_at: %Schema{type: :string, format: :"date-time"}
95       },
96       example: %{
97         "id" => "1234",
98         "account" => Account.schema().example,
99         "title" => "Some Title",
100         "artist" => "Some Artist",
101         "album" => "Some Album",
102         "length" => 180_000,
103         "externalLink" => "https://www.last.fm/music/Some+Artist/_/Some+Title",
104         "created_at" => "2019-09-28T12:40:45.000Z"
105       }
106     }
107   end
108 end