{
    "openapi": "3.1.0",
    "info": {
        "title": "Rova Publishing API",
        "version": "1.0.0",
        "description": "Post to Rova for a member who allowed your app. OAuth 2.1 authorization code + PKCE (S256). Every post goes through the same checks as the Rova composer and shows \"via <your app>\"."
    },
    "servers": [
        {
            "url": "https://rovasocial.com/api/public/v1"
        }
    ],
    "security": [
        {
            "oauth": []
        }
    ],
    "components": {
        "securitySchemes": {
            "oauth": {
                "type": "oauth2",
                "flows": {
                    "authorizationCode": {
                        "authorizationUrl": "https://rovasocial.com/oauth/authorize",
                        "tokenUrl": "https://rovasocial.com/oauth/token",
                        "refreshUrl": "https://rovasocial.com/oauth/token",
                        "scopes": {
                            "profile.read": "See your name, username and profile photo",
                            "posts.write": "Publish posts for you, and delete the posts it published",
                            "media.write": "Upload photos and videos for those posts",
                            "posts.read": "See the status of the posts it published"
                        }
                    }
                }
            }
        },
        "schemas": {
            "Error": {
                "type": "object",
                "properties": {
                    "error": {
                        "type": "string"
                    },
                    "message": {
                        "type": "string"
                    }
                },
                "required": [
                    "error"
                ]
            },
            "Media": {
                "type": "object",
                "properties": {
                    "media_id": {
                        "type": "string",
                        "example": "m_123"
                    },
                    "type": {
                        "type": "string",
                        "enum": [
                            "image",
                            "video"
                        ]
                    },
                    "status": {
                        "type": "string",
                        "enum": [
                            "processing",
                            "ready",
                            "failed",
                            "expired",
                            "used"
                        ]
                    },
                    "expires_in": {
                        "type": "integer"
                    }
                }
            },
            "Post": {
                "type": "object",
                "properties": {
                    "id": {
                        "type": "string",
                        "example": "p_45"
                    },
                    "status": {
                        "type": "string",
                        "enum": [
                            "published",
                            "scheduled",
                            "held_for_review",
                            "removed",
                            "failed",
                            "deleted",
                            "cancelled"
                        ]
                    },
                    "post_id": {
                        "type": "string"
                    },
                    "url": {
                        "type": "string",
                        "format": "uri"
                    },
                    "scheduled_at": {
                        "type": "string",
                        "format": "date-time"
                    },
                    "idempotent_replay": {
                        "type": "boolean"
                    }
                }
            },
            "NewPost": {
                "type": "object",
                "properties": {
                    "text": {
                        "type": "string",
                        "description": "The caption. Text or media is required."
                    },
                    "media_ids": {
                        "type": "array",
                        "items": {
                            "type": "string"
                        },
                        "description": "From POST /media, /media/chunk or /media/from-url (ready, unused, within 2 h)."
                    },
                    "visibility": {
                        "type": "string",
                        "enum": [
                            "public",
                            "followers"
                        ],
                        "default": "public"
                    },
                    "scheduled_at": {
                        "type": "string",
                        "format": "date-time",
                        "description": "At least a minute ahead."
                    }
                }
            }
        },
        "parameters": {
            "IdemKey": {
                "name": "Idempotency-Key",
                "in": "header",
                "required": false,
                "schema": {
                    "type": "string",
                    "pattern": "^[A-Za-z0-9._:-]{8,80}$"
                },
                "description": "The same key for the same member answers the same post instead of a second one."
            }
        }
    },
    "paths": {
        "/me": {
            "get": {
                "summary": "The member this token speaks for",
                "security": [
                    {
                        "oauth": [
                            "profile.read"
                        ]
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "id": {
                                            "type": "string"
                                        },
                                        "username": {
                                            "type": "string"
                                        },
                                        "display_name": {
                                            "type": "string"
                                        },
                                        "avatar_url": {
                                            "type": "string"
                                        },
                                        "profile_url": {
                                            "type": "string"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "Invalid token",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/media": {
            "post": {
                "summary": "Upload a photo or short video (multipart field \"media\")",
                "security": [
                    {
                        "oauth": [
                            "media.write"
                        ]
                    }
                ],
                "requestBody": {
                    "content": {
                        "multipart/form-data": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "media": {
                                        "type": "string",
                                        "format": "binary"
                                    }
                                }
                            }
                        }
                    }
                },
                "responses": {
                    "201": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Media"
                                }
                            }
                        }
                    },
                    "422": {
                        "description": "Refused (for example a blank photo)",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    },
                    "429": {
                        "description": "Rate limited",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/media/chunk": {
            "post": {
                "summary": "Upload a large video in pieces",
                "security": [
                    {
                        "oauth": [
                            "media.write"
                        ]
                    }
                ],
                "description": "Raw body (or base64 with X-Chunk-B64: 1) plus headers X-Upload-Id, X-Chunk-Idx, X-Chunk-Total, X-Chunk-Offset, X-File-Size. The last piece answers with a media_id.",
                "responses": {
                    "200": {
                        "description": "A piece received",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "done": {
                                            "type": "boolean"
                                        },
                                        "received": {
                                            "type": "integer"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "201": {
                        "description": "The last piece: the media is ready",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Media"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/media/from-url": {
            "post": {
                "summary": "Have Rova fetch a photo or video from a public https URL",
                "security": [
                    {
                        "oauth": [
                            "media.write"
                        ]
                    }
                ],
                "requestBody": {
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "url": {
                                        "type": "string",
                                        "format": "uri"
                                    }
                                },
                                "required": [
                                    "url"
                                ]
                            }
                        }
                    }
                },
                "responses": {
                    "202": {
                        "description": "Accepted: poll GET /media/{id} or wait for media.ready",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Media"
                                }
                            }
                        }
                    },
                    "422": {
                        "description": "Not a public https address",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/media/{id}": {
            "get": {
                "summary": "A media item's status",
                "security": [
                    {
                        "oauth": [
                            "media.write"
                        ]
                    }
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Media"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/posts": {
            "post": {
                "summary": "Publish (or schedule) a post",
                "security": [
                    {
                        "oauth": [
                            "posts.write"
                        ]
                    }
                ],
                "parameters": [
                    {
                        "$ref": "#/components/parameters/IdemKey"
                    }
                ],
                "requestBody": {
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/NewPost"
                            }
                        }
                    }
                },
                "responses": {
                    "201": {
                        "description": "Published or scheduled",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Post"
                                }
                            }
                        }
                    },
                    "200": {
                        "description": "Idempotent replay",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Post"
                                }
                            }
                        }
                    },
                    "402": {
                        "description": "The member needs an active Rova membership",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    },
                    "422": {
                        "description": "Refused by Rova's rules",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    },
                    "429": {
                        "description": "Posting limit reached",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/posts/{id}": {
            "get": {
                "summary": "A post this app made: its status",
                "security": [
                    {
                        "oauth": [
                            "posts.read"
                        ]
                    }
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Post"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "Not a post this app made for this member",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            },
            "delete": {
                "summary": "Delete a post this app made (a scheduled one is cancelled)",
                "security": [
                    {
                        "oauth": [
                            "posts.write"
                        ]
                    }
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Post"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "Not a post this app made for this member",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            }
        }
    },
    "webhooks": {
        "post.published": {
            "post": {
                "summary": "post.published",
                "description": "Signed: Rova-Signature: t=<unix>,v1=<hex HMAC-SHA256(secret, \"<t>.<body>\")>. Reject t older than 5 minutes.",
                "requestBody": {
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "id": {
                                        "type": "string"
                                    },
                                    "event": {
                                        "type": "string"
                                    },
                                    "created_at": {
                                        "type": "string"
                                    },
                                    "data": {
                                        "type": "object"
                                    }
                                }
                            }
                        }
                    }
                },
                "responses": {
                    "200": {
                        "description": "Any 2xx = delivered"
                    }
                }
            }
        },
        "post.failed": {
            "post": {
                "summary": "post.failed",
                "description": "Signed: Rova-Signature: t=<unix>,v1=<hex HMAC-SHA256(secret, \"<t>.<body>\")>. Reject t older than 5 minutes.",
                "requestBody": {
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "id": {
                                        "type": "string"
                                    },
                                    "event": {
                                        "type": "string"
                                    },
                                    "created_at": {
                                        "type": "string"
                                    },
                                    "data": {
                                        "type": "object"
                                    }
                                }
                            }
                        }
                    }
                },
                "responses": {
                    "200": {
                        "description": "Any 2xx = delivered"
                    }
                }
            }
        },
        "media.ready": {
            "post": {
                "summary": "media.ready",
                "description": "Signed: Rova-Signature: t=<unix>,v1=<hex HMAC-SHA256(secret, \"<t>.<body>\")>. Reject t older than 5 minutes.",
                "requestBody": {
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "id": {
                                        "type": "string"
                                    },
                                    "event": {
                                        "type": "string"
                                    },
                                    "created_at": {
                                        "type": "string"
                                    },
                                    "data": {
                                        "type": "object"
                                    }
                                }
                            }
                        }
                    }
                },
                "responses": {
                    "200": {
                        "description": "Any 2xx = delivered"
                    }
                }
            }
        }
    }
}