The main Client class. This is the primary way you will interact with snoots.

Every Client instance is fully independent, so you are free to create as many as you require.

Example: The most common way to use snoots is to make a client

const client = new Client({
userAgent: '<your user agent>',
auth: {
username: '<your username>',
password: '<your password>',
},
creds: {
clientId: '<your client id>',
clientSecret: '<your client secret>',
},
})

Example: If you already have a refresh token from a previous session you can

use that as well.

const client = new Client({
userAgent: '<your user agent>',
auth: {
refreshToken: '<the token>',
},
creds: {
clientId: '<your client id>',
clientSecret: '<your client secret>',
},
})

Example: If you want to make requests not on behalf of a user, you can leave

out the auth key. See ClientOptions.auth for more details.

const client = new Client({
userAgent: '<your user agent>',
creds: {
clientId: '<your client id>',
clientSecret: '<your client secret>',
},
});

Example: If you want to make completely unauthenticated requests, you can

leave out both the auth and creds keys. See ClientOptions.creds for more details and restrictions.

const client = new Client({ userAgent: '<your user agent>' })

Constructors

Properties

comments: CommentControls

Controls for interacting with comments.

Controls for interacting with the currently authorized user.

Controls for interacting with posts.

subreddits: SubredditControls

Controls for interacting with subreddits.

Controls for interacting with users.

Accessors

  • get rateLimit(): Maybe<RateLimit>
  • Get the last-known rate limit status for this client.

    Returns Maybe<RateLimit>

    Note

    The rate limit status is only updated when a request is made from this client. It will also get out of sync if there are multiple clients using the same authorization (and thus the same rate limit pool).

Methods

  • Get the set of authorized scopes for the current session.

    Returns Maybe<string[]>

    The scopes, or undefined if no oauth session exists.

  • Get the refresh token for the current session, if there is one.

    Returns Maybe<string>

    The refresh token, or undefined if no token exists.

  • Create a client from an OAuth code.

    Type Parameters

    • Self extends typeof Client

      Client or a subclass of Client.

    Parameters

    • this: Self

      The Client subclass. This is only used for typescript to work with subclasses, this is not actually a parameter.

    • options: Required<Omit<ClientOptions, "auth">>

      The Client options.

    • code: string

      The OAuth code.

    • redirectUri: string

      The redirect URI. This must be the same as the uri given to makeAuthUrl.

    Returns Promise<InstanceType<Self>>

    A promise that resolves when the authorization is complete.

  • Make an OAuth login url.

    Parameters

    • clientId: string

      The ID of the Reddit app.

    • scopes: string[]

      The scopes to authorize with.

    • redirectUri: string

      The uri to redirect to after authorization.

    • state: string = "snoots"

      Some arbitrary state that will be passed back upon authorization. This is used as a CSRF token to prevent various attacks.

    • temporary: boolean = false

      Whether the auth should be temporary (expires after 1hr), or permanent.

    Returns string

    The URL to direct the user to for authorization.