1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
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
12 import Pleroma.Web.ApiSpec.Helpers
14 def open_api_operation(action) do
15 operation = String.to_existing_atom("#{action}_operation")
16 apply(__MODULE__, operation, [])
19 def create_operation do
22 summary: "Creates a new Listen activity for an account",
23 security: [%{"oAuth" => ["write"]}],
24 operationId: "PleromaAPI.ScrobbleController.create",
26 requestBody: request_body("Parameters", create_request(), required: true),
28 200 => Operation.response("Scrobble", "application/json", scrobble())
33 def index_operation do
36 summary: "Requests a list of current and recent Listen activities for an account",
37 operationId: "PleromaAPI.ScrobbleController.index",
40 %Reference{"$ref": "#/components/parameters/accountIdOrNickname"} | pagination_params()
42 security: [%{"oAuth" => ["read"]}],
45 Operation.response("Array of Scrobble", "application/json", %Schema{
53 defp create_request do
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"},
64 allOf: [VisibilityScope],
66 description: "Scrobble visibility"
70 "title" => "Some Title",
71 "artist" => "Some Artist",
72 "album" => "Some Album",
74 "externalLink" => "https://www.last.fm/music/Some+Artist/_/Some+Title"
83 id: %Schema{type: :string},
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"},
91 description: "The length of the media playing",
94 created_at: %Schema{type: :string, format: :"date-time"}
98 "account" => Account.schema().example,
99 "title" => "Some Title",
100 "artist" => "Some Artist",
101 "album" => "Some Album",
103 "externalLink" => "https://www.last.fm/music/Some+Artist/_/Some+Title",
104 "created_at" => "2019-09-28T12:40:45.000Z"