Client creation and authentication configuration for connecting to the Tumblr API with various credential types.
Factory function to create a new Tumblr API client instance.
/**
* Creates a Tumblr API client using the given options
* @param options - Client configuration options
* @returns Client instance
*/
function createClient(options?: Options): Client;Usage Examples:
const tumblr = require('tumblr.js');
// Create client with OAuth credentials
const client = tumblr.createClient({
consumer_key: 'your-consumer-key',
consumer_secret: 'your-consumer-secret',
token: 'your-oauth-token',
token_secret: 'your-oauth-token-secret'
});
// Create client with API key only
const apiKeyClient = tumblr.createClient({
consumer_key: 'your-consumer-key'
});
// Create client with no authentication
const publicClient = tumblr.createClient();Direct constructor for creating client instances.
/**
* Creates a Tumblr API client using the given options
* @param options - Client configuration options
*/
class Client {
constructor(options?: Options);
/** Package version */
static version: string;
/** Package version (instance property) */
version: string;
/** Base URL for API requests */
baseUrl: string;
}Usage Examples:
const { Client } = require('tumblr.js');
// Using constructor directly
const client = new Client({
consumer_key: 'your-consumer-key',
consumer_secret: 'your-consumer-secret',
token: 'your-oauth-token',
token_secret: 'your-oauth-token-secret'
});
console.log(client.version); // "5.0.1"
console.log(Client.version); // "5.0.1"Legacy method for enabling promise mode. Now promises are returned automatically when no callback is provided.
/**
* @deprecated Promises are returned if no callback is provided
*/
returnPromises(): void;Full OAuth 1.0 authentication for authenticated endpoints requiring user permissions.
interface OAuth1Options {
consumer_key: string;
consumer_secret: string;
token: string;
token_secret: string;
baseUrl?: string;
}Requirements:
Usage Example:
const client = tumblr.createClient({
consumer_key: 'your-consumer-key',
consumer_secret: 'your-consumer-secret',
token: 'user-oauth-token',
token_secret: 'user-oauth-token-secret'
});
// Can access authenticated endpoints
const userInfo = await client.userInfo();
const dashboard = await client.userDashboard();API key authentication for read-only endpoints.
interface ApiKeyOptions {
consumer_key: string;
baseUrl?: string;
}Requirements:
Usage Example:
const client = tumblr.createClient({
consumer_key: 'your-consumer-key'
});
// Can access public endpoints
const blogInfo = await client.blogInfo('staff');
const posts = await client.blogPosts('staff');
const taggedPosts = await client.taggedPosts('cats');No authentication for completely public endpoints.
interface NoAuthOptions {
baseUrl?: string;
}Usage Example:
const client = tumblr.createClient();
// Limited to completely public endpoints
const taggedPosts = await client.taggedPosts('cats');Complete configuration interface for client creation.
interface Options {
/** OAuth1 credential. Required for API key auth endpoints */
consumer_key?: string;
/** OAuth1 credential. Required for OAuth endpoints */
consumer_secret?: string;
/** OAuth1 credential. Required for OAuth endpoints */
token?: string;
/** OAuth1 credential. Required for OAuth endpoints */
token_secret?: string;
/** The API url if different from the default */
baseUrl?: string;
/** @deprecated Methods will return promises if no callback is provided */
returnPromises?: boolean;
}Custom base URL for API requests (useful for testing or alternative endpoints).
Usage Example:
const client = tumblr.createClient({
consumer_key: 'your-key',
baseUrl: 'https://api.tumblr.com' // default
});Base URL Requirements:
The client constructor validates configuration and throws specific errors:
// Missing OAuth credentials
try {
const client = new Client({
consumer_key: 'key',
consumer_secret: 'secret'
// Missing token and token_secret
});
} catch (error) {
// TypeError: Provide consumer_key or all oauth credentials. Invalid token provided.
}
// Invalid baseUrl
try {
const client = new Client({
baseUrl: 'https://api.tumblr.com/v2' // includes path
});
} catch (error) {
// TypeError: baseUrl option must not include a pathname.
}// Development/testing with custom base URL
const devClient = tumblr.createClient({
consumer_key: process.env.TUMBLR_CONSUMER_KEY,
baseUrl: 'https://api-test.tumblr.com'
});
// Production with full OAuth
const prodClient = tumblr.createClient({
consumer_key: process.env.TUMBLR_CONSUMER_KEY,
consumer_secret: process.env.TUMBLR_CONSUMER_SECRET,
token: userOAuthToken,
token_secret: userOAuthTokenSecret
});
// Public read-only client
const publicClient = tumblr.createClient({
consumer_key: process.env.TUMBLR_CONSUMER_KEY
});