Nachos Pillage Milwaukee

    tsl-mastodon-api
    TypeScript icon, indicating that this package has built-in type declarations

    0.3.0 • Public • Published

    TypeScript Library for the Mastodon API

    This is a TypeScript-optimized library to access a Mastodon server.

    Installation

    npm install tsl-mastodon-api

    Access Token

    You need an access token for communication with a Mastodon server.

    1. Open your Mastodon website and go to the profile settings of the account.

    2. In the profile settings open the section 'Development'.

    3. Create a new application and use the related access token.

    Or you can use the Mastodon.API.createOAuthApp function.

    Examples

    import * as Mastodon from 'tsl-mastodon-api';
    async function postHelloWorld(): Promise<void> {
        // create the API instance
        const mastodon = new Mastodon.API({
            access_token: 'ABC',
            api_url: 'https://mastodon.example/api/v1/',
            auto_delay: true
        });
        // expect client / server errors
        try {
            const result = await mastodon.postStatus({
                sensitive: true,
                spoiler_text: 'Hello',
                status: 'World'
            });
            console.log(JSON.stringify(result));
        }
        catch (error) {
            console.error(error);
        }
    }
    postHelloWorld();

    API Overview

    The following snippets show an excerpt of the v0.0.6 API.

    API(config)
    API.delay()
    API.search(search)
    
    API.getAccount()
    API.getList(listID)
    API.getListAccounts(listID, queryParameters?)
    API.getLists(queryParameters?)
    API.getMediaAttachment(mediaAttachmentID)
    API.getNotifications()
    API.getStatus(statusID)
    API.getStatusContext(statusID)
    API.getStatuses(queryParameters?)
    API.getStatusesOfHome(queryParameters?)
    API.getStatusesOfList(listID, queryParameters?)
    API.getStatusesOfPublic(queryParameters?)
    API.getStatusesOfTag(tag, queryParameters?)
    
    API.postList(list)
    API.postListAccounts(listID, listAccounts)
    API.postMediaAttachment(mediaAttachment)
    API.postPollVote(pollId, pollVote)
    API.postStatus(status)
    
    API.deleteList(listID)
    API.deleteListAccounts(listID, listAccounts)
    API.deleteStatus(statusID)
    JSON.isAccount(json)
    JSON.isList(json)
    JSON.isMediaAttachment(json)
    JSON.isNotification(json)
    JSON.isPoll(json)
    JSON.isSearchResults(json)
    JSON.isStatus(json)
    REST.delete(path, params?)
    REST.fetch(method, path, params?)
    REST.get(path, params?)
    REST.patch(path, params?)
    REST.post(path, params?)
    REST.put(path, params?)
    Bridge.fetch(url, options?)
    Utilities.fileFrom(path, mimeType?)

    Links

    Install

    npm i tsl-mastodon-api

    DownloadsWeekly Downloads

    68

    Version

    0.3.0

    License

    MIT

    Unpacked Size

    124 kB

    Total Files

    58

    Last publish

    Collaborators

    • typescriptlibs