Class: MastodonServer

MastodonServer(domain)

Class for interacting with the public non-authenticated API of a Mastodon server. Provides methods to fetch trending toots, tags, links, and server info, as well as utilities for aggregating and processing trending data across multiple servers in the fediverse.

Constructor

new MastodonServer(domain)

Constructs a MastodonServer instance for the given domain.
Parameters:
Name Type Description
domain string The domain of the Mastodon server.
Properties:
Name Type Description
domain string Domain of the server this MastodonServer instance interacts with.
logger Logger Logger instance for this server.

Members

trendUrl

Build a URL for a trending type (tags, links, toots).

v1Url

Build a v1 API URL.

v2Url

Build a v2 API URL.

Methods

(async) fetchServerInfo() → {Promise.<InstanceResponse>}

Fetch the mastodon.v2.Instance (MAU, version, languages, rules, etc) for this server.
Returns:
The instance info or null if not available.
Type
Promise.<InstanceResponse>

Get the links that are trending on this server.
Returns:
Array of trending links.
Type
Promise.<Array.<TrendingLink>>

(async) fetchTrendingStatuses() → {Promise.<Array.<Toot>>}

Fetch Toots that are trending on this server. Note: Returned Toots have not had Toot.completeProperties called yet.
Returns:
Array of trending Toot objects.
Type
Promise.<Array.<Toot>>

(async) fetchTrendingTags() → {Promise.<Array.<TagWithUsageCounts>>}

Get the tags that are trending on this server.
Returns:
Array of trending tags with usage counts.
Type
Promise.<Array.<TagWithUsageCounts>>

Get the top trending links from all servers in the fediverse.
Returns:
Array of trending links across all servers.
Type
Promise.<Array.<TrendingLink>>

(async, static) fediverseTrendingTags() → {Promise.<TagList>}

Get the top trending tags from all servers, minus any invalid or muted tags.
Returns:
TagList of trending tags across all servers.
Type
Promise.<TagList>

(async, static) fediverseTrendingToots() → {Promise.<Array.<Toot>>}

Pull public top trending Toots on popular mastodon servers including from accounts user doesn't follow.
Returns:
Array of trending Toots across all servers.
Type
Promise.<Array.<Toot>>

(async, static) getMastodonInstances() → {Promise.<MastodonInstances>}

Get the server names that are most relevant to the user, meaning servers that a lot of the accounts the user follows live on.
Returns:
Dictionary of MastodonInstances keyed by domain.
Type
Promise.<MastodonInstances>

(async, static) getTrendingData() → {Promise.<TrendingData>}

Collect all three kinds of trending data (links, tags, Toots) in one call.
Returns:
Object containing trending links, tags, toots, and servers.
Type
Promise.<TrendingData>