Merge branch 'openapi/pleroma-api/emojis' into 'develop'
[akkoma] / lib / pleroma / web / api_spec / operations / pleroma_scrobble_operation.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 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 requestBody: request_body("Parameters", create_request(), requried: true),
26 responses: %{
27 200 => Operation.response("Scrobble", "application/json", scrobble())
28 }
29 }
30 end
31
32 def index_operation do
33 %Operation{
34 tags: ["Scrobbles"],
35 summary: "Requests a list of current and recent Listen activities for an account",
36 operationId: "PleromaAPI.ScrobbleController.index",
37 parameters: [
38 %Reference{"$ref": "#/components/parameters/accountIdOrNickname"} | pagination_params()
39 ],
40 security: [%{"oAuth" => ["read"]}],
41 responses: %{
42 200 =>
43 Operation.response("Array of Scrobble", "application/json", %Schema{
44 type: :array,
45 items: scrobble()
46 })
47 }
48 }
49 end
50
51 defp create_request do
52 %Schema{
53 type: :object,
54 required: [:title],
55 properties: %{
56 title: %Schema{type: :string, description: "The title of the media playing"},
57 album: %Schema{type: :string, description: "The album of the media playing"},
58 artist: %Schema{type: :string, description: "The artist of the media playing"},
59 length: %Schema{type: :integer, description: "The length of the media playing"},
60 visibility: %Schema{
61 allOf: [VisibilityScope],
62 default: "public",
63 description: "Scrobble visibility"
64 }
65 },
66 example: %{
67 "title" => "Some Title",
68 "artist" => "Some Artist",
69 "album" => "Some Album",
70 "length" => 180_000
71 }
72 }
73 end
74
75 defp scrobble do
76 %Schema{
77 type: :object,
78 properties: %{
79 id: %Schema{type: :string},
80 account: Account,
81 title: %Schema{type: :string, description: "The title of the media playing"},
82 album: %Schema{type: :string, description: "The album of the media playing"},
83 artist: %Schema{type: :string, description: "The artist of the media playing"},
84 length: %Schema{
85 type: :integer,
86 description: "The length of the media playing",
87 nullable: true
88 },
89 created_at: %Schema{type: :string, format: :"date-time"}
90 },
91 example: %{
92 "id" => "1234",
93 "account" => Account.schema().example,
94 "title" => "Some Title",
95 "artist" => "Some Artist",
96 "album" => "Some Album",
97 "length" => 180_000,
98 "created_at" => "2019-09-28T12:40:45.000Z"
99 }
100 }
101 end
102 end