logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

pleroma_scrobble_operation.ex (3696B)


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